helper-glob
Version:
Template helper for globbing files. Works with handlebars, Lo-Dash or any template engine that supports helper functions.
78 lines (57 loc) • 1.89 kB
Markdown
> Template helper for globbing files. Works with handlebars, Lo-Dash or any template engine that supports helper functions.
```bash
npm i helper-glob --save
```
**Lo-Dash**
```js
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**
```js
var handlebars = require('handlebars');
var fs = require('fs');
handlebars.registerHelper('glob', require('helper-glob'));
handlebars.registerHelper('read', function(fp) {
return fs.readFileSync(fp, 'utf8');
});
```
```handlebars
{{glob 'files/*.txt'}}
<!-- glob and read files using subexpressions -->
{{
{{read .}}
{{/each}}
```
**Jon Schlinkert**
+ [github/helpers](https://github.com/helpers)
+ [twitter/helpers](http://twitter.com/helpers)
Copyright (c) 2014 Jon Schlinkert
Released under the MIT license
***
_This file was generated by [verb](https://github.com/assemble/verb) on December 06, 2014. To update, run `npm i -g verb && verb`._
[]: https://github.com/assemble/assemble
[]: https://github.com/assemble/generator-verb
[]: https://github.com/assemble/handlebars-helpers/
[]: https://github.com/wycats/handlebars.js/
[]: https://github.com/helpers
[]: https://lodash.com/
[]: https://github.com/jonschlinkert/template
[]: https://github.com/jashkenas/underscore
[]: https://github.com/assemble/verb
[]: https://github.com/helpers/requests