Comparing version 0.0.7 to 1.0.0
@@ -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`. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
1
6778
1
12
98
41
+ Addedhandlebars@>= 1.0.0
+ Addedhandlebars@4.7.8(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedneo-async@2.6.2(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addeduglify-js@3.19.3(transitive)
+ Addedwordwrap@1.0.0(transitive)