1.0.0 • Published 6 years ago

consolidate-jstransformer v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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

1.0.0

6 years ago

0.3.0

6 years ago

0.2.0

7 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago