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 2.6.0 to 2.7.0

5

History.md

@@ -0,1 +1,6 @@

# 2.7.0 (2014-06-02)
* fix registering directories of partials on windows
* add api to expose locals as template data
# 2.5.0 / 2014-02-19

@@ -2,0 +7,0 @@

29

lib/hbs.js

@@ -53,3 +53,5 @@ var fs = require('fs');

try {
var res = template(locals);
var data = locals.__hbsLocals;
delete locals.__hbsLocals;
var res = template(locals, { data: data });
async.done(function(values) {

@@ -175,3 +177,3 @@ Object.keys(values).forEach(function(id) {

var templateName = path.relative(directory, filepath)
.slice(0, -(ext.length)).replace(/[ -]/g, '_');
.slice(0, -(ext.length)).replace(/[ -]/g, '_').replace('\\', '/');
handlebars.registerPartial(templateName, data);

@@ -196,2 +198,25 @@ }

Instance.prototype.localsAsTemplateData = function(app) {
app.render = (function(render) {
return function(view, options, callback) {
if (typeof options === "function") {
callback = options;
options = {};
}
// Mix response.locals (options._locals) with app.locals (this.locals)
options._locals = options._locals || {};
for (var key in this.locals) {
options._locals[key] = this.locals[key];
}
// Store the data again, so that we can differentiate this data from
// the data passed to response.data() when we're inside the view
options._locals.__hbsLocals = options._locals;
return render.call(this, view, options, callback);
};
})(app.render);
};
module.exports = new Instance();

@@ -198,0 +223,0 @@ module.exports.create = function(handlebars) {

4

package.json
{
"name": "hbs",
"description": "Express.js template engine plugin for Handlebars",
"version": "2.6.0",
"version": "2.7.0",
"homepage": "https://github.com/donpark/hbs",

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

}
}
}

@@ -57,2 +57,25 @@ # hbs [![Build Status](https://secure.travis-ci.org/donpark/hbs.png)](http://travis-ci.org/donpark/hbs) #

## Exposing locals as template data ##
hbs has the ability to expose the application and request locals within any context inside a view. To enable this functionality, simply call the `localsAsTemplateData` method and pass in your Express application instance.
```javascript
var hbs = require('hbs');
var express = require('express');
var app = express();
hbs.localsAsTemplateData(app);
app.locals.foo = "bar";
```
The local data can then be accessed using the `@property` syntax:
```
top level: {{@foo}}
{{#each items}}
{{label}}: {{@foo}}
{{/each}}
```
## handlebars ##

@@ -93,1 +116,4 @@

## Helpful Modules ##
- **[hbs-utils](https://github.com/dpolivy/hbs-utils)**: A small utility library that provides helpers for registering and compiling partials, including automatic updates when partials are changed.
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