diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..61c90f2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +[*] +end_of_line = lf + +[*.{js}] +indent_style = space +indent_size = 2 + +[*.{json}] +indent_style = space +indent_size = 2 diff --git a/.gitignore b/.gitignore index 3c3629e..eb79dd5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +.idea diff --git a/index.js b/index.js index a0be123..934559b 100644 --- a/index.js +++ b/index.js @@ -4,23 +4,28 @@ var through = require('through'); var filenamePattern = /\.(html|handlebars|hbs)$/; var wrap = function (template) { - return 'var templater = require("handlebars/runtime")["default"].template;' + - 'module.exports = templater(' + template + ');' + return 'var templater = require("handlebars/runtime")["default"].template;' + + 'module.exports = templater(' + template + ');' } -module.exports = function (file) { - if (!filenamePattern.test(file)) return through(); +module.exports = function (file, options) { + if (!options.filenamePattern) { + options.filenamePattern = filenamePattern; + } - var input = ''; - var write = function (buffer) { - input += buffer; - } + var regexp = new RegExp(options.filenamePattern); + if (!regexp.test(file)) return through(); - var end = function () { - this.queue(wrap(handlebars.precompile(input))); - this.queue(null); - } + var input = ''; + var write = function (buffer) { + input += buffer; + }; - return through(write, end); + var end = function () { + this.queue(wrap(handlebars.precompile(input))); + this.queue(null); + }; -} + return through(write, end); + +}; diff --git a/package.json b/package.json index c787338..b833ee9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "browserify-handlebars", - "version": "1.0.0", + "version": "1.1.0", "description": "browserify transform for handlebars template files", "main": "index.js", "scripts": { @@ -22,10 +22,10 @@ }, "homepage": "https://github.com/dlmanning/browserify-handlebars", "dependencies": { - "through": "~2.3.4" + "through": "~2.3.8" }, "devDependencies": { - "handlebars": "~1.2.0" + "handlebars": "~4.0.5" }, "peerDependencies": { "handlebars": ">= 1.2.0"