1.0.1 • Published 9 years ago

koa-cheerio v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

koa-cheerio

Simple templating for koa using cheerio. You can use your jQuery knowledge for server-side templating.

Installation

npm install koa-cheerio

Example

views/index.html

<html>
<body>
Hello <span id='hello'></span>!
</body>
</html>
var app = require('koa')();
var render = require('koa-cheerio');

app.use(render({ root: 'views/', ext: '.html' }));

app.use(function *index(next) {
  var $ = yield this.render('index');
  $('#hello').text('World');
});

app.listen(3000);

You can also pass an extra object if you need to modify any of the default parsing options:

var $ = yield this.render('index', {
  normalizeWhitespace: true,
  xmlMode: true
});

Comment from the cheerio-readme: These parsing options are taken directly from htmlparser2, therefore any options that can be used in htmlparser2 are valid in cheerio as well. The default options are:

{
    normalizeWhitespace: false,
    xmlMode: false,
    decodeEntities: true
}

License

MIT