added a wrapper around the templating engine, to be able to have default values popcorn-port
authorhamidouk
Wed, 30 Nov 2011 16:13:22 +0100
branchpopcorn-port
changeset 362 0b1bf06c28ed
parent 361 15074091bdba
child 363 8d4b329836b6
added a wrapper around the templating engine, to be able to have default values for some template variables.
src/js/utils.js
unittests/tests/utils.js
--- a/src/js/utils.js	Wed Nov 30 14:27:39 2011 +0100
+++ b/src/js/utils.js	Wed Nov 30 16:13:22 2011 +0100
@@ -97,6 +97,12 @@
 	 return(hex);
 };
 
+/* shortcut to have global variables in templates */
+IriSP.templToHTML = function(template, values) {
+  var params = IriSP.jQuery.extend(IriSP.default_templates_vars, values);
+  return Mustache.to_html(template, params);
+};
+
 /* for ie compatibility
 if (Object.prototype.__defineGetter__&&!Object.defineProperty) {
    Object.defineProperty=function(obj,prop,desc) {
--- a/unittests/tests/utils.js	Wed Nov 30 14:27:39 2011 +0100
+++ b/unittests/tests/utils.js	Wed Nov 30 16:13:22 2011 +0100
@@ -52,4 +52,9 @@
     equal(IriSP.DEC_HEXA_COLOR(24345), "5F19", "second test passes");
 
   });
+
+  test("test template function", function() {
+    IriSP.default_templates_vars["test_fixture"] = "FIXTURE";
+    equal(IriSP.templToHTML("{{test_fixture}} {{foo}}", {foo: 2}), "FIXTURE 2", "correct template returned"); 
+  });
 }