helper-glob
v0.1.0
Published
Template helper for globbing files. Works with handlebars, Lo-Dash or any template engine that supports helper functions.
Downloads
218
Maintainers
Readme
helper-glob
Template helper for globbing files. Works with handlebars, Lo-Dash or any template engine that supports helper functions.
Install with npm
npm i helper-glob --save
Usage
Lo-Dash
var _ = require('lodash');
_.template('<%= glob("files/*.txt") %>', {
glob: require('helper-glob')
});
// glob and read files
var fs = require('fs');
_.template('<%= _.map(glob("files/*.txt"), read) %>', {
glob: require('helper-glob'),
read: function(fp) {
return fs.readFileSync(fp, 'utf8');
}
});
Handlebars
var handlebars = require('handlebars');
var fs = require('fs');
handlebars.registerHelper('glob', require('helper-glob'));
handlebars.registerHelper('read', function(fp) {
return fs.readFileSync(fp, 'utf8');
});
{{glob 'files/*.txt'}}
<!-- glob and read files using subexpressions -->
{{#each (glob "files/*.hbs")}}
{{read .}}
{{/each}}
Author
Jon Schlinkert
License
Copyright (c) 2014 Jon Schlinkert
Released under the MIT license
This file was generated by verb on December 06, 2014. To update, run npm i -g verb && verb
.