public
Fork of bmizerany/sinatra
Description: Classy web-development dressed in a DSL
Homepage: http://sinatrarb.com
Clone URL: git://github.com/JackDanger/sinatra.git
Search Repo:
* Default error messages
* Use SINATRA_ENV var if set
Blake Mizerany (author)
Thu Nov 29 18:35:06 -0800 2007
commit  9ee50b308247b18326111b81272944c5c7ce2090
tree    2d0ec39c88f0b7f899b67f3a873a4a3b5c1297d6
parent  bd8515bbf89bcb7502ef5e7099bc6f714ecbf30f
...
4
5
6
 
7
8
...
4
5
6
7
8
9
0
@@ -4,6 +4,7 @@
0
 task :default => :test
0
 
0
 Rake::TestTask.new do |t|
0
+ ENV['SINATRA_ENV'] = 'test'
0
   t.pattern = "test/*_test.rb"
0
 end
...
64
65
66
67
 
68
69
70
...
328
329
330
 
 
 
 
 
331
332
333
...
444
445
446
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
447
...
64
65
66
 
67
68
69
70
...
328
329
330
331
332
333
334
335
336
337
338
...
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
0
@@ -64,7 +64,7 @@
0
       
0
   class Event
0
 
0
- URI_CHAR = '[^/?:,&#]'.freeze unless defined?(URI_CHAR)
0
+ URI_CHAR = '[^/?:,&#\.]'.freeze unless defined?(URI_CHAR)
0
     PARAM = /:(#{URI_CHAR}+)/.freeze unless defined?(PARAM)
0
     
0
     attr_reader :path, :block, :param_keys, :pattern
0
@@ -328,6 +328,11 @@
0
   Sinatra.application.define_layout(name, &b)
0
 end
0
 
0
+def configures(*envs, &b)
0
+ yield if envs.include?(Sinatra.application.options.env) ||
0
+ envs.empty?
0
+end
0
+
0
 ### Misc Core Extensions
0
 
0
 module Kernel
0
@@ -444,5 +449,76 @@
0
 at_exit do
0
   raise $! if $!
0
   Sinatra.run if Sinatra.application.options.run
0
+end
0
+
0
+ENV['SINATRA_ENV'] = 'test' if $0 =~ /_test\.rb$/
0
+Sinatra::Application.default_options.merge!(
0
+ :env => (ENV['SINATRA_ENV'] || 'development').to_sym
0
+)
0
+
0
+configures :development do
0
+
0
+ get '/sinatra_custom_images/:image.png' do
0
+ File.read(File.dirname(__FILE__) + "/../images/#{params[:image]}.png")
0
+ end
0
+
0
+ error 404 do
0
+ %Q(
0
+ <html>
0
+ <body style='text-align: center; color: #888; font-family: Arial; font-size: 22px; margin: 20px'>
0
+ <h2>Sinatra doesn't know this diddy.</h2>
0
+ <img src='/sinatra_custom_images/404.png'></img>
0
+ </body>
0
+ </html>
0
+ )
0
+ end
0
+
0
+ error 500 do
0
+ @error = request.env['sinatra.error']
0
+ %Q(
0
+ <html>
0
+ <body>
0
+ <style type="text/css" media="screen">
0
+ body {
0
+ font-family: Verdana;
0
+ color: #333;
0
+ }
0
+
0
+ #content {
0
+ width: 700px;
0
+ margin-left: 20px;
0
+ }
0
+
0
+ #content h1 {
0
+ width: 99%;
0
+ color: #1D6B8D;
0
+ font-weight: bold;
0
+ }
0
+
0
+ #stacktrace {
0
+ margin-top: -20px;
0
+ }
0
+
0
+ #stacktrace pre {
0
+ font-size: 12px;
0
+ border-left: 2px solid #ddd;
0
+ padding-left: 10px;
0
+ }
0
+
0
+ #stacktrace img {
0
+ margin-top: 10px;
0
+ }
0
+ </style>
0
+ <div id="content">
0
+ <img src="/sinatra_custom_images/500.png" />
0
+ <div id="stacktrace">
0
+ <h1>#{@error.message}</h1>
0
+ <pre><code>#{@error.backtrace.join("\n")}</code></pre>
0
+ </div>
0
+ </body>
0
+ </html>
0
+ )
0
+ end
0
+
0
 end

Comments

    No one has commented yet.