https://github.com/jstransformers/consolidate-jstransformer
Consolidate-compatible API for JSTransformers.
https://github.com/jstransformers/consolidate-jstransformer
Last synced: 11 months ago
JSON representation
Consolidate-compatible API for JSTransformers.
- Host: GitHub
- URL: https://github.com/jstransformers/consolidate-jstransformer
- Owner: jstransformers
- License: mit
- Created: 2015-06-27T16:20:25.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2020-04-26T02:40:35.000Z (about 6 years ago)
- Last Synced: 2024-11-13T04:04:23.821Z (over 1 year ago)
- Language: JavaScript
- Homepage: http://npm.im/consolidate-jstransformer
- Size: 68.4 KB
- Stars: 2
- Watchers: 7
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE.md
Awesome Lists containing this project
README
# consolidate-jstransformer
[Consolidate](https://github.com/tj/consolidate.js)-compatible API to use [JSTransformers](http://github.com/jstransformers).
[](https://travis-ci.org/jstransformers/consolidate-jstransformer)
[](https://codecov.io/gh/jstransformers/consolidate-jstransformer)
[](http://david-dm.org/jstransformers/consolidate-jstransformer)
[](https://www.npmjs.org/package/consolidate-jstransformer)
## API
Replace the `consolidate` package with `consolidate-jstransformer`.
### Before
``` javascript
var cons = require('consolidate')
```
### After
``` javascript
var cons = require('consolidate-jstransformer')
```
### Usage
Use `consolidate-jstransformer` the same way you would use Consolidate:
```js
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:
```js
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:
```js
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:
```js
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.
```js
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