From 583f998844d06875d20d1f08d9ca74822ba419e4 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Fri, 22 Jan 2010 17:48:39 +0800 Subject: [PATCH] Add a `Jaml.automaticScope` option, enabled by default, that allows Jaml to work in environments that don't support function decompilation. --- Jaml-all.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Jaml-all.js b/Jaml-all.js index c20bf99..8229ff6 100644 --- a/Jaml-all.js +++ b/Jaml-all.js @@ -7,6 +7,7 @@ */ Jaml = function() { return { + automaticScope: true, templates: {}, helpers : {}, @@ -222,10 +223,20 @@ Jaml.Template.prototype = { data = [data]; } - with(this) { - for (var i=0; i < data.length; i++) { - eval("(" + this.tpl.toString() + ")(data[i])"); - }; + if (Jaml.automaticScope) { + // Use function decompilation to put all helpers in the + // function's scope. + with(this) { + for (var i = 0; i < data.length; i++) { + eval("(" + this.tpl.toString() + ")(data[i])"); + }; + } + } else { + // Avoid the `eval` call at the cost of slightly more verbose + // templates. + for (var i = 0; i < data.length; i++) { + this.tpl.call(this, data[i]); + } } var roots = this.getRoots(),