consolidate-jstransformer

1.0.0 • Public • Published

consolidate-jstransformer

Consolidate-compatible API to use JSTransformers.

Build Status Coverage Status Dependency Status Greenkeeper badge NPM version

API

Replace the consolidate package with consolidate-jstransformer.

Before

var cons = require('consolidate')

After

var cons = require('consolidate-jstransformer')

Usage

Use consolidate-jstransformer the same way you would use Consolidate:

var cons = require('consolidate-jstransformer');
cons.swig('views/page.html', { user: 'tobi' }, function(err, html){
  if (err) throw err;
  console.log(html);
});

Or without options / local variables:

var cons = require('consolidate-jstransformer');
cons.swig('views/page.html', function(err, html){
  if (err) throw err;
  console.log(html);
});

To dynamically pass the engine, simply use the subscript operator and a variable:

var cons = require('consolidate-jstransformer')
  , name = 'swig';
 
cons[name]('views/page.html', { user: 'tobi' }, function(err, html){
  if (err) throw err;
  console.log(html);
});

Render strings rather than files:

var cons = require('consolidate-jstransformer')
  , name = 'swig';
 
cons[name].render('Hello {{ user }}', { user: 'tobi' }, function(err, html){
  if (err) throw err;
  console.log(html);
});

Promises

If no callback function is provided, a Promise will be returned.

var cons = require('consolidate-jstransformer');
 
cons.swig('views/page.html', { user: 'tobi' })
  .then(function (html) {
    console.log(html);
  })
  .catch(function (err) {
    throw err;
  });

License

MIT

Package Sidebar

Install

npm i consolidate-jstransformer

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

7.05 kB

Total Files

5

Last publish

Collaborators

  • calebeby
  • forbeslindesay
  • hemanth
  • robloach
  • stoeffel
  • timothygu