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

hbs

Package Overview
Dependencies
Maintainers
2
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 1.0.1 to 1.0.2

.travis.yml

100

lib/hbs.js

@@ -1,9 +0,17 @@

var handlebars = require('handlebars');
var compile = function (str, options) {
// builtin
var fs = require('fs');
var path = require('path');
// expose handlebars, allows users to use their versions
// by overriding this early in their apps
exports.handlebars = require('handlebars');
// express 2.x template engine compliance
exports.compile = function (str, options) {
if (typeof str !== 'string') {
return str;
}
var template = handlebars.compile(str);
var template = exports.handlebars.compile(str);
return function (locals) {

@@ -18,19 +26,87 @@ return template(locals, {

// Express view template engine compliance
// cache for templates, express 3.x doesn't do this for us
var cache = {};
exports.compile = compile;
// express 3.x template engine compliance
exports.__express = function(filename, options, cb) {
var handlebars = exports.handlebars;
// Expose Handlebars and useful methods
// render the original file
// cb(err, str)
function render_file(locals, cb) {
// cached?
var template = cache[filename];
if (template) {
return cb(null, template(locals));
}
exports.handlebars = handlebars;
fs.readFile(filename, 'utf8', function(err, str){
if (err) {
return cb(err);
}
var locals = options;
var template = handlebars.compile(str);
if (options.cache) {
cache[filename] = template;
}
cb(null, template(locals));
});
}
// render with a layout
function render_with_layout(template, locals, cb) {
render_file(locals, function(err, str) {
if (err) {
return cb(err);
}
var locals = options;
locals.body = str;
var str = template(locals);
cb(null, str);
});
}
// options.layout specified and false (don't use layout)
if (options.layout !== undefined && !options.layout) {
return render_file(options, cb);
}
var view_dir = options.settings.views;
var layout_filename = path.join(view_dir, options.layout || 'layout.hbs');
var layout_template = cache[layout_filename];
if (layout_template) {
return render_with_layout(layout_template, cb);
}
// TODO check if layout path has .hbs extension
fs.readFile(layout_filename, 'utf8', function(err, str) {
if (err) {
return cb(err);
}
var layout_template = handlebars.compile(str);
if (options.cache) {
cache[layout_filename] = layout_template;
}
render_with_layout(layout_template, options, cb);
});
}
/// expose useful methods
exports.registerHelper = function () {
handlebars.registerHelper.apply(handlebars, arguments);
exports.handlebars.registerHelper.apply(exports.handlebars, arguments);
};
exports.registerPartial = function () {
handlebars.registerPartial.apply(handlebars, arguments);
exports.handlebars.registerPartial.apply(exports.handlebars, arguments);
};
exports.SafeString = handlebars.SafeString;
exports.Utils = handlebars.Utils;
// DEPRECATED, kept for backwards compatibility
exports.SafeString = exports.handlebars.SafeString;
exports.Utils = exports.handlebars.Utils;
{
"name": "hbs",
"description": "Express.js template engine plugin for Handlebars",
"version": "1.0.1",
"version": "1.0.2",
"homepage": "https://github.com/donpark/hbs",

@@ -14,2 +14,10 @@ "author": "Don Park <donpark@docuverse.com> (http://blog.docuverse.com)",

},
"devDependencies": {
"mocha": ">=1.0.0",
"npm": "*",
"request": ">=2.9.202"
},
"scripts": {
"test": "mocha"
},
"engines": {

@@ -16,0 +24,0 @@ "node": ">= 0.4.0"

18

Readme.md

@@ -7,2 +7,4 @@ # hbs #

[![Build Status](https://secure.travis-ci.org/donpark/hbs.png)](http://travis-ci.org/donpark/hbs)
## Why ##

@@ -13,6 +15,8 @@

adds Express.js view engine support directly.
## Installation ##
npm install hbs
```
npm install hbs
```

@@ -22,8 +26,10 @@ ## Usage ##

To set *hbs* as default view engine:
app.set("view engine", "hbs");
```javascript
app.set("view engine", "hbs");
```
## Examples ##
See `test/server` source code.
See `test/2.x/app.js` or `test/3.x/app.js` depending on your version of express.

@@ -30,0 +36,0 @@ ## Issues ##

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