Skip to content

korbai/koa-cheerio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

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

About

Koa view render based on Cheerio for simple templating

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published