From 850486dbbbfa83cb3e7dfe01dde72f9cb0f58341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Wr=C3=B3bel?= Date: Sat, 28 Jan 2017 16:29:47 +0100 Subject: [PATCH 1/2] add filenamePattern option to pass different file extensions --- .editorconfig | 10 ++++++++++ .gitignore | 1 + index.js | 33 +++++++++++++++++++-------------- package.json | 6 +++--- 4 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 .editorconfig 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..fd6f70c 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.filnamePattern); + 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" From dcbcce128d043b0402e1a6ae0e826376a8ea39d0 Mon Sep 17 00:00:00 2001 From: mateuszwrobel Date: Sat, 28 Jan 2017 19:02:59 +0100 Subject: [PATCH 2/2] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index fd6f70c..934559b 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ module.exports = function (file, options) { options.filenamePattern = filenamePattern; } - var regexp = new RegExp(options.filnamePattern); + var regexp = new RegExp(options.filenamePattern); if (!regexp.test(file)) return through(); var input = '';