Started specs for views
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 3a6ddd1 · Browse files · 5 files·+97 added−1 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+97 added−1 removed
- tests:+39 added−0 removed
- other:+58 added−1 removed
Provenance
- Commit
eaa399f- Tree
9ffba80- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
3a6ddd1
5 files changed+97 added−1 removed
modified:lib/express/view.js+5 added-1 removed
1223456
// Express - View - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)No newline at end of file// Express - View - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
exports.render = function(view) { }No newline at end of fileadded:lib/support/ejs.js+53 added
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253/* Ejs template parser for CommonJS * * Copyright (c) 2009, Howard Rauscher * Licensed under the MIT License * * base on: * Simple JavaScript Templating (http://ejohn.org/blog/javascript-micro-templating/) * John Resig - http://ejohn.org/ - MIT Licensed */ (function(){ var cache = {}; var ejs = this.ejs = {}; ejs.parse = function tmpl(str, options) { options = options || {}; options.context = options.context || {}; options.locals = options.locals || {}; // Figure out if we're getting a template, or if we need to // load the template - and be sure to cache the result. var fn = cache[str] || // Generate a reusable function that will serve as a template // generator (and which will be cached). new Function("obj", "var p=[];" + // Introduce the data as local variables using with(){} "with(obj){p.push('" + // Convert the template into pure JavaScript str .replace(/\-%>(\n|\r)/g, "%>") .replace(/[\t\b\f]/g, " ") .replace(/[\n\r]/g, "\f") .split("<%").join("\t") .replace(/((^|%>)[^\t]*)'/g, "$1\r") .replace(/\t=(.*?)%>/g, "',$1,'") .split("\t").join("');") .split("%>").join("p.push('") .split("\r").join("\\'").replace(/\f+/g, '\\n') + "');}return p.join('');"); cache[str] = fn; // Provide some basic currying to the user return fn.call(options.context, options.locals); };})(); exports.parse = ejs.parse;No newline at end of fileadded:spec/fixtures/user.html.ejs+2 added
1+<h1><%= this.name %></h1>2+<p><%= this.email %></p>modified:spec/spec.node.js+1 added
25 unmodified lines2627282930313233342 unmodified lines25 unmodified lines .exec('spec/spec.routing.js') .exec('spec/spec.helpers.js') .exec('spec/spec.mime.js') .exec('spec/spec.collection.js') .exec('spec/spec.view.js') .exec('spec/spec.plugins.js') .exec('spec/spec.plugins.common-logger.js') .exec('spec/spec.plugins.content-length.js') .exec('spec/spec.plugins.method-override.js')2 unmodified linesadded:spec/spec.view.js+36 added
123456789101112131415161718192021222324252627282930313233343536
describe 'Express' before_each reset() set('views', dirname(__filename) + '/fixtures') user = { name: 'TJ', email: 'tj@vision-media.ca' } end
describe 'render()' describe 'given *.ejs' it 'should render an ejs view' get('/user', function(){ render('user.html.ejs', { context: user }, function(content){ halt(200, content) }) }) p(get('/user').body) end end describe 'given *.*' it 'should render the contents' end end describe 'given a file which does not exist' it 'should throw ViewNotFound' end end endendNo newline at end of file