Skip to content
Myr

app.engine.js

This file

Path

test/app.engine.js

58 lines · 1.5 KiB · JavaScript

Last changed by

Merge branch 'view-signature'Tj Holowaychukbefore adoption2d77279

History of this file

Take it

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

make sure req/res protos are app-specificTj Holowaychukbefore adoptione27b224

line 1why, one step back
1

Merge branch 'view-signature'Tj Holowaychukbefore adoption2d77279

lines 2–3why, one step back
2var express = require('../')
3 , fs = require('fs');

make sure req/res protos are app-specificTj Holowaychukbefore adoptione27b224

line 4why, one step back
4

Merge branch 'view-signature'Tj Holowaychukbefore adoption2d77279

lines 5–10why, one step back
5function render(path, options, fn) {
6 fs.readFile(path, 'utf8', function(err, str){7 if (err) return fn(err);8 str = str.replace('{{user.name}}', options.user.name);9 fn(null, str);10 });

make sure req/res protos are app-specificTj Holowaychukbefore adoptione27b224

lines 11–58why, one step back
11}
1213describe('app', function(){14 describe('.engine(ext, fn)', function(){15 it('should map a template engine', function(done){16 var app = express();1718 app.set('views', __dirname + '/fixtures');19 app.engine('.html', render);20 app.locals.user = { name: 'tobi' };2122 app.render('user.html', function(err, str){23 if (err) return done(err);24 str.should.equal('<p>tobi</p>');25 done();26 })27 })28 29 it('should work without leading "."', function(done){30 var app = express();3132 app.set('views', __dirname + '/fixtures');33 app.engine('html', render);34 app.locals.user = { name: 'tobi' };3536 app.render('user.html', function(err, str){37 if (err) return done(err);38 str.should.equal('<p>tobi</p>');39 done();40 })41 })42 43 it('should work "view engine" setting', function(done){44 var app = express();4546 app.set('views', __dirname + '/fixtures');47 app.engine('html', render);48 app.set('view engine', 'html');49 app.locals.user = { name: 'tobi' };5051 app.render('user', function(err, str){52 if (err) return done(err);53 str.should.equal('<p>tobi</p>');54 done();55 })56 })57 })58})