Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/core/core.helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@
// Blows up jshint errors based on the new Function constructor
//Templating methods
//Javascript micro templating by John Resig - source at http://ejohn.org/blog/javascript-micro-templating/
templateStringCache = {},
template = helpers.template = function(templateString, valuesObject) {

// If templateString is function rather than string-template - call the function for valuesObject
Expand All @@ -466,17 +467,17 @@
return templateString(valuesObject);
}

var cache = {};

function tmpl(str, data) {
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] :
var fn;

if (templateStringCache.hasOwnProperty(str)) {
fn = templateStringCache[str];
} else {
// Generate a reusable function that will serve as a template
// generator (and which will be cached).
new Function("obj",
fn = new Function("obj",
"var p=[],print=function(){p.push.apply(p,arguments);};" +

// Introduce the data as local variables using with(){}
Expand All @@ -494,6 +495,10 @@
"');}return p.join('');"
);

// Cache the result
templateStringCache[str] = fn;
}

// Provide some basic currying to the user
return data ? fn(data) : fn;
}
Expand Down