consolidate-jstransformer
v1.0.0
Published
Consolidate-compatible API to use JSTransformers.
Downloads
18
Readme
consolidate-jstransformer
Consolidate-compatible API to use JSTransformers.
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