Higher level thunk-based template rendering for Co and others, built on co-render
$ npm install co-views
And install whichever engine(s) you use:
$ npm install ejs jade
mapan object mapping extension names to engine names [
defaultdefault extension name to use when missing [
cachecached compiled functions [NODE_ENV != 'development']
For example if you wanted to use "swig" for .html files you would simply pass:
map: html: 'swig'
Set the default template extension when none is passed to the render function. This defaults to "html". For example if you mostly use Jade, then you'd likely want to assign this to:
Allowing you to invoke
render('user') instead of
When true compiled template functions will be cached in-memory, this prevents subsequent disk i/o, as well as the additional compilation step that most template engines peform. By default this is enabled when the NODE_ENV environment variable is anything but "development", such as "stage" or "production".
Render several users with different template engines in parallel. View
lookup is performed relative to the
./examples directory passed,
and the "swig" engine is mapped to ".html" files.
var co = require'co';var views = require'co-views';var render = views'examples'map: html: 'swig';var tobi =name: 'tobi'species: 'ferret';var loki =name: 'loki'species: 'ferret';var luna =name: 'luna'species: 'cat';covar a = render'user' user: tobi ;var b = render'user.jade' user: loki ;var c = render'user.ejs' user: luna ;var html = yield a b c;html = htmljoin'';console.loghtml;;
Dependending on your choice of application structure, you may wish to
share these same settings between all of your application, instead of
constantly initializing co-views. To do this simply create a
module and export the render function returned:
var views = require'co-views';moduleexports = views'views'map:html: 'swig'md: 'hogan';