/** @var {string[]} requiredStrings - Collection of strings found during the rendering of one template */
var requiredStrings = [];
- /** @var {string[]} requiredJS - Collection of js blocks found during the rendering of one template */
- var requiredJS = [];
-
/** @var {Number} uniqid Incrementing value that is changed for every call to render */
var uniqid = 1;
* @return {string}
*/
var jsHelper = function(sectionText, helper) {
- requiredJS.push(helper(sectionText, this));
+ this.jsBlocks.push(helper(sectionText, this));
return '';
};
var addHelpers = function(context, themeName) {
currentThemeName = themeName;
requiredStrings = [];
- requiredJS = [];
context.uniqid = uniqid++;
context.str = function() {
return stringHelper;
return quoteHelper;
};
context.globals = {config: config};
+ context.jsBlocks = [];
context.currentTheme = themeName;
};
*/
var getJS = function(strings) {
var js = '';
- if (requiredJS.length > 0) {
- js = requiredJS.join(";\n");
+ if (this.jsBlocks.length > 0) {
+ js = this.jsBlocks.join(";\n");
}
// Re-render to get the final strings.
// and cause the template to die on the second pass (unbalanced).
result = treatStringsInContent(result, strings);
- deferred.resolve(result, getJS(strings));
+ deferred.resolve(result, getJS.bind(context)(strings));
})
.fail(deferred.reject);
} else {
- deferred.resolve(result.trim(), getJS([]));
+ deferred.resolve(result.trim(), getJS.bind(context)([]));
}
}
).fail(deferred.reject);