Skip to content

add filenamePattern option to pass different file extensions #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[*]
end_of_line = lf

[*.{js}]
indent_style = space
indent_size = 2

[*.{json}]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.idea
33 changes: 19 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

};
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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"
Expand Down