broccoli-handlebars
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -23,2 +23,5 @@ var path = require('path'); | ||
this.context = this.options.context || {}; | ||
this.destFile = this.options.destFile || function (filename) { | ||
return filename.replace(/(hbs|handlebars)$/, 'html'); | ||
}; | ||
this.handlebars = this.options.handlebars || Handlebars; | ||
@@ -72,8 +75,7 @@ | ||
function write (output) { | ||
var targetHTMLFile = targetFile.replace(/(hbs|handlebars)$/, 'html'); | ||
var destFilepath = path.join(destDir, targetHTMLFile); | ||
var destFilepath = path.join(destDir, self.destFile(targetFile)); | ||
mkdirp.sync(path.dirname(destFilepath)); | ||
var str = fs.readFileSync(path.join(sourceDir, targetFile)).toString(); | ||
var template = self.handlebars.compile(str); | ||
fs.writeFileSync(path.join(destDir, targetHTMLFile), template(output)); | ||
fs.writeFileSync(destFilepath, template(output)); | ||
} | ||
@@ -80,0 +82,0 @@ var output = ('function' !== typeof self.context) ? self.context : self.context(targetFile); |
{ | ||
"name": "broccoli-handlebars", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Compile handlebars templates with helpers and dynamic contexts", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/moudy/broccoli-handlebars", |
@@ -23,3 +23,4 @@ # Broccoli Handlebars | ||
, partials: 'partials-path' | ||
, context: function (filename) { return dataForFile(filename); }; | ||
, context: function (filename) { return dataForFile(filename); } | ||
, destFile: function (filename) { return filename.replace(/\.(hbs|handlebars)$/, ''); } | ||
}); | ||
@@ -65,3 +66,15 @@ ``` | ||
#### destFile (optional) | ||
A function that returns the name of a Handlebars-compiled file in the Broccoli output tree. The function is called for every input file, with `filename` supplied. If no function is supplied, the default is for the .hbs or .handlebars suffix of `filename` to be replaced with .html. E.g. `example.hbs` becomes `example.html`. | ||
```js | ||
var tree = broccoliHandlebars(tree, { | ||
destFile: function (filename) { return filename.replace(/\.(hbs|handlebars)$/, ''); } | ||
}); | ||
// Generate output files like Rails sprockets | ||
// example.json.hbs -> example.json | ||
``` | ||
#### helpers (optional) | ||
@@ -68,0 +81,0 @@ An object of helpers or a function that returns an object of helpers. |
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
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
7750
71
103