beardcomb

Hogan.js adapter for Express.js applications, with support for file-based partials and foundation template.

npm install beardcomb
14 downloads in the last week
28 downloads in the last month

Build Status

Beardcomb v0.3.1

Hogan.js adapter for Express.js applications, with support for file-based partials and foundation template.

Installation

For Express 3.x users:

NPM

For Express 2.x users, install version 0.2.3

npm install beardcomb@0.2.3

How to use

Express 3.x

var express = require('express'),
    beardcomb = require('../lib/beardcomb'),
    app = express(),
    server = require('http')
        .createServer(app)
        .listen(8081);

// express config
app.engine('html', beardcomb);
app.set('view engine', 'html')
app.set("views", __dirname + '/views');
app.use(express.static(__dirname + '/public'));

app.get('/', function(req, res) {
    res.render('index', {
        locals: {
            title: 'Beardcomb'
        },
        partials: {
            footer: '<p align="center">Powered by {{title}}</p>'
        },
        foundation: 'layout.html'
    });    
});

Express 2x (with beardcomb@0.2.3)

var express = require('express'),
    app = express.createServer(),
    beardcomb = require('beardcomb');

//express config
app.set('view engine', 'html')
app.set("views", __dirname + '/views');
app.register(".html", beardcomb);
app.use(express.static(__dirname + '/public'));

app.get('/', function(req, res) {
    res.render('index', {
        locals: {
            title: 'Beardcomb'
        },
        partials: {
            footer: '<p align="center">Powered by {{title}}</p>'
        }
    });    
});

app.listen(8080);

Features

  • Foundation template: create a file called 'layout.html' and add the tag {{{contents}}}, it will parse the view contents into it
  • Partials can be passed either as html code as seen above, or as a template file
  • Support for recursive lookup of partials template files
  • NEW in 0.3.0! Support for Express.js 3.x (for Express.js 2.x, use beardcomb@0.2.3)
  • NEW in 0.3.0! Support for custom foundation template name (via options.foundation)
  • EXPERIMENTAL (0.3.1 only) Support for multiple views folders (via express patch, see demo/express-patch.js)

Demo

npm install
node demo/app.js

Test

npm test

Contributors

jcole
jesusabdullah

License

The MIT License (MIT) Copyright (c) 2012, 2013 Stephane P. Pericat

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

npm loves you