Template helper for reading from the file system. Includes both async and sync versions.
Install with npm
npm i helper-read --save
var read = require('helper-read');
Usage with lodash
var ctx = {read: read.sync};
_.template('<%= read("fixtures/a.txt") %>')(ctx);
//=> 'AAA'
_.template('<%= read("fixtures/b.txt") %>')(ctx);
//=> 'BBB'
Usage with Template
var read = require('helper-read');
var Template = require('template');
var template = new Template();
/**
* Register an engine
*/
template.engine('foo', require('engine-lodash'));
/**
* Register the helper
*/
template.asyncHelper('read', read);
/**
* Add some templates
*/
template.page('abc.foo', '<%= read("fixtures/a.txt") %>');
template.page('xyz.foo', '<%= read("fixtures/b.txt") %>');
/**
* Render the templates
*/
template.render('abc.foo', function (err, contents) {
if (err) console.log(err);
console.log(contents);
//=> 'AAA'
});
template.render('xyz.foo', function (err, contents) {
if (err) console.log(err);
console.log(contents);
//=> 'BBB'
});
- assemble: Static site generator for Grunt.js, Yeoman and Node.js. Used by Zurb Foundation, Zurb Ink, H5BP/Effeckt,… more
- template: Render templates using any engine. Supports, layouts, pages, partials and custom template types. Use template… more
- template-helpers: Generic JavaScript helpers that can be used with any template engine. Handlebars, Lo-Dash, Underscore, or… more
- verb: Documentation generator for GitHub projects. Extremely powerful, easy to use, can generate anything from API… more
Install dev dependencies:
npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Jon Schlinkert
Copyright (c) 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on May 11, 2015.