Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

hbs

Package Overview
Dependencies
Maintainers
0
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hbs - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

55

lib/hbs.js

@@ -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)",

@@ -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);
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc