Merge branch 'integration'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parents 33277c3, 206e800 · Browse files · 3 files·+37 added−5 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+37 added−5 removed
- tests:+10 added−0 removed
- other:+27 added−5 removed
Provenance
- Commit
7d100da- Tree
2aee317- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent 1
33277c3- Parent 2
206e800
3 files changed+37 added−5 removed
modified:lib/express/plugins/view.js+26 added-5 removed
12 unmodified lines13141516171819202122232425268 unmodified lines3536373839404142434445464748495051525354558 unmodified lines6465666768697071725 unmodified lines787980816282838465858687888923 unmodified lines1131141151169711711811912012112 unmodified lines1341351361371181381391401411421431441451461471481281491501511521538 unmodified lines12 unmodified lines */
var engines = {}
/** * Cache partial store */ var partials = {}
// --- View
exports.View = Plugin.extend({ extend: {8 unmodified lines if (!set('views')) set('views', function(){ return set('root') + '/views' }) if (!set('partials')) set('partials', function(){ return set('views') + '/partials' }) // Cache partials in memory if (set('cache view partials')) { var dir = set('partials') fs.readdirSync(dir).each(function(file){ file = dir + '/' + file partials[file] = fs.readFileSync(file) }) } // Request Request.include({ 8 unmodified lines * will have an object "video" available to it. * * @param {string} view * @param {hash} options * @settings 'partials', 'cache view partials' * @return {string} * @api public */ 5 unmodified lines var name = options.as || view.split('.').first options.locals = options.locals || {} return options.collection.map(function(val){ options.locals[name] = val return this.render('partials/' + view, options) return this.render(view, options) }, this).join('') } else return this.render('partials/' + view, options) return this.render(view, options) },
/** * Render _view_ with _options_.23 unmodified lines render: function(view, options) { var self = this, options = options || {}, partial = options.partial, path = set('views') + '/' + view, path = set(partial ? 'partials' : 'views') + '/' + view, type = path.split('.').slice(-2)[0], ext = extname(path), layout = options.layout === undefined ? 'layout' : options.layout options.context = options.context || this12 unmodified lines else self.halt(200, content) } function renderFromDisc() { if (partial) return render(fs.readFileSync(path)) if (partial) return render(partials[path] || fs.readFileSync(path)) fs.readFile(path, function(err, content){ if (err) throw err set('cache view contents') ? self.cache.set('view:' + path, content, function(cache){ render(cache) }) : render(content) }) } if (set('cache view contents')) if (!partial && set('cache view contents')) self.cache.get('view:' + path, function(cache){ if (cache) return render(cache) else return renderFromDisc() })8 unmodified linesmodified:lib/express/core.js+1 added
341 unmodified lines342 })343 344 configure('production', function(){345 enable('cache view contents')346+ enable('cache view partials')347 enable('cache static files')348 })modified:spec/spec.plugins.view.js+10 added
10 unmodified lines11 set('views').should.eql 'spec/views'12 end13 end14 15+ describe 'set("partials")'16+ it 'should default to <views>/partials'17+ set('root', 'spec')18+ set('partials').should.eql 'spec/views/partials'19+ set('views', 'magicland')20+ set('partials').should.eql 'magicland/partials'21+ end22+ end23+ 24 describe '#partial()'25 before_each26 set('views', 'spec/fixtures')27+ set('partials', 'spec/fixtures/partials')28 end29 30 describe 'given a valid view name'31 it 'should render a partial'169 unmodified lines