Permalink
Browse files

Add a `Jaml.automaticScope` option, enabled by default, that allows J…

…aml to work in environments that don't support function decompilation.
  • Loading branch information...
savetheclocktower authored and edspencer committed Jan 22, 2010
1 parent 20bf85c commit 583f998844d06875d20d1f08d9ca74822ba419e4
Showing with 15 additions and 4 deletions.
  1. +15 −4 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(),

0 comments on commit 583f998

Please sign in to comment.