Added markdown template engine example

This commit is contained in:
Tj Holowaychuk 2011-03-02 18:37:36 -08:00
parent 42f3ad436d
commit 61aec6e961
2 changed files with 45 additions and 0 deletions

41
examples/markdown/app.js Normal file
View File

@ -0,0 +1,41 @@
// Expose modules in ./support for demo purposes
require.paths.unshift(__dirname + '/../../support');
// $ npm install markdown
/**
* Module dependencies.
*/
var express = require('../../lib/express')
, md = require('markdown').markdown;
var app = express.createServer();
// register .md so that markdown may comply
// with the express view system by implementing
// a .compile() method
app.register('.md', {
compile: function(str, options){
var html = md.toHTML(str);
return function(locals){
return html.replace(/\{([^}]+)\}/g, function(_, name){
return locals[name];
});
};
}
});
// Optional since express defaults to CWD/views
app.set('views', __dirname + '/views');
app.set('view engine', 'md');
app.get('/', function(req, res){
res.render('index', { layout: false, title: 'Markdown Example' });
});
app.listen(3000);
console.log('Express app started on port 3000');

View File

@ -0,0 +1,4 @@
# {title}
Just an example view rendered with _markdown_.