npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

helper-read

0.1.0

@jonschlinkert

npmHomeRepoSnykSocket
Downloads:14
$ npm install helper-read
DailyWeeklyMonthlyYearly

helper-read NPM version

Template helper for reading from the file system. Includes both async and sync versions.

Install

Install with npm

npm i helper-read --save

Usage

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'
});

Related projects

  • 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

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

Author

Jon Schlinkert

  • github/jonschlinkert
  • twitter/jonschlinkert

License

Copyright (c) 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on May 11, 2015.