Fractal template engine adapters
Work-in-progress template engine adapters for Fractal v2.
Overview
This repository contains a collection of template engine adapters for Fractal that can be used to render HTML output of component view files.
The currently available adapters are:
- React
- Nunjucks
- Handlebars
const fractal = require('@frctl/fractal');
const adapters = require('@frctl/adapters');
const parser = fractal({
src: './path/to/components',
adapters: [
adapters.nunjucks
]
});
parser.parse(function(err, components) {
if (err) {
return console.log(err);
}
const component = components.find({
name: 'button'
});
const view = component.files.find({
role: 'view',
adapter: 'nunjucks'
}); // get the nunjucks template for the 'button' component
components.renderView(view, {label: 'Click me!'}, function(err, html){
console.log(html);
});
});
Installation
The adapters in this repository are included with Fractal by default so do not need to be installed manually.
However, the underlying template engines do need to be installed in your project before the corresponding adapter can be used.
Nunjucks
npm i nunjucks --save
Handlebars
npm i handlebars --save
React
npm i react react-dom babel-register babel-preset-es2015 babel-preset-react --save
Requirements
Node >= v6.0 is required.