Skip to content
Myr

Added "charset" option

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 f0c90ce · Browse files · 3 files+31 added−87 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+31 added−87 removed

  • tests:+25 added−83 removed
  • other:+6 added−4 removed

3 files+31 added−87 removed

modified:lib/http.js+6 added
69 unmodified lines
70 this.set('env', process.env.NODE_ENV || 'development');7172 // expose objects to each other73 this.use(function(req, res, next){74 var charset;75 req.query = req.query || {};76 res.setHeader('X-Powered-By', 'Express');77 req.app = res.app = self;78 req.res = res;79 res.req = req;80 req.next = next;8182 // charset83 if (charset = self.set('charset')) res.charset = charset;8485 // assign req.query86 if (req.url.indexOf('?') > 0) {87 var query = url.parse(req.url).query;88 req.query = qs.parse(query);89 }9091 next();92 });9394 // apply middleware
448 unmodified lines
modified:lib/view.js-4 removed
334 unmodified lines
335 , self = this336 , app = this.app337 , locals = app._locals338 , dynamic = app._dynamicLocals339 , viewOptions = app.set('view options')339 , root = app.set('views') || process.cwd() + '/views';340341 // cache id342 var cid = app.enabled('view cache')343 ? view + (parent ? ':' + parent.path : '')344 : false;345347 // merge "view options"348 if (viewOptions) merge(options, viewOptions);349346 // merge res._locals347 if (this._locals) merge(options, this._locals);348349 // merge render() options
106 unmodified lines
modified:test/view.test.js+25 added-83 removed
936 unmodified lines
937 { url: '/' },938 { body: '<ul><li>foo</li><li>bar</li></ul>' });939 },940 941 'test "view options"': function(){942 var app = create();943 944 app.set('view options', {945 layout: false946 , open: '{{'947 , close: '}}'948 });949 950 app.get('/', function(req, res, next){951 res.render('user.ejs', {952 name: 'tj'953 , email: 'tj@vision-media.ca'954 });955 });956 957 app.get('/video', function(req, res, next){958 res.render('video.ejs', {959 open: '<?'960 , close: '?>'961 , title: 'keyboard cat'962 });963 });964 965 assert.response(app,966 { url: '/' },967 { body: '<h1>tj</h1>\n<p>tj@vision-media.ca</p>' });968 assert.response(app,969 { url: '/video' },970 { body: '<h1>keyboard cat</h1>' });971 },972 941 'test .register()': function(){942 var app = create();943 944 app.register('.bar', require('jade'));
53 unmodified lines
998 { url: '/video' },999 { body: '<h1>keyboard cat</h1>' });1000 },1001 1034 'test res.local() "view options" precedence': function(){1035 var app = create();1036 1037 app.set('view options', {1038 layout: false1039 , open: '<?'1040 , title: 'Original'1041 });1042 1043 function setTitle(req, res, next) {1044 res.local('title', 'Wahoo');1045 next();1046 }1047 1048 app.get('/video', setTitle, function(req, res, next){1049 res.local('close', '?>');1050 res.render('video.ejs', { layout: false, title: 'keyboard cat' });1051 });1052 1053 app.get('/video/2', setTitle, function(req, res, next){1054 res.local('close', '?>');1055 res.render('video.ejs', { layout: false });1056 });1057 1058 app.get('/video/3', function(req, res, next){1059 res.local('close', '?>');1060 res.render('video.ejs', { layout: false });1061 });1062 1063 assert.response(app,1064 { url: '/video' },1065 { body: '<h1>keyboard cat</h1>' });1066 1067 assert.response(app,1068 { url: '/video/2' },1069 { body: '<h1>Wahoo</h1>' });1070 1071 assert.response(app,1072 { url: '/video/3' },1073 { body: '<h1>Original</h1>' });1074 },1075 1002 'test res.local() partials': function(){1003 var app = create();10041005 app.local('site', 'My Cool Pets');1006 1079 app.set('view options', {1080 site: 'My Cool Pets'1081 });1082 1007 app.get('/pets', function(req, res, next){1008 res.local('pets', ['Tobi']);1009 next();1010 });
53 unmodified lines
1064 { url: '/' },1065 { headers: { 'Content-Type': 'text/html; charset=ISO-8859-1' }});1066 },1067 1144 'test charset option': function(){1068 'test "charset" option': function(){1069 var app = create();10701146 app.set('view options', { charset: 'ISO-8859-1' });1147 1148 app.get('/', function(req, res){1071 app.set('charset', 'ISO-8859-1');10721073 app.get('/option', function(req, res, next){1074 res.render('hello.jade');1075 });10761077 app.get('/local', function(req, res){1078 res.local('charset', 'ISO-8859-1');1079 res.render('hello.jade');1080 });10811082 app.get('/render', function(req, res){1083 res.render('hello.jade', { charset: 'ISO-8859-1' });1084 });10851086 assert.response(app,1087 { url: '/option' },1088 { headers: { 'Content-Type': 'text/html; charset=ISO-8859-1' }});10891090 assert.response(app,1091 { url: '/render' },1092 { headers: { 'Content-Type': 'text/html; charset=ISO-8859-1' }});1093 1094 assert.response(app,1153 { url: '/' },1095 { url: '/local' },1096 { headers: { 'Content-Type': 'text/html; charset=ISO-8859-1' }});1097 },1098 1099 'test charset override': function(){
12 unmodified lines