Skip to content
Myr

index.js

This file

Path

examples/view-constructor/index.js

48 lines · 1.2 KiB · JavaScript

Last changed by

tests: exclude untestable lines in examples from coverageDouglas Christopher Wilsonbefore adoptionc18c2a8

History of this file

Take it

The walk stopped after 200 commits: lines older than a10f695 point at it.

pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695

lines 1–43why, one step back
1
2/**3 * Module dependencies.4 */56var express = require('../../')7 , http = require('http')8 , GithubView = require('./github-view')9 , md = require('marked').parse;1011var app = module.exports = express();1213// register .md as an engine in express view system14app.engine('md', function(str, options, fn){15 try {16 var html = md(str);17 html = html.replace(/\{([^}]+)\}/g, function(_, name){18 return options[name] || '';19 })20 fn(null, html);21 } catch(err) {22 fn(err);23 }24})2526// pointing to a particular github repo to load files from it27app.set('views', 'visionmedia/express');2829// register a new view constructor30app.set('view', GithubView);3132app.get('/', function(req, res){33 // rendering a view relative to the repo.34 // app.locals, res.locals, and locals passed35 // work like they normally would36 res.render('examples/markdown/views/index.md', { title: 'Example' });37})3839app.get('/Readme.md', function(req, res){40 // rendering a view from https://github.com/visionmedia/express/blob/master/Readme.md41 res.render('Readme.md');42})43

tests: exclude untestable lines in examples from coverageDouglas Christopher Wilsonbefore adoptionc18c2a8

line 44why, one step back
44/* istanbul ignore next */

pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695

lines 45–48why, one step back
45if (!module.parent) {
46 app.listen(3000);47 console.log('Express started on port 3000');48}