npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ractive-render

v0.4.0

Published

A simple way to render Ractive templates on node.js

Downloads

20

Readme

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 = require('ractive-render');
var template = 'template.html';
var options = { data: { ... } };
var callback = function (err, html) { ... };

rr.renderFile(template, options, callback);

.renderFile() returns a Promise so you can use .then() instead of the callback:

rr.renderFile(template, options).then(callback);

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.renderFile(template, options, callback);

Partials

You can define your partial directly:

options = { data: { ... }, partials: { partial: myPart } };

rr.renderFile(template, options, callback);

Or you can provide a path to the partial:

options = { data: { ... }, partials: { partial: 'partial!path/to/the/partial' } };

rr.renderFile(template, options, callback);

If you have your partials in the same directory as template, you can let ractive-render to take care of the whole process:

rr.config({ autoloadPartials: true }); // you can omit this as it defaults to true

rr.renderFile(template, options, callback);

Components

Just like with partials, you can define your components directly:

options = { data: { ... }, components: { component: myComp } };

rr.renderFile(template, options, callback);

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.renderFile(template, options, callback);

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.use('rvc').config({ componentsLoader: 'rvc' });

Now you can render your components like this:

options = { use: 'rvc', data: { ... } };

rr.renderFile(template, options, callback);

Optionally, use can set RVC as default loader and omit the use parameter.

rr.config({ defaultLoader: 'rvc' });

options = { data: { ... } };

rr.renderFile(template, options, callback);

Ractive load

$ npm install ractive-load

You can use it the same way as the RVC plugin.

Integration with Express

var rr = require('ractive-render');
app.engine('html', rr.renderFile);

app.render(template, options, callback);

Performance

If you set cache to true, ractive-render will cache the templates in memory:

options = { cache: true, data: { ... } };

rr.renderFile(template, options, callback);

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.