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

hbs

Package Overview
Dependencies
Maintainers
1
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.7 to 1.0.0

.gitignore

63

lib/hbs.js

@@ -1,45 +0,32 @@

var hbs = {};
var handlebars = null;
var handlebarsPath = __dirname + "/../support/handlebars/lib/handlebars";
var handlebars = require('handlebars');
Object.defineProperty(hbs, "handlebars", {
enumerable: true,
get: function() {
if(handlebars == null) {
handlebars = require(hbs.handlebarsPath);
}
return handlebars;
},
set: function(value) {
handlebars = value;
var compile = function (str, options) {
if (typeof str !== 'string') {
return str;
}
});
var template = handlebars.compile(str);
return function (locals) {
return template(locals, {
helpers: locals.blockHelpers,
partials: null,
data: null
});
};
};
Object.defineProperty(hbs, "handlebarsPath", {
enumerable: true,
get: function() {
return handlebarsPath;
},
set: function(value) {
handlebarsPath = value;
handlebars = null;
}
})
// Express view template engine compliance
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.compile = compile;
// Expose Handlebars and useful methods
exports.handlebars = handlebars;
exports.registerHelper = function () {
handlebars.registerHelper.apply(handlebars, arguments);
};
var render = hbs.render = function(template, options) {
var compiledTemplate = compile(template, options);
return compiledTemplate(options);
exports.registerPartial = function () {
handlebars.registerPartial.apply(handlebars, arguments);
};
module.exports = hbs;
{
"name": "hbs",
"description": "Express.js template engine plugin for Handlebars",
"version": "0.0.7",
"version": "1.0.0",
"homepage": "https://github.com/donpark/hbs",
"author": "Don Park <donpark@docuverse.com> (http://blog.docuverse.com)",
"main": "lib/hbs.js",
"directories": {
"lib":"./lib"
},
"dependencies": {
"handlebars": ">= 1.0.0"
},
"engines": {
"node": ">= 0.2.0"
"node": ">= 0.4.0"
}
}

@@ -22,65 +22,20 @@ # hbs #

app.set("view engine", "hbs");
To your own version of Handlebars:
## Examples ##
require('hbs').handlebars = require('/path/to/handlebars');
See `test/server` source code.
or
## Issues ##
require('hbs').handlebarsPath = '/path/to/handlebars';
Block Helper support is broken currently.
## Tricks ##
## Migrating to 1.0.0 ##
Handlebars support view helper functions which comes in handy. For example, following
code allow view templates to affect head section which is typically rendered from layout
template.
* Version number bumped to 1.0.0 to match `Handlebars` version.
* `Handlebars` is now loaded using `require` and is longer embedded.
* `hbs.handlebarsPath` was removed
* `registerHelper` and `registerPartial` methods are exported.
### layout.hbs ###
<html>
<head>
<title>{{page_title}}</title>
<script src="js/common.js" type="text/javascript" charset="utf-8"></script>
<script src="js/{{app_name}}.js" type="text/javascript" charset="utf-8"></script>
<link type="text/css" rel="stylesheet" href="common.css">
<link type="text/css" rel="stylesheet" href="{{app_name}}.css">
</head>
<body>
{{{body}}}
</body>
</html>
### myview.hbs ###
{{#properties}}
"app_name": "myapp",
"page_title": "My View"
{{/properties}}
<div>blah</div>
...
### view rendering code ###
var options = {
cache: true,
compile: true,
locals {
...
},
blockHelpers: {
properties: function (context, fn) {
var props = JSON.parse("{" + fn(this) + "}");
for (var prop in props) {
if (props.hasOwnProperty(prop)) {
context[prop] = props[prop];
}
}
return "";
}
}
};
res.render("myview", options);
## Migrating from 0.0.3 from 0.0.2 ##
Handlebars' block-helpers now needs to be in `blockHelpers` (see example above) instead of `locals`.
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