helper-concat
v0.3.0
Published
Template helper for concatenating a list of files using glob patterns. Should work with handlebars, lodash or any template engine that allows helper functions.
Downloads
788
Maintainers
Readme
helper-concat
Template helper for concatenating a list of files using glob patterns. Should work with handlebars, lodash or any template engine that allows helper functions.
Install with npm
npm i helper-concat --save
Usage examples
concat
Get the contatenated content from a glob of files.
patterns
{String}options
{Options}returns
: {String}
var concat = require('helper-concat');
concat('files/*.md', function(err, content) {
//=> 'AAA\nBBB\nCCC'
});
As a helper:
{{concat 'files/*.md'}}
.sync
Synchronously get the contatenated content from a glob of files.
patterns
{String}options
{Options}returns
: {String}
var concat = require('helper-concat');
concat('files/*.md');
//=> 'AAA\nBBB\nCCC'
As a helper:
{{concat 'files/*.md'}}
Register the helper
This should work with any template engine, here are a few examples
template
Register the helper for use with any template engine
template.helper('concat', require('helper-concat'));
assemble
To register the helper for use with assemble v0.6.x:
assemble.helper('concat', require('helper-concat'));
verb
Register the helper for use with verb:
var verb = require('verb');
verb.helper('concat', require('helper-concat'));
verb.task('default', function() {
verb.src('.verb*.md')
.pipe(verb.dest('./'));
});
handlebars
var handlebars = require('handlebars');
handlebars.registerHelper('concat', require('helper-concat'));
Lo-Dash or underscore
var handlebars = require('handlebars');
handlebars.registerHelper('concat', require('helper-concat'));
// as a mixin
_.mixin({concat: concatHelper});
_.template('<%= _.concat("fixtures/*.txt") %>', {});
//=> 'AAA\nBBB\nCCC'
// passed on the context
var settings = {imports: {concat: concatHelper}};
_.template('<%= concat("fixtures/*.txt") %>', {concat: concatHelper});
//=> 'AAA\nBBB\nCCC'
// as an import
var settings = {imports: {concat: concatHelper}};
_.template('<%= concat("fixtures/*.txt") %>', {}, settings);
//=> 'AAA\nBBB\nCCC'
Running tests
Install dev dependencies.
npm i -d && npm test
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
To request or contribute a helper to the github.com/helpers org, please read this contributing guide to get started.
Author
Jon Schlinkert
License
Copyright (c) 2015 Jon Schlinkert
Released under the MIT license
This file was generated by verb-cli on March 15, 2015.