Comparar commits

...

33 Commits

Autor SHA1 Mensagem Data
Tj Holowaychuk 80f4d08e8b Release 2.0.0rc 2011-03-14 15:01:37 -07:00
Tj Holowaychuk 07c9cae923 Fixed; expose HTTPSServer constructor 2011-03-14 14:36:22 -07:00
Tj Holowaychuk d867cc9271 Fixed express(1) default test charset. Cloeses #579 [reported by secoif] 2011-03-13 10:15:53 -07:00
Tj Holowaychuk 3a1fe1e295 Fixed; default charset to utf-8 instead of utf8 for lame IE [reported by NickP] 2011-03-11 16:34:41 -08:00
Tj Holowaychuk 3cacf050df Docs for staticProvider() changes 2011-03-11 14:11:45 -08:00
Tj Holowaychuk 1536d73d1b Release 2.0.0beta3 2011-03-09 15:45:55 -08:00
Tj Holowaychuk 55143a9d44 Updated connect submodule 2011-03-09 15:39:10 -08:00
Tj Holowaychuk c92e193916 Fixed res.redirect(). RFC states absolute 2011-03-09 15:18:22 -08:00
Tj Holowaychuk d12452fc49 docs for charset 2011-03-09 10:59:47 -08:00
Tj Holowaychuk 3d8400a40c docs for res.contentType() literal 2011-03-09 10:54:35 -08:00
Tj Holowaychuk 1fe0aea0b0 Added test for res.contentType() literal 2011-03-09 10:53:50 -08:00
Tj Holowaychuk 5df2544883 fixed a test 2011-03-09 10:46:59 -08:00
Tj Holowaychuk acbf224277 default res.send() string charset to utf8 2011-03-09 10:42:14 -08:00
Tj Holowaychuk d0d17a0d35 charset tests using ISO-8859-1 2011-03-09 10:33:28 -08:00
Tj Holowaychuk f7b53d33bc more tests 2011-03-09 10:33:06 -08:00
Tj Holowaychuk 92be06874b more tests 2011-03-09 10:31:45 -08:00
Tj Holowaychuk f327455d9d Added charset option for render() 2011-03-09 10:31:10 -08:00
Tj Holowaychuk 54415bf2af moved a test 2011-03-09 10:29:03 -08:00
Tj Holowaychuk bac62dfcd9 added charset test with res.render() 2011-03-09 10:26:37 -08:00
Tj Holowaychuk 820b43c1f3 Added .charset + res.send() test 2011-03-09 10:23:05 -08:00
Tj Holowaychuk a5b69290d5 fixed a test 2011-03-09 10:20:44 -08:00
Tj Holowaychuk 5c7a9c86f6 Updated connect submodule 2011-03-09 10:20:03 -08:00
Tj Holowaychuk 7f83f916f6 Updated jade submodule 2011-03-09 09:46:47 -08:00
Masahiro Hayashi c15a949cc3 Updated express command
- Fixed a genereated test's bug
- Added a forgotten semicolon
2011-03-08 13:42:06 -08:00
Tj Holowaychuk ce47f96570 dont change NODE_ENV in tests 2011-03-08 13:39:30 -08:00
Tj Holowaychuk 57b035cd94 hinting at fully resolved paths 2011-03-08 12:58:16 -08:00
Tj Holowaychuk f1f126171c Added view resolution hints when in development 2011-03-08 12:51:40 -08:00
Tj Holowaychuk 71e1bcd855 fixed a test 2011-03-08 12:02:35 -08:00
Tj Holowaychuk b5579b6307 Added layout lookup support relative to the page view
for example if you render ./views/forum/thread and
./views/forum/thread/layout.jade exists, it will be used,
falling back on ./views/layout.jade.
2011-03-08 12:01:45 -08:00
Tj Holowaychuk 110b0fe14a misc refactor 2011-03-08 11:47:03 -08:00
Tj Holowaychuk d7488bbb62 Removed Partial constructor (not used) 2011-03-08 11:42:03 -08:00
Tj Holowaychuk 2007407e7b docs 2011-03-08 09:56:24 -08:00
Tj Holowaychuk d152e7e780 Added res.render() status support back
useful for error templates that display the status _and_
set the status code
2011-03-08 09:56:05 -08:00
16 arquivos alterados com 286 adições e 139 exclusões
+25
Ver Arquivo
@@ -1,4 +1,29 @@
2.0.0rc / 2011-03-14
==================
* Fixed; expose `HTTPSServer` constructor
* Fixed express(1) default test charset. Closes #579 [reported by secoif]
* Fixed; default charset to utf-8 instead of utf8 for lame IE [reported by NickP]
2.0.0beta3 / 2011-03-09
==================
* Added support for `res.contentType()` literal
The original `res.contentType('.json')`,
`res.contentType('application/json')`, and `res.contentType('json')`
will work now.
* Added `res.render()` status option support back
* Added charset option for `res.render()`
* Added `.charset` support (via connect 1.0.4)
* Added view resolution hints when in development and a lookup fails
* Added layout lookup support relative to the page view.
For example while rendering `./views/user/index.jade` if you create
`./views/user/layout.jade` it will be used in favour of the root layout.
* Fixed `res.redirect()`. RFC states absolute url [reported by unlink]
* Fixed; default `res.send()` string charset to utf8
* Removed `Partial` constructor (not currently used)
2.0.0beta2 / 2011-03-07
==================
+2 -2
Ver Arquivo
@@ -11,7 +11,7 @@ var fs = require('fs')
* Framework version.
*/
var version = '2.0.0beta2';
var version = '2.0.0rc';
/**
* Add session support.
@@ -220,7 +220,7 @@ var app = [
, ''
, 'if (!module.parent) {'
, ' app.listen(3000);'
, ' console.log("Express server listening on port %d", app.address().port)'
, ' console.log("Express server listening on port %d", app.address().port);'
, '}'
, ''
].join('\n');
+27 -1
Ver Arquivo
@@ -47,7 +47,7 @@ otherwise the first call to _app.get()_, _app.post()_, etc will mount the routes
app.configure('production', function(){
var oneYear = 31557600000;
app.use(express.static({ root: __dirname + '/public', maxAge: oneYear }));
app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
app.use(express.errorHandler());
});
@@ -753,6 +753,24 @@ Get or set the response header _key_.
res.header('Content-Length');
// => 123
### res.charset
Sets the charset for subsequent `Content-Type` header fields. For example `res.send()` and `res.render()` default to "utf8", so we may explicitly set the charset before rendering a template:
res.charset = 'ISO-8859-1';
res.render('users');
or before responding with `res.send()`:
res.charset = 'ISO-8859-1';
res.send(str);
or with node's `res.end()`:
res.charset = 'ISO-8859-1';
res.header('Content-Type', 'text/plain');
res.end(str);
### res.contentType(type)
Sets the _Content-Type_ response header to the given _type_.
@@ -761,6 +779,14 @@ Sets the _Content-Type_ response header to the given _type_.
res.contentType(filename);
// Content-Type is now "image/png"
A literal _Content-Type_ works as well:
res.contentType('application/json');
Or simply the extension without leading `.`:
res.contentType('json');
### res.attachment([filename])
Sets the _Content-Disposition_ response header to "attachment", with optional _filename_.
+12 -1
Ver Arquivo
@@ -140,4 +140,15 @@ However now we have the alternative _maxAge_ property which may be used to set _
Express and Connect now utilize the _mime_ module in npm, so to add more use:
require('mime').define({ 'foo/bar': ['foo', 'bar'] });
require('mime').define({ 'foo/bar': ['foo', 'bar'] });
### static() middleware
Previously named `staticProvider()`, the now `static()` middleware takes a single directory path, followed by options.
app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
Previously when using options the `root` option would be used for this:
app.use(express.staticProvider({ root: __dirname + '/public', maxAge: oneYear }));
+3 -2
Ver Arquivo
@@ -27,7 +27,7 @@ var exports = module.exports = connect.middleware;
* Framework version.
*/
exports.version = '2.0.0beta2';
exports.version = '2.0.0rc';
/**
* Shortcut for `new Server(...)`.
@@ -46,10 +46,11 @@ exports.createServer = function(options){
};
/**
* Expose `HTTPServer`.
* Expose constructors.
*/
exports.HTTPServer = HTTPServer;
exports.HTTPSServer = HTTPSServer;
/**
* View extensions.
+5
Ver Arquivo
@@ -83,6 +83,11 @@ Server.prototype.init = function(middleware){
return fn;
});
// default development configuration
this.configure('development', function(){
this.enable('hints');
});
// default production configuration
this.configure('production', function(){
this.enable('cache views');
+19 -8
Ver Arquivo
@@ -63,6 +63,7 @@ res.send = function(body, headers, status){
break;
case 'string':
if (!this.header('Content-Type')) {
this.charset = this.charset || 'utf-8';
this.contentType('.html');
}
break;
@@ -315,34 +316,44 @@ res.cookie = function(name, val, options){
res.redirect = function(url, status){
var app = this.app
, req = this.req
, base = app.set('home') || '/'
, status = status || 302
, body;
// Setup redirect map
var map = {
back: this.req.header('Referrer', base)
back: req.header('Referrer', base)
, home: base
};
// Support custom redirect map
map.__proto__ = this.app.redirects;
map.__proto__ = app.redirects;
// Attempt mapped redirect
var mapped = 'function' == typeof map[url]
? map[url](this.req, this)
? map[url](req, this)
: map[url];
// Perform redirect
url = mapped || url;
// Respect mount-point
if (app.route && !~url.indexOf('://')) {
url = join(app.route, url);
}
// Relative
if (!~url.indexOf('://')) {
// Respect mount-point
if (app.route) {
url = join(app.route, url);
}
// Absolute
var host = req.headers.host
, tls = req.connection.constructor.name == 'CleartextStream';
url = 'http' + (tls ? 's' : '') + '://' + host + url;
}
// Support text/{plain,html} by default
if (this.req.accepts('html')) {
if (req.accepts('html')) {
body = '<p>' + http.STATUS_CODES[status] + '. Redirecting to <a href="' + url + '">' + url + '</a></p>';
this.header('Content-Type', 'text/html');
} else {
+42 -25
Ver Arquivo
@@ -15,7 +15,7 @@ var path = require('path')
, basename = path.basename
, utils = require('connect').utils
, View = require('./view/view')
, Partial = require('./view/partial')
, partial = require('./view/partial')
, union = require('./utils').union
, merge = utils.merge
, http = require('http')
@@ -34,7 +34,6 @@ var cache = {};
*/
exports = module.exports = View;
exports.Partial = Partial;
/**
* Export template engine registrar.
@@ -78,7 +77,7 @@ function renderPartial(res, view, options, locals, parent){
options.layout = false;
// Deduce name from view path
var name = options.as || Partial.resolveObjectName(view);
var name = options.as || partial.resolveObjectName(view);
// Render partial
function render(){
@@ -162,6 +161,7 @@ res.partial = function(view, options){
*
* - `scope` Template evaluation context (the value of `this`)
* - `debug` Output debugging information
* - `status` Response status code
*
* @param {String} view
* @param {Object|Function} options or callback function
@@ -195,6 +195,9 @@ res.render = function(view, opts, fn, parent){
// merge render() .locals
if (opts && opts.locals) merge(options, opts.locals);
// status support
if (options.status) this.statusCode = options.status;
// Defaults
var self = this
, root = app.set('views') || process.cwd() + '/views'
@@ -218,31 +221,28 @@ res.render = function(view, opts, fn, parent){
// "view engine" setting
options.defaultEngine = app.set('view engine');
// charset option
if (options.charset) this.charset = options.charset;
// Populate view
// TODO: move this logic into the protos
var orig = view = partial
? new Partial(view, options)
: new View(view, options);
var orig = view = new View(view, options);
// Ensure view exists, otherwise try _ prefix
if (!view.exists) {
view = partial
? new Partial(view.prefixPath, options)
: new View(view.prefixPath, options);
}
// Try _ prefix ex: ./views/_user.jade
if (!view.exists) view = new View(orig.prefixPath, options);
// Ensure view _ prefix exists, otherwise try index
if (!view.exists) {
view = partial
? new Partial(orig.indexPath, options)
: new View(orig.indexPath, options);
}
// Try index ex: ./views/user/index.jade
if (!view.exists) view = new View(orig.indexPath, options);
// Ensure view exists, or try ../index
if (!view.exists && !options.isLayout) {
view = partial
? new Partial(orig.upIndexPath, options)
: new View(orig.upIndexPath, options);
// Try ../name ../user from within ./user
if (!view.exists && !options.isLayout) view = new View(orig.upIndexPath, options);
// Try layout relative to the "views" dir
if (!view.exists && options.isLayout) view = new View(orig.rootPath, options);
// Does not exist
if (!view.exists) {
if (app.enabled('hints')) hintAtViewPaths(orig, options);
throw new Error('failed to locate view "' + orig.view + '"');
}
// Dynamic helper support
@@ -294,7 +294,6 @@ res.render = function(view, opts, fn, parent){
options.isLayout = true;
options.layout = false;
options.body = str;
options.relative = false;
self.render(layout, options, fn, view);
} else if (partial) {
return str;
@@ -304,3 +303,21 @@ res.render = function(view, opts, fn, parent){
this.send(str);
}
};
/**
* Hint at view path resolution, outputting the
* paths that Express has tried.
*
* @api private
*/
function hintAtViewPaths(view, options) {
console.error();
console.error('failed to locate view "' + view.view + '", tried:');
console.error(' - ' + new View(view.path, options).path);
console.error(' - ' + new View(view.prefixPath, options).path);
console.error(' - ' + new View(view.indexPath, options).path);
if (!options.isLayout) console.error(' - ' + new View(view.upIndexPath, options).path);
if (options.isLayout) console.error(' - ' + new View(view.rootPath, options).path);
console.error();
}
-26
Ver Arquivo
@@ -5,38 +5,12 @@
* MIT Licensed
*/
/**
* Module dependencies.
*/
var View = require('./view')
, basename = require('path').basename;
/**
* Memory cache.
*/
var cache = {};
/**
* Initialize a new `Partial` for the given `view` and `options`.
*
* @param {String} view
* @param {Object} options
* @api private
*/
var Partial = exports = module.exports = function Partial(view, options) {
options = options || {};
View.call(this, view, options);
};
/**
* Inherit from `View.prototype`.
*/
Partial.prototype.__proto__ = View.prototype;
/**
* Resolve partial object name from the view path.
*
+12
Ver Arquivo
@@ -134,6 +134,18 @@ View.prototype.__defineGetter__('templateEngine', function(){
return cache[ext] || (cache[ext] = require(this.engine));
});
/**
* Return root path alternative.
*
* @return {String}
* @api public
*/
View.prototype.__defineGetter__('rootPath', function(){
this.relative = false;
return this.resolvePath();
});
/**
* Return index path alternative.
*
+1 -1
Ver Arquivo
@@ -1,7 +1,7 @@
{
"name": "express",
"description": "Sinatra inspired web development framework",
"version": "2.0.0beta2",
"version": "2.0.0rc",
"author": "TJ Holowaychuk <tj@vision-media.ca>",
"contributors": [
{ "name": "TJ Holowaychuk", "email": "tj@vision-media.ca" },
+6 -1
Ver Arquivo
@@ -13,6 +13,11 @@ module.exports = {
var server = express.createServer();
server.should.be.an.instanceof(connect.HTTPServer);
},
'test constructor exports': function(){
express.should.have.property('HTTPServer');
express.should.have.property('HTTPSServer');
},
'test connect middleware autoloaders': function(){
express.errorHandler.should.equal(connect.errorHandler);
@@ -232,8 +237,8 @@ module.exports = {
'test #configure()': function(beforeExit){
var calls = [];
process.env.NODE_ENV = 'development';
var server = express.createServer();
server.set('env', 'development');
// Config blocks
var ret = server.configure(function(){
+66 -45
Ver Arquivo
@@ -11,7 +11,7 @@ var express = require('express')
module.exports = {
'test #send()': function(){
var app = express.createServer();
app.get('/html', function(req, res){
res.send('<p>test</p>', { 'Content-Language': 'en' });
});
@@ -30,7 +30,7 @@ module.exports = {
app.get('/text', function(req, res){
res.header('X-Foo', 'bar');
res.contentType('.txt');
res.contentType('txt');
res.send('wahoo');
});
@@ -49,15 +49,15 @@ module.exports = {
app.get('/noargs', function(req, res, next){
res.send();
});
assert.response(app,
{ url: '/html' },
{ body: '<p>test</p>'
, headers: {
'Content-Language': 'en'
, 'Content-Type': 'text/html'
, 'Content-Type': 'text/html; charset=utf-8'
}});
assert.response(app,
{ url: '/json' },
{ body: '{"foo":"bar"}'
@@ -66,7 +66,7 @@ module.exports = {
'Content-Type': 'application/json'
, 'X-Foo': 'baz'
}});
assert.response(app,
{ url: '/jsonp?callback=test' },
{ body: 'test({"foo":"bar"});'
@@ -75,7 +75,7 @@ module.exports = {
'Content-Type': 'text/javascript'
, 'X-Foo': 'baz'
}});
assert.response(app,
{ url: '/jsonp?callback=baz' },
{ body: 'baz({"foo":"bar"});'
@@ -83,7 +83,7 @@ module.exports = {
'Content-Type': 'text/javascript'
, 'X-Foo': 'baz'
}});
assert.response(app,
{ url: '/jsonp?callback=invalid()[]' },
{ body: 'invalid({"foo":"bar"});'
@@ -92,7 +92,7 @@ module.exports = {
'Content-Type': 'text/javascript'
, 'X-Foo': 'baz'
}});
assert.response(app,
{ url: '/json?callback=test' },
{ body: '{"foo":"bar"}'
@@ -101,7 +101,7 @@ module.exports = {
'Content-Type': 'application/json'
, 'X-Foo': 'baz'
}});
assert.response(app,
{ url: '/text' },
{ body: 'wahoo'
@@ -109,22 +109,22 @@ module.exports = {
'Content-Type': 'text/plain'
, 'X-Foo': 'bar'
}});
assert.response(app,
{ url: '/status' },
{ body: 'Not Found'
, status: 404
, headers: { 'Content-Type': 'text/plain' }});
assert.response(app,
{ url: '/error' },
{ body: 'Oh shit!'
, status: 500
, headers: {
'Content-Type': 'text/plain'
'Content-Type': 'text/plain; charset=utf-8'
, 'Content-Length': '8'
}});
assert.response(app,
{ url: '/buffer' },
{ body: 'wahoo!'
@@ -132,7 +132,7 @@ module.exports = {
'Content-Type': 'application/octet-stream'
, 'Content-Length': '6'
}});
assert.response(app,
{ url: '/noargs' },
{ status: 204 }, function(res){
@@ -154,7 +154,15 @@ module.exports = {
res.contentType('json');
res.send('{"foo":"bar"}');
});
app.get('/literal', function(req, res){
res.contentType('application/json');
res.send('{"foo":"bar"}')
});
assert.response(app,
{ url: '/literal' },
{ headers: { 'Content-Type': 'application/json' }});
assert.response(app,
{ url: '/html' },
{ body: '<p>yay</p>', headers: { 'Content-Type': 'text/html' }});
@@ -239,58 +247,58 @@ module.exports = {
});
assert.response(app,
{ url: '/html', headers: { Accept: 'text/html,text/plain' }},
{ url: '/html', headers: { Accept: 'text/html,text/plain', Host: 'foo.com' }},
{ body: '<p>Moved Temporarily. Redirecting to <a href="http://google.com">http://google.com</a></p>' });
assert.response(app,
{ url: '/', headers: { Accept: 'text/plain' }},
{ url: '/', headers: { Accept: 'text/plain', Host: 'foo.com' }},
{ body: 'Moved Permanently. Redirecting to http://google.com'
, status: 301, headers: { Location: 'http://google.com' }});
assert.response(app,
{ url: '/back', headers: { Accept: 'text/plain' }},
{ body: 'Moved Temporarily. Redirecting to /'
, status: 302, headers: { Location: '/', 'Content-Type': 'text/plain' }});
{ url: '/back', headers: { Accept: 'text/plain', Host: 'foo.com' }},
{ body: 'Moved Temporarily. Redirecting to http://foo.com/'
, status: 302, headers: { Location: 'http://foo.com/', 'Content-Type': 'text/plain' }});
assert.response(app,
{ url: '/back', headers: { Referer: '/foo', Accept: 'text/plain' }},
{ body: 'Moved Temporarily. Redirecting to /foo'
, status: 302, headers: { Location: '/foo' }});
{ url: '/back', headers: { Referer: '/foo', Accept: 'text/plain', Host: 'foo.com' }},
{ body: 'Moved Temporarily. Redirecting to http://foo.com/foo'
, status: 302, headers: { Location: 'http://foo.com/foo' }});
assert.response(app,
{ url: '/back', headers: { Referrer: '/foo', Accept: 'text/plain' }},
{ body: 'Moved Temporarily. Redirecting to /foo'
, status: 302, headers: { Location: '/foo' }});
{ url: '/back', headers: { Referrer: '/foo', Accept: 'text/plain', Host: 'foo.com' }},
{ body: 'Moved Temporarily. Redirecting to http://foo.com/foo'
, status: 302, headers: { Location: 'http://foo.com/foo' }});
assert.response(app,
{ url: '/home', headers: { Accept: 'text/plain' } },
{ body: 'Moved Temporarily. Redirecting to /'
, status: 302, headers: { Location: '/' }});
{ url: '/home', headers: { Accept: 'text/plain', Host: 'foo.com' } },
{ body: 'Moved Temporarily. Redirecting to http://foo.com/'
, status: 302, headers: { Location: 'http://foo.com/' }});
assert.response(app2,
{ url: '/', headers: { Accept: 'text/plain' }},
{ url: '/', headers: { Accept: 'text/plain', Host: 'foo.com' }},
{ body: 'Moved Permanently. Redirecting to http://google.com'
, status: 301, headers: { Location: 'http://google.com' }});
assert.response(app2,
{ url: '/back', headers: { Accept: 'text/plain' }},
{ body: 'Moved Temporarily. Redirecting to /blog'
, status: 302, headers: { Location: '/blog' }});
{ url: '/back', headers: { Accept: 'text/plain', Host: 'foo.com' }},
{ body: 'Moved Temporarily. Redirecting to http://foo.com/blog'
, status: 302, headers: { Location: 'http://foo.com/blog' }});
assert.response(app2,
{ url: '/home', headers: { Accept: 'text/plain' }},
{ body: 'Moved Temporarily. Redirecting to /blog'
, status: 302, headers: { Location: '/blog' }});
{ url: '/home', headers: { Accept: 'text/plain', Host: 'foo.com' }},
{ body: 'Moved Temporarily. Redirecting to http://foo.com/blog'
, status: 302, headers: { Location: 'http://foo.com/blog' }});
assert.response(app2,
{ url: '/google', headers: { Accept: 'text/plain' }},
{ url: '/google', headers: { Accept: 'text/plain', Host: 'foo.com' }},
{ body: 'Moved Temporarily. Redirecting to http://google.com'
, status: 302, headers: { Location: 'http://google.com' }});
assert.response(app2,
{ url: '/user/12', headers: { Accept: 'text/plain' }},
{ body: 'Moved Temporarily. Redirecting to /user/12/blog'
, status: 302, headers: { Location: '/user/12/blog', 'X-Foo': 'bar' }});
{ url: '/user/12', headers: { Accept: 'text/plain', Host: 'foo.com' }},
{ body: 'Moved Temporarily. Redirecting to http://foo.com/user/12/blog'
, status: 302, headers: { Location: 'http://foo.com/user/12/blog', 'X-Foo': 'bar' }});
},
'test #redirect() when mounted': function(){
@@ -309,9 +317,9 @@ module.exports = {
app.use('/blog', blog);
assert.response(app,
{ url: '/blog/posts' },
{ url: '/blog/posts', headers: { Host: 'foo.com' }},
{ status: 302
, headers: { Location: '/blog/posts/all' }});
, headers: { Location: 'http://foo.com/blog/posts/all' }});
},
'test #sendfile()': function(){
@@ -403,7 +411,7 @@ module.exports = {
{ url: '/large.json' },
{ headers: {
'Accept-Ranges': 'bytes'
, 'Cache-Control': 'public max-age=3600'
, 'Cache-Control': 'public, max-age=3600'
}});
beforeExit(function(){
@@ -529,7 +537,7 @@ module.exports = {
});
assert.response(app,
{ url: '/' },
{ url: '/', headers: { Host: 'foo.com' }},
function(res){
res.headers['set-cookie']
.should.eql(['rememberme=yes; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly', 'something=else']);
@@ -562,5 +570,18 @@ module.exports = {
assert.response(app,
{ url: '/', method: 'HEAD' },
{ body: '', headers: { 'Content-Length': 11 }});
},
'test .charset with res.send()': function(){
var app = express.createServer();
app.get('/', function(req, res){
res.charset = 'ISO-8859-1';
res.send('<p>hey</p>');
});
assert.response(app,
{ url: '/' },
{ headers: { 'Content-Type': 'text/html; charset=ISO-8859-1' }});
}
};
+64 -25
Ver Arquivo
@@ -8,7 +8,7 @@ var express = require('express')
, assert = require('assert')
, should = require('should')
, View = require('../lib/view')
, Partial = View.Partial
, partial = require('../lib/view/partial')
/**
* Create a test server with views set to ./fixtures.
@@ -93,8 +93,8 @@ module.exports = {
view.templateEngine.should.equal(require('jade'));
},
'test Partial.resolveObjectName()': function(){
var resolve = Partial.resolveObjectName;
'test partial.resolveObjectName()': function(){
var resolve = partial.resolveObjectName;
resolve('/path/to/user.ejs').should.equal('user');
resolve('/path/to/user-post.ejs').should.equal('userPost');
resolve('/path/to/user post.ejs').should.equal('userPost');
@@ -102,25 +102,6 @@ module.exports = {
resolve('forum thread post.ejs').should.equal('forumThreadPost');
},
'test Partial#path for partials': function(){
var fixtures = __dirname + '/fixtures';
var view = new Partial('user.jade', { root: fixtures });
view.path.should.equal(fixtures + '/user.jade');
var view = new Partial('user', { parentView: view, root: fixtures });
view.path.should.equal(fixtures + '/user.jade');
var view = new Partial('forum/thread', { parentView: view });
view.path.should.equal(fixtures + '/forum/thread.jade');
var view = new Partial('forum/thread.jade', { root: fixtures });
view.path.should.equal(fixtures + '/forum/thread.jade');
var view = new Partial('thread', { parentView: view });
view.path.should.equal(fixtures + '/forum/thread.jade');
},
'test #render()': function(){
var app = create();
app.set('view engine', 'jade');
@@ -182,12 +163,19 @@ module.exports = {
res.render('ferret', { layout: false, ferret: { name: 'Tobi' }});
});
app.get('/status', function(req, res){
res.render('hello.jade', { status: 500 });
});
assert.response(app,
{ url: '/status' },
{ status: 500 });
assert.response(app,
{ url: '/ferret' },
{ body: '<li class="ferret">Tobi</li>' });
assert.response(app,
{ url: '/' },
{ body: '<p>Welcome</p>', headers: { 'Content-Type': 'text/html' }});
{ body: '<p>Welcome</p>', headers: { 'Content-Type': 'text/html; charset=utf-8' }});
assert.response(app,
{ url: '/jade' },
{ body: '<p>Welcome</p>' });
@@ -277,8 +265,8 @@ module.exports = {
assert.response(app,
{ url: '/nope' },
function(res){
assert.ok(~res.body.indexOf('Error: E'));
assert.ok(~res.body.indexOf('nope/index.jade'));
assert.ok(~res.body.indexOf('Error: failed to locate view'));
assert.ok(~res.body.indexOf('nope'));
});
beforeExit(function(){
@@ -895,5 +883,56 @@ module.exports = {
assert.response(app,
{ url: '/pets' },
{ body: html });
},
'test .charset with res.render()': function(){
var app = create();
app.get('/', function(req, res){
res.charset = 'ISO-8859-1';
res.render('hello.jade');
});
assert.response(app,
{ url: '/' },
{ headers: { 'Content-Type': 'text/html; charset=ISO-8859-1' }});
},
'test charset res.render() option': function(){
var app = create();
app.get('/', function(req, res){
res.render('hello.jade', { charset: 'ISO-8859-1' });
});
assert.response(app,
{ url: '/' },
{ headers: { 'Content-Type': 'text/html; charset=ISO-8859-1' }});
},
'test charset option': function(){
var app = create();
app.set('view options', { charset: 'ISO-8859-1' });
app.get('/', function(req, res){
res.render('hello.jade');
});
assert.response(app,
{ url: '/' },
{ headers: { 'Content-Type': 'text/html; charset=ISO-8859-1' }});
},
'test charset override': function(){
var app = create();
app.set('view options', { charset: 'ISO-8859-1' });
app.get('/', function(req, res){
res.render('hello.jade', { charset: 'utf8' });
});
assert.response(app,
{ url: '/' },
{ headers: { 'Content-Type': 'text/html; charset=utf8' }});
}
};