Jade template render helper for connect
$ npm install connect-jade
// require lib
var connectJade = require('connect-jade');
var connect = require('connect');
// initialize connect app
var app = connect();
app.use(connectJade({
root: __dirname + "/views",
debug: true,
defaults: {
title: "No title"
keywords: "node, connect, jade, template"
}
})
);
// in routes
var items = [1, 2, 3, 4];
res.render('index', { title: 'Index Page', items: items });
// require lib
var connectJade = require('connect-jade');
var connect = require('connect');
// initialize connect app
var app = connect();
app.use(Connect.session({
secret: Configuration.Session.secret,
cookie: {
maxAge: 60000
}
})
);
// it is stupid because I redefine user in each request
// but better solution is longer
// and not ass-simple
// :) sorry
app.use(function addUserFromSession(req, res, next) {
if (typeof req.session.user != "undefined") {
res.addVariable('user', req.session.user);
} else {
res.addVariable('user', {name: "Anonymous"});
}
next();
});
app.use(connectJade({
root: __dirname + "/views",
debug: true
})
);
please check tests [line 60 - addSomeHelper]
Self:
git clone https://github.com/Folyam/connect-jade.git
cd connect-jade
npm test