add EJS.variable_name to mirror Underscore template variable option #14

Closed
wants to merge 3 commits into
from

2 participants

@wireframe

Underscore's _.template method supports a variable option to allow for templates to use the defined variable name instead of local scope.

http://underscorejs.org/#template

This branch ports existing Underscore behavior to EJS by adding the EJS.variable_name option.

One nice side effect of this change is that rendering no longer uses the Javascript with statement which is slow and should generally be avoided whenever possible.

Resources:

@larsklevan larsklevan commented on an outdated diff Feb 20, 2013
@@ -38,10 +39,21 @@ def compile(source, options = {})
replace_escape_tags!(source, options)
replace_interpolation_tags!(source, options)
replace_evaluation_tags!(source, options)
- "function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};" +
- "with(obj||{}){__p.push('#{source}');}return __p.join('');}"
+ source = assemble_source(source);
@larsklevan
larsklevan added a line comment Feb 20, 2013

looks like an unintentional semi-colon in ruby code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@MoonScript

Nice! Looks good, man.

@wireframe wireframe closed this Dec 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment