Comparing version 0.1.5 to 1.0.0
23
index.js
@@ -6,5 +6,10 @@ /*jshint node: true*/ | ||
module.exports = function(file) { | ||
if (!/\.hbs|\.handlebars/.test(file)) return through(); | ||
var extensions = { | ||
hbs: 1, | ||
handlebar: 1 | ||
}; | ||
function hbsfy(file) { | ||
if (!extensions[file.split(".").pop()]) return through(); | ||
var buffer = ""; | ||
@@ -18,3 +23,4 @@ | ||
// Compile only with the runtime dependency. | ||
var compiled = "var Handlebars = require('handlebars-runtime');\n"; | ||
var compiled = "// hbsfy compiled Handlebars template\n"; | ||
compiled += "var Handlebars = require('hbsfy/runtime');\n"; | ||
compiled += "module.exports = Handlebars.template(" + js.toString() + ");\n"; | ||
@@ -27,1 +33,12 @@ this.queue(compiled); | ||
hbsfy.configure = function(opts) { | ||
if (!opts || !opts.extensions) return hbsfy; | ||
extensions = {}; | ||
opts.extensions.forEach(function(ext) { | ||
extensions[ext] = 1; | ||
}); | ||
return hbsfy; | ||
}; | ||
module.exports = hbsfy; | ||
{ | ||
"name": "hbsfy", | ||
"version": "0.1.5", | ||
"version": "1.0.0", | ||
"description": "Handlebars precompiler plugin for Browserify v2", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node test/test.js" | ||
"test": "sh test.sh" | ||
}, | ||
@@ -24,12 +24,11 @@ "repository": { | ||
"dependencies": { | ||
"through": "~2.2.7", | ||
"handlebars": "~1.0.12" | ||
"through": "~2.2.7" | ||
}, | ||
"peerDependencies": { | ||
"handlebars-runtime": "~1.0.12" | ||
"handlebars": "~1.0.12" | ||
}, | ||
"devDependencies": { | ||
"browserify": "~2.4.0", | ||
"handlebars-runtime": "~1.0.12" | ||
"browserify": "~2.35.1", | ||
"concat-stream": "~1.1.0" | ||
} | ||
} |
@@ -7,4 +7,4 @@ [![Build Status](https://travis-ci.org/epeli/node-hbsfy.png?branch=master)](https://travis-ci.org/epeli/node-hbsfy) | ||
Compiles Handlebars templates to plain Javascript. The compiled templates | ||
depend only on [handlebars-runtime][] so they are lightweight and fast! | ||
Compiles Handlebars templates to plain Javascript. The compiled templates only | ||
have one copy of the Handlebars runtime so they are lightweight and fast! | ||
@@ -17,3 +17,3 @@ ## Usage | ||
Handlebars runtime will be automatically installed as [peer dependency][]. | ||
Handlebars will be automatically installed as [peer dependency][]. | ||
@@ -26,2 +26,3 @@ Then use it as Browserify transform module with `-t`: | ||
```javascript | ||
@@ -38,2 +39,18 @@ var template = require("./template.hbs"); | ||
## Programmatic usage | ||
When compiling using Javascript code custom extensions | ||
can be set: | ||
```javascript | ||
var hbsfy = require("hbsfy").configure({ | ||
extensions: ["html"] | ||
}); | ||
var browserify = require("browserify"); | ||
var b = browserify("./index.js"); | ||
b.transform(hbsfy); | ||
b.bundle().pipe(fs.createWriteStream("./bundle.js"); | ||
``` | ||
### Helpers | ||
@@ -45,3 +62,3 @@ | ||
```javascript | ||
var Handlebars = require("handlebars-runtime"); | ||
var Handlebars = require("hbsfy/runtime"); | ||
Handlebars.registerHelper("upcase", function(s) { | ||
@@ -63,2 +80,13 @@ return s.toUpperCase(); | ||
## Changelog | ||
### 1.0.0 | ||
- Remove `handlebars-runtime` dependency and depend directly on | ||
the `handlebars` module as a [peer dependency][]. | ||
- Runtime must be now required with `require("hbsfy/runtime")` instead of | ||
`require("handlebars-runtime")`. | ||
- Thanks to @kamicane for teaching me how to do this. | ||
- Option to configure template extensions | ||
## Browserify? | ||
@@ -72,3 +100,2 @@ | ||
[Browserify v2]: https://github.com/substack/node-browserify | ||
[handlebars-runtime]: https://npmjs.org/package/handlebars-runtime | ||
[peer dependency]: http://blog.nodejs.org/2013/02/07/peer-dependencies/ |
@@ -6,4 +6,4 @@ /*jshint node: true*/ | ||
var hbsfy = require("../index"); | ||
var Handlebars = require("handlebars-runtime"); | ||
var hbsfy = require("hbsfy"); | ||
var Handlebars = require("hbsfy/runtime"); | ||
@@ -10,0 +10,0 @@ Handlebars.registerHelper("upcase", function(s) { |
Sorry, the diff of this file is not supported yet
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
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
23528
2
24
447
1
95
5
- Removedhandlebars@~1.0.12
- Removedhandlebars-runtime@1.0.12(transitive)