Skip to content
Myr

add "view" constructor setting to override view behaviour

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Caridy Patino · committed by TJ Holowaychuk · parent 49cc1a7 · Browse files · 5 files+131 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+131 added−8 removed

  • tests:+28 added−5 removed
  • other:+103 added−3 removed

5 files+131 added−8 removed

modified:examples/markdown/index.js+2 added-2 removed
added:examples/view-constructor/github-view.js+52 added
added:examples/view-constructor/index.js+47 added
modified:lib/application.js+2 added-1 removed
77 unmodified lines
78 // default locals79 this.locals.settings = this.settings;8081 // default configuration82 this.set('view', View);83 this.set('views', process.cwd() + '/views');84 this.set('jsonp callback name', 'callback');8586 this.configure('development', function(){
392 unmodified lines
479 if (opts.cache) view = cache[name];480481 // view482 if (!view) {482 view = new View(name, {483 view = new (this.get('view'))(name, {484 defaultEngine: this.get('view engine'),485 root: this.get('views'),486 engines: engines487 });
44 unmodified lines
modified:test/app.render.js+28 added-5 removed
12 unmodified lines
13 str.should.equal('<p>tobi</p>');14 done();15 })16 })17 1718 it('should support absolute paths with "view engine"', function(done){19 var app = express();2021 app.set('view engine', 'jade');
17 unmodified lines
39 str.should.equal('<p>tobi</p>');40 done();41 })42 })43 4344 it('should support index.<engine>', function(done){45 var app = express();4647 app.set('views', __dirname + '/fixtures');
60 unmodified lines
108 done();109 })110 })111 })112113 describe('when a "view" constructor is given', function(){114 it('should create an instance of it', function(done){115 var app = express();116117 function View(name, options){118 this.name = name;119 this.path = 'path is required by application.js as a signal of success even though it is not used there.';120 }121122 View.prototype.render = function(options, fn){123 fn(null, 'abstract engine');124 };125126 app.set('view', View);127128 app.render('something', function(err, str){129 if (err) return done(err);130 str.should.equal('abstract engine');131 done();132 })133 })134 })135 })113 136137 describe('.render(name, options, fn)', function(){138 it('should render the template', function(done){139 var app = express();140
6 unmodified lines
147 str.should.equal('<p>tobi</p>');148 done();149 })150 })128 151152 it('should expose app.locals', function(done){153 var app = express();154155 app.set('views', __dirname + '/fixtures');
4 unmodified lines
160 str.should.equal('<p>tobi</p>');161 done();162 })163 })141 164165 it('should give precedence to app.render() locals', function(done){166 var app = express();167168 app.set('views', __dirname + '/fixtures');
11 unmodified lines