Skip to content

Commit

Permalink
Add a Jaml.automaticScope option, enabled by default, that allows J…
Browse files Browse the repository at this point in the history
…aml to work in environments that don't support function decompilation.
  • Loading branch information
savetheclocktower authored and edspencer committed Jan 23, 2010
1 parent 20bf85c commit 583f998
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Jaml-all.js
Expand Up @@ -7,6 +7,7 @@
*/
Jaml = function() {
return {
automaticScope: true,
templates: {},
helpers : {},

Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 583f998

Please sign in to comment.