added Partial.resolveObjectName()
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 · parent 27a9401 · 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
Provenance
- Commit
969f422- Tree
24a038b- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
27a9401
2 files changed+10 added−40 removed
modified:lib/express/view.js+3 added-25 removed
138 unmodified lines139 140 var 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 };145 146 /**15 unmodified lines162 * @return {String}163 * @api private164 */165 167-Partial.prototype.resolveObjectName = function(){166+Partial.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 lines177 }).join('');178 };179 180 /**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- */195-196-function objectName(view) {197- return view.split('/').slice(-1)[0].split('.')[0];198-}199-200-/**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 lines260 options.renderPartial = true;261 options.layout = false;262 263 // Deduce name from view path284- var name = options.as285- || viewNameCache[view]286- || (viewNameCache[view] = objectName(view));264+ var name = options.as || Partial.resolveObjectName(view);265 266 // Collection support267 var collection = options.collection;268 if (collection) {147 unmodified linesmodified:test/view.test.js+7 added-15 removed
91 unmodified lines92 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');99-100- var view = new Partial('/path/to/user-post.ejs');101- view.objectName.should.equal('userPost');102-103- var view = new Partial('/path/to/user_post.ejs');104- view.objectName.should.equal('userPost');105-106- 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