Skip to content
Myr

index.js

This file

Path

examples/view-constructor/index.js

47 lines · 1.2 KiB · JavaScript

Last changed by

Merge tag '3.16.7'Douglas Christopher Wilsonbefore adoption9eafaa2

History of this file

Take it

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

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 1–25why, one step back
1/**
2 * Module dependencies.3 */45var express = require('../../');6var http = require('http');7var GithubView = require('./github-view');8var md = require('marked').parse;910var app = module.exports = express();1112// register .md as an engine in express view system13app.engine('md', function(str, options, fn){14 try {15 var html = md(str);16 html = html.replace(/\{([^}]+)\}/g, function(_, name){17 return options[name] || '';18 });19 fn(null, html);20 } catch(err) {21 fn(err);22 }23});2425// pointing to a particular github repo to load files from it

Merge tag '3.16.7'Douglas Christopher Wilsonbefore adoption9eafaa2

line 26why, one step back
26app.set('views', 'strongloop/express');

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 27–38why, one step back
27
28// register a new view constructor29app.set('view', GithubView);3031app.get('/', function(req, res){32 // rendering a view relative to the repo.33 // app.locals, res.locals, and locals passed34 // work like they normally would35 res.render('examples/markdown/views/index.md', { title: 'Example' });36});3738app.get('/Readme.md', function(req, res){

Merge tag '3.16.7'Douglas Christopher Wilsonbefore adoption9eafaa2

line 39why, one step back
39 // rendering a view from https://github.com/strongloop/express/blob/master/Readme.md

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 40–47why, one step back
40 res.render('Readme.md');
41});4243/* istanbul ignore next */44if (!module.parent) {45 app.listen(3000);46 console.log('Express started on port 3000');47}