Skip to content
Myr

Added Express.Break

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by visionmedia · committed by visionmedia · parent b1b5daf · Browse files · 4 files+29 added−15 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+29 added−15 removed

  • tests:+8 added−6 removed
  • other:+21 added−9 removed

4 files+29 added−15 removed

modified:lib/express.core.js+21 added-9 removed
2 unmodified lines
3 Express = { 4 version : '0.0.1',5 routes : [],6 7 // --- Break8 9 Break : function(){10 this.toString = function() {11 return 'Express.Break'12 }13 },14 15 // --- Response16 17 response : {18 headers : {},
7 unmodified lines
26 maxAge : 360027 },28 route : {29 callback : function() {22 Express.respond('Not Found')30 Express.respond('Page or file cannot be found', 'Not Found')31 }32 }33 },34
70 unmodified lines
105 })106 },107 108 fail : function(e) {109 if (e.constructor == Express.Break) return110 this.header('Content-Type', 'text/html')102 this.response.body = this.respond(e.name + ': ' + e.message, 500)111 this.response.body = e.message ? e.name + ': ' + e.message : e.toString()112 this.response.status = 500113 },114 115 server : {116
56 unmodified lines
173 /**174 * Redirect to _url_.175 *176 * @param {string} url167 * @return {string}177 * @api public178 */179 180 redirect : function(url) {181 // TODO: respond / redirect should halt182 this.header('Location', url)174 return this.respond('Moved Temporarily')183 this.respond('Moved Temporarily')184 },185 186 /**187 * Set response status to _value_. Where value may be
5 unmodified lines
193 * @api public194 */195 196 status : function(value) {197 if (value == undefined) throw 'Express.status(): value must be passed'198 if (typeof value == 'number') return this.response.status = value199 for (var code in node.http.STATUS_CODES)200 if (node.http.STATUS_CODES.hasOwnProperty(code))201 if (node.http.STATUS_CODES[code].toLowerCase() == value.toLowerCase())
4 unmodified lines
206 * Set response _status_ and _body_.207 *208 * @param {string} body209 * @param {string, int} status200 * @return {string}210 * @api public211 */212 213 respond : function(body, status) {205 this.status(status || body)206 return body214 this.response.body = body215 this.status(status)216 throw new Express.Break()217 },218 219 /**220 * Sets _name_ header to _value_. When _value_
359 unmodified lines
580 'list of articles'581})582583get(/articles\/(\d+)/, function(){584 redirect('http://google.com') // TODO: remove / fix585 header('Content-Type', 'text/html')586 'article id ' + captures[1]576 redirect('http://google.com') // TODO: remove / fix587})588589get('articles/:name', function(){580 if (param('name') == 'tj')590 if (param('name') == 'tj') {591 respond('Halted execution')592 'hello tj'593 }594 else595 'article name ' + param('name')596})597
1 unmodified line
modified:spec/spec.core.js+5 added-3 removed
modified:spec/spec.dom.html+2 added-2 removed
1<html>2 <head>3 <link type="text/css" rel="stylesheet" href="/Library/Ruby/Gems/1.8/gems/visionmedia-jspec-2.4.2/lib/jspec.css" />4 <script src="/Library/Ruby/Gems/1.8/gems/visionmedia-jspec-2.4.2/lib/jspec.js"></script>3 <link type="text/css" rel="stylesheet" href="/Library/Ruby/Gems/1.8/gems/visionmedia-jspec-2.5.0/lib/jspec.css" />4 <script src="/Library/Ruby/Gems/1.8/gems/visionmedia-jspec-2.5.0/lib/jspec.js"></script>5 <script src="../lib/express.core.js"></script>6 <script src="../lib/express.mime.js"></script>7 <script src="../lib/express.view.js"></script>8 <script>
17 unmodified lines
modified:spec/spec.rhino.js+1 added-1 removed
12load('/Library/Ruby/Gems/1.8/gems/visionmedia-jspec-2.4.2/lib/jspec.js')2load('/Library/Ruby/Gems/1.8/gems/visionmedia-jspec-2.5.0/lib/jspec.js')3load('lib/express.core.js')4load('lib/express.mime.js')5load('lib/express.view.js')6
7 unmodified lines