Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including co-view with all npm packages installed. Try it out:

var coView = require("co-view")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

co-view v0.0.1

Higher level thunk-based template rendering for Co and others, built on co-render

co-render

Template rendering for co using co-render. This module provides higher level sugar than co-render to reduce redundancy, for example specifying a views directory and default extension name.

Installation

$ npm install co-views

And install whichever engine(s) you use:

$ npm install ejs jade

Options

  • map an object mapping extnames to engine names [{}]
  • ext default esxtname to use when missing [html]

map

For example if you wanted to use "swig" for .html files you would simply pass:

{ map: { html: 'swig' } }

ext

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:

{ ext: 'jade' }

Allowing you to invoke render('user') instead of render('user.jade').

Example

Render several users with different template engines in parallel:

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'
};

co(function *(){
  var 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 = html.join('');
  console.log(html);
});

License

MIT

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free