Comparing version 0.0.5 to 0.0.6
@@ -1,18 +0,45 @@ | ||
var compile = exports.compile = function (source, options) { | ||
if (typeof source == 'string') { | ||
var handlebars = exports.handlebars || | ||
(exports.handlebars = require(exports.handlebarsPath || | ||
'../support/handlebars/lib/handlebars')); | ||
var template = handlebars.compile(source); | ||
return function (options) { | ||
return template(options, options.blockHelpers); | ||
}; | ||
} else { | ||
return source; | ||
var hbs = {}; | ||
var handlebars = null; | ||
var handlebarsPath = __dirname + "/../support/handlebars/lib/handlebars"; | ||
Object.defineProperty(hbs, "handlebars", { | ||
enumerable: true, | ||
get: function() { | ||
if(handlebars == null) { | ||
handlebars = require(hbs.handlebarsPath); | ||
} | ||
return handlebars; | ||
}, | ||
set: function(value) { | ||
handlebars = value; | ||
} | ||
}); | ||
Object.defineProperty(hbs, "handlebarsPath", { | ||
enumerable: true, | ||
get: function() { | ||
return handlebarsPath; | ||
}, | ||
set: function(value) { | ||
handlebarsPath = value; | ||
handlebars = null; | ||
} | ||
}) | ||
var compile = hbs.compile = function (source, options) { | ||
if (typeof source == 'string') { | ||
var template = hbs.handlebars.compile(source); | ||
return function (options) { | ||
return template(options, options.blockHelpers); | ||
}; | ||
} else { | ||
return source; | ||
} | ||
}; | ||
exports.render = function (template, options) { | ||
template = compile(template, options); | ||
return template(options); | ||
var render = hbs.render = function(template, options) { | ||
var compiledTemplate = compile(template, options); | ||
return compiledTemplate(options); | ||
}; | ||
module.exports = hbs; |
{ | ||
"name": "hbs", | ||
"description": "Express.js template engine plugin for Handlebars", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"homepage": "https://github.com/donpark/hbs", | ||
@@ -6,0 +6,0 @@ "author": "Don Park <donpark@docuverse.com> (http://blog.docuverse.com)", |
39
test.js
@@ -0,3 +1,7 @@ | ||
var assert = require('assert'); | ||
var hbs = require("./lib/hbs"); | ||
var handlebars = hbs.handlebars; | ||
assert.ok(handlebars != null); | ||
var options = { | ||
@@ -7,6 +11,39 @@ message: "foobar" | ||
//testing out of the box configuration | ||
var source = "testing {{message}}"; | ||
var template = hbs.compile(source, options); | ||
var rendered = hbs.render(template, options); | ||
assert.equal('testing foobar', rendered); | ||
console.log(rendered); | ||
//fake handlebars conforming interface | ||
var fakeHandlebars = { | ||
compile: function(source, options) { | ||
return function(template, options) { | ||
return source; | ||
} | ||
}, | ||
render: function(tpl, options) { | ||
return tpl(); | ||
} | ||
}; | ||
module.exports = fakeHandlebars; | ||
//setting handlebars to fake version | ||
hbs.handlebars = fakeHandlebars; | ||
var template = hbs.compile(source, options); | ||
var rendered = hbs.render(template, options); | ||
assert.equal('testing {{message}}', rendered); | ||
//changing require path to go back to path of real handlebars | ||
hbs.handlebarsPath = __dirname + '/support/handlebars/lib/handlebars'; | ||
var template = hbs.compile(source, options); | ||
var rendered = hbs.render(template, options); | ||
assert.equal('testing foobar', rendered); | ||
//changing require path to use this file (which exports fake version) | ||
hbs.handlebarsPath = __filename; | ||
var template = hbs.compile(source, options); | ||
var rendered = hbs.render(template, options); | ||
assert.equal('testing {{message}}', rendered); | ||
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
2
4860
6
1
79
1