-
Notifications
You must be signed in to change notification settings - Fork 15.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added markdown template engine example
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
# {title} | ||
|
||
Just an example view rendered with _markdown_. |