Comparing version 1.1.0 to 1.2.0
@@ -5,5 +5,6 @@ 'use strict'; | ||
Builtins = require('./builtins'), | ||
defaultOptions = require('./defaultOptions.json'); | ||
defaultOptions = require('./defaultOptions.json'), | ||
_ = require('lodash'); | ||
function Precompiled(code, options) { | ||
function Precompiled(code, options, customBuiltins) { | ||
var self = this; | ||
@@ -16,2 +17,4 @@ | ||
self.customBuiltins = customBuiltins; | ||
self.fn = null; | ||
@@ -41,2 +44,6 @@ try { | ||
var builtins = new Builtins(context, locals); | ||
// add/update custom builtins | ||
_.each(self.customBuiltins, function(builtin, name) { | ||
builtins[name] = builtin; | ||
}); | ||
@@ -43,0 +50,0 @@ try { |
@@ -79,2 +79,3 @@ 'use strict'; | ||
function _renderPlainText(t) { | ||
@@ -84,6 +85,7 @@ return '__out+="' + utils.escapeStr(t) + '";\n'; | ||
function Wash(source, options) { | ||
function Wash(source, options, customBuiltins) { | ||
var self = this; | ||
self.source = source; | ||
console.assert(_.isString(self.source)); | ||
@@ -96,2 +98,6 @@ self.options = options || {}; | ||
if(customBuiltins) { | ||
self.customBuiltins = customBuiltins; | ||
} | ||
self._code = ''; | ||
@@ -102,2 +108,11 @@ self._forLoopVars = []; | ||
Wash.prototype._isBuiltin = function(token) { | ||
var self = this; | ||
if(Builtins.isBuiltin(token)) { return true; } | ||
if(self.customBuiltins) { | ||
return !!utils.getValueByPath(self.customBuiltins, '.' + token); | ||
} | ||
}; | ||
Wash.prototype._evalTokens = function(tokens) { | ||
@@ -122,3 +137,3 @@ var self = this; | ||
} | ||
} else if(Builtins.isBuiltin(token)) { | ||
} else if(self._isBuiltin(token)) { | ||
outs += '__builtins.' + token; | ||
@@ -292,3 +307,3 @@ } else { | ||
return new Precompiled(self._code, self.options); | ||
return new Precompiled(self._code, self.options, self.customBuiltins); | ||
}; | ||
@@ -295,0 +310,0 @@ |
{ | ||
"name": "wash", | ||
"description": "a safe template rendering engine", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"main": "index", | ||
@@ -6,0 +6,0 @@ "author": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57951
33
1300