Explorar el Código

New behavior for markup render with data binding

soyjavi hace 14 años
padre
commit
57ed968643
Se han modificado 2 ficheros con 19 adiciones y 22 borrados
  1. 13 18
      src/view/Lungo.View.Template.Binding.js
  2. 6 4
      src/view/Lungo.View.Template.js

+ 13 - 18
src/view/Lungo.View.Template.Binding.js

@@ -16,14 +16,21 @@ LUNGO.View.Template.Binding = (function(lng, undefined) {
     /**
      * Performs databinding process for a data set and a given template
      *
-     * @method create
+     * @method process
      *
-     * @param {String} Databinding Template Id
+     * @param {String} Markup for binding
      * @param {Object} Data for binding
      */
-    var create = function(template_id, data) {
-        var template = lng.View.Template.get(template_id);
-        return _processData(data, template);
+    var process = function(markup, data) {
+        var data_type = lng.Core.toType(data);
+
+        if (data_type === 'array') {
+            return _bindPropertiesInMultiplesElements(data, markup);
+        } else if (data_type === 'object') {
+            return _bindProperties(data, markup);
+        } else {
+            lng.Core.log(3, ERROR.BINDING_DATA_TYPE);
+        }
     };
 
     var dataAttribute = function(element, attribute) {
@@ -35,18 +42,6 @@ LUNGO.View.Template.Binding = (function(lng, undefined) {
         }
     };
 
-    var _processData = function(data, template) {
-        var data_type = lng.Core.toType(data);
-
-        if (data_type === 'array') {
-            return _bindPropertiesInMultiplesElements(data, template);
-        } else if (data_type === 'object') {
-            return _bindProperties(data, template);
-        } else {
-            lng.Core.log(3, ERROR.BINDING_DATA_TYPE);
-        }
-    };
-
     var _bindPropertiesInMultiplesElements = function(elements, template) {
         var markup = '';
         for (var i = 0, len = elements.length; i < len; i++) {
@@ -71,7 +66,7 @@ LUNGO.View.Template.Binding = (function(lng, undefined) {
     };
 
     return {
-        create: create,
+        process: process,
         dataAttribute: dataAttribute
     };
 

+ 6 - 4
src/view/Lungo.View.Template.js

@@ -61,8 +61,10 @@ LUNGO.View.Template = (function(lng, undefined) {
      */
     var render = function(element, template_id, data) {
         if (lng.View.Template.exists(template_id)) {
+            var template_markup = this.get(template_id);
+            var markup = lng.View.Template.process(template_markup, data);
+
             var container = lng.dom(element);
-            var markup = this.markup(template_id, data);
             container.html(markup);
         } else {
             lng.Core.log(3, ERROR.BINDING_TEMPLATE + template_id);
@@ -74,11 +76,11 @@ LUNGO.View.Template = (function(lng, undefined) {
      *
      * @method markup
      *
-     * @param {String} Databinding Template Id
+     * @param {String} Markup for binding
      * @param {Object} Data for binding
      */
-    var markup = function(template_id, data) {
-        return lng.View.Template.Binding.create(template_id, data);
+    var markup = function(markup, data) {
+        return lng.View.Template.process(markup, data);
     };
 
     return {