Skip to content
Myr

Merge branch 'views'

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

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parents 27a9401, 969f422 · Browse files · 2 files+10 added−40 removed
This commit

State

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

Diff stats

2 files+10 added−40 removed

  • tests:+7 added−15 removed
  • other:+3 added−25 removed

2 files+10 added−40 removed

modified:lib/express/view.js+3 added-25 removed
138 unmodified lines
139140var Partial = exports.Partial = function Partial(view, options) {141 options = options || {};142 View.call(this, view, options);143 this.objectName = options.as || this.resolveObjectName();143 this.path = this.dirname + '/_' + basename(this.path);144};145146/**
15 unmodified lines
162 * @return {String}163 * @api private164 */165167Partial.prototype.resolveObjectName = function(){166Partial.resolveObjectName = function(view){167 // TODO: cache169 return this.view168 return view169 .split('/')170 .slice(-1)[0]171 .split('.')[0]172 .replace(/[^a-zA-Z0-9 ]+/g, ' ')
4 unmodified lines
177 }).join('');178};179180/**182 * Return object name deduced from the given `view` path.183 *184 * Examples:185 *186 * "movie/director" -> director187 * "movie.director" -> director188 * "forum/thread/post" -> post189 * "forum/thread.post" -> post190 *191 * @param {String} view192 * @return {String}193 * @api private194 */195196function objectName(view) {197 return view.split('/').slice(-1)[0].split('.')[0];198}199200/**181 * Register the given template engine `exports`182 * as `ext`. For example we may wish to map ".html"183 * files to jade:184 *
75 unmodified lines
260 options.renderPartial = true;261 options.layout = false;262263 // Deduce name from view path284 var name = options.as285 || viewNameCache[view]286 || (viewNameCache[view] = objectName(view));264 var name = options.as || Partial.resolveObjectName(view);265266 // Collection support267 var collection = options.collection;268 if (collection) {
147 unmodified lines
modified:test/view.test.js+7 added-15 removed
91 unmodified lines
92 var view = new View(__dirname + '/fixtures/hello.jade');93 view.templateEngine.should.equal(require('jade'));94 },95 96 'test Partial#objectName': function(){97 var view = new Partial('/path/to/user.ejs');98 view.objectName.should.equal('user');99100 var view = new Partial('/path/to/user-post.ejs');101 view.objectName.should.equal('userPost');102103 var view = new Partial('/path/to/user_post.ejs');104 view.objectName.should.equal('userPost');105106 var view = new Partial('/path/to/forum thread post.ejs');107 view.objectName.should.equal('forumThreadPost');108 109 var view = new Partial('/path/to/forum thread post.ejs', { as: 'post' });110 view.objectName.should.equal('post');96 'test Partial.resolveObjectName()': function(){97 var resolve = Partial.resolveObjectName;98 resolve('/path/to/user.ejs').should.equal('user');99 resolve('/path/to/user-post.ejs').should.equal('userPost');100 resolve('/path/to/user post.ejs').should.equal('userPost');101 resolve('forum thread post.ejs').should.equal('forumThreadPost');102 resolve('forum thread post.ejs').should.equal('forumThreadPost');103 },104 105 'test Partial#path for partials': function(){106 var view = new Partial('user.ejs', { root: '/www' });
659 unmodified lines