Skip to content

Commit

Permalink
Added markdown template engine example
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Mar 3, 2011
1 parent 42f3ad4 commit 61aec6e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
41 changes: 41 additions & 0 deletions examples/markdown/app.js
Original file line number Diff line number Diff line change
@@ -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');
4 changes: 4 additions & 0 deletions examples/markdown/views/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

# {title}

Just an example view rendered with _markdown_.

0 comments on commit 61aec6e

Please sign in to comment.