ractive-render
A simple way to render Ractive templates on node.js.
Installation
$ npm install ractive-render
Use v0.4.x for Ractive v1.x.x.
Use v0.3.x for Ractive v0.5.x.
Use v0.2.x for Ractive v0.4.0.
Usage
var rr = ;var template = 'template.html';var options = data: ... ;var { ... }; rr;
.renderFile()
returns a Promise so you can use .then()
instead of the callback:
rr;
If you don't specify data
in options
, the whole options
object will be passed to Ractive as data
argument:
options = ... ; // the same as { data: { ... } } rr;
Partials
You can define your partial directly:
options = data: ... partials: partial: myPart ; rr;
Or you can provide a path to the partial:
options = data: ... partials: partial: 'partial!path/to/the/partial' ; rr;
If you have your partials in the same directory as template, you can let ractive-render to take care of the whole process:
rr; // you can omit this as it defaults to true rr;
Components
Just like with partials, you can define your components directly:
options = data: ... components: component: myComp ; rr;
Or you can provide a path. This requires either RVC or load plugin to be installed:
options = data: ... components: component: 'path/to/the/component' ; rr;
Ractive RVC
To use the RVC plugin, you need to install it along with RequireJS:
$ npm install rvc requirejs
Be careful to install the correct RVC version for your version of Ractive:
- for Ractive 0.4.0 use RVC 0.1.3,
- for Ractive 0.5.x use RVC 0.2.x.
- for Ractive 1.x.x use RVC 0.6.x.
Tell ractive-render to use the plugin:
rr;
Now you can render your components like this:
options = use: 'rvc' data: ... ; rr;
Optionally, use can set RVC as default loader and omit the use
parameter.
rr; options = data: ... ; rr;
Ractive load
$ npm install ractive-load
You can use it the same way as the RVC plugin.
Integration with Express
var rr = ;app; app;
Performance
If you set cache
to true
, ractive-render will cache the templates in memory:
options = cache: true data: ... ; rr;
Note that Express does this automatically for production environments. You can clear the cache by calling rr.clearCache()
.
More details
Just look at the code.
License
Copyright (c) 2014 Martin Kolárik. Released under the MIT license.