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.1.0 to 2.3.0

examples/partial/views/partials/partial1.html

1

examples/partial/app.js

@@ -12,2 +12,3 @@

hbs.registerPartial('partial', fs.readFileSync(__dirname + '/views/partial.hbs', 'utf8'));
hbs.registerPartials(__dirname + '/views/partials');

@@ -14,0 +15,0 @@ // set the view engine to use handlebars

@@ -6,2 +6,5 @@

// handle simple flow control
var after = require('after');
// handle async helpers

@@ -163,2 +166,36 @@ var async = require('./async');

Instance.prototype.registerPartials = function (directory, done) {
var handlebars = this.handlebars;
var register = function(filepath, done) {
var isValidTemplate = /\.(html|hbs)$/.test(filepath);
if (!isValidTemplate) {
return done(null);
}
fs.readFile(filepath, 'utf8', function(err, data) {
if (!err) {
var templateName = path.basename(filepath, path.extname(filepath));
templateName = templateName.replace(/[ -]/g, '_');
handlebars.registerPartial(templateName, data);
}
done(err);
});
};
fs.readdir(directory, function(err, filenames) {
if (err) {
return done(err);
}
var next = after(filenames.length, done || function() {});
filenames.forEach(function(filename) {
register(path.join(directory, filename), next);
});
});
};
Instance.prototype.registerAsyncHelper = function(name, fn) {

@@ -165,0 +202,0 @@ this.handlebars.registerHelper(name, function(context) {

5

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

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

"dependencies": {
"handlebars": "1.0.9"
"handlebars": "1.0.9",
"after": "0.7.0"
},

@@ -15,0 +16,0 @@ "devDependencies": {

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

For convenience, `registerPartials` provides a quick way to load all partials from a specific directory:
```javascript
var hbs = require('hbs');
hbs.registerPartials(__dirname + '/views/partials');
```
Partials that are loaded from a directory are named based on their filename, where spaces and hyphens are replaced with an underscore character:
```
template.html -> {{> template}}
template 2.html -> {{> template_2}}
login view.hbs -> {{> login_view}}
template-file.html -> {{> template_file}}
```
See the [handlebars.js](http://github.com/wycats/handlebars.js) README and docs for more information.

@@ -40,0 +57,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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