sinatra 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sinatra might be problematic. Click here for more details.

data/ChangeLog CHANGED
@@ -1,6 +1,34 @@
1
+ = 0.3.3 / 2009-01-06
2
+
3
+ * Pin to Rack 0.4.0 (this is the last release on Rack 0.4)
4
+
5
+ * Log unhandled exception backtraces to rack.errors.
6
+
7
+ * Use RACK_ENV environment variable to establish Sinatra
8
+ environment when given. Thin sets this when started with
9
+ the -e argument.
10
+
11
+ * BUG: raising Sinatra::NotFound resulted in a 500 response
12
+ code instead of 404.
13
+
14
+ * BUG: use_in_file_templates! failes with CR/LF (#45)
15
+
16
+ * BUG: Sinatra detects the app file and root path when run under
17
+ thin/passenger.
18
+
19
+ = 0.3.2
20
+
21
+ * BUG: Static and send_file read entire file into String before
22
+ sending. Updated to stream with 8K chunks instead.
23
+
24
+ * Rake tasks and assets for building basic documentation website.
25
+ See http://sinatra.rubyforge.org
26
+
27
+ * Various minor doc fixes.
28
+
1
29
  = 0.3.1
2
30
 
3
- * Unbreak optional path parameters [jeremyevans]
31
+ * Unbreak optional path parameters [jeremyevans]
4
32
 
5
33
  = 0.3.0
6
34
 
data/README.rdoc CHANGED
@@ -140,14 +140,14 @@ blocks can be accessed direcly in views:
140
140
 
141
141
  get '/:id' do
142
142
  @foo = Foo.find(params[:id])
143
- haml '%h1== @foo.name'
143
+ haml '%h1= @foo.name'
144
144
  end
145
145
 
146
146
  Or, specify an explicit Hash of local variables:
147
147
 
148
148
  get '/:id' do
149
149
  foo = Foo.find(params[:id])
150
- haml '%h1== foo.name', :locals => { :foo => foo }
150
+ haml '%h1= foo.name', :locals => { :foo => foo }
151
151
  end
152
152
 
153
153
  This is typically used when rendering templates as partials from within
data/lib/sinatra.rb CHANGED
@@ -11,6 +11,10 @@ elsif ENV['EVENT']
11
11
  puts "Using Evented Mongrel"
12
12
  end
13
13
 
14
+ unless defined?(Rack::File::MIME_TYPES)
15
+ class Rack::File; MIME_TYPES = Rack::Mime::MIME_TYPES; end
16
+ end
17
+
14
18
  module Rack #:nodoc:
15
19
 
16
20
  class Request #:nodoc:
@@ -55,7 +59,7 @@ end
55
59
  module Sinatra
56
60
  extend self
57
61
 
58
- VERSION = '0.3.2'
62
+ VERSION = '0.3.3'
59
63
 
60
64
  class NotFound < RuntimeError
61
65
  def self.code ; 404 ; end
@@ -923,18 +927,19 @@ module Sinatra
923
927
  # file, before any DSL related functions are invoked.
924
928
  def self.default_options
925
929
  return @default_options unless @default_options.nil?
926
- root = File.expand_path(File.dirname($0))
930
+ app_file = locate_app_file
931
+ root = File.expand_path(File.dirname(app_file))
927
932
  @default_options = {
928
933
  :run => true,
929
934
  :port => 4567,
930
935
  :host => '0.0.0.0',
931
- :env => :development,
936
+ :env => (ENV['RACK_ENV'] || :development).to_sym,
932
937
  :root => root,
933
938
  :views => root + '/views',
934
939
  :public => root + '/public',
935
940
  :sessions => false,
936
941
  :logging => true,
937
- :app_file => $0,
942
+ :app_file => app_file,
938
943
  :raise_errors => false
939
944
  }
940
945
  load_default_options_from_command_line!
@@ -957,6 +962,16 @@ module Sinatra
957
962
  end.parse!(ARGV.dup.select { |o| o !~ /--name/ })
958
963
  end
959
964
 
965
+ # Use heuristics to locate the application file.
966
+ def self.locate_app_file
967
+ caller[1..-1].reverse.each do |path|
968
+ path = path.split(':', 2)[0]
969
+ next if path =~ /sinatra\.rb$/ || path == '(__DSL__)'
970
+ return path
971
+ end
972
+ $0
973
+ end
974
+
960
975
  # Determine whether the application is in the process of being
961
976
  # reloaded.
962
977
  def reloading?
@@ -1255,8 +1270,13 @@ module Sinatra
1255
1270
  end
1256
1271
  body = returned.to_result(context)
1257
1272
  rescue => e
1273
+ msg = "#{e.class.name} - #{e.message}:"
1274
+ msg << "\n #{e.backtrace.join("\n ")}"
1275
+ request.env['rack.errors'] << msg
1276
+
1258
1277
  request.env['sinatra.error'] = e
1259
- context.status(500)
1278
+ status = e.class.code rescue 500
1279
+ context.status(status)
1260
1280
  raise if options.raise_errors && e.class != NotFound
1261
1281
  result = (errors[e.class] || errors[ServerError]).invoke(request)
1262
1282
  returned =
@@ -1365,11 +1385,11 @@ def helpers(&b)
1365
1385
  end
1366
1386
 
1367
1387
  def use_in_file_templates!
1368
- require 'stringio'
1369
- templates = IO.read(caller.first.split(':').first).split('__FILE__').last
1370
- data = StringIO.new(templates)
1388
+ file = caller.first.sub(/:\d+$/, '')
1389
+ data = IO.read(file).split('__END__').last
1390
+ data.gsub! /\r\n/, "\n"
1371
1391
  current_template = nil
1372
- data.each do |line|
1392
+ data.each_line do |line|
1373
1393
  if line =~ /^@@\s?(.*)/
1374
1394
  current_template = $1.to_sym
1375
1395
  Sinatra.application.templates[current_template] = ''
data/sinatra.gemspec CHANGED
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
3
3
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
4
 
5
5
  s.name = 'sinatra'
6
- s.version = '0.3.2'
6
+ s.version = '0.3.3'
7
7
  s.date = "2008-11-02"
8
8
 
9
9
  s.description = "Classy web-development dressed in a DSL"
@@ -66,7 +66,7 @@ Gem::Specification.new do |s|
66
66
  s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/}
67
67
 
68
68
  s.extra_rdoc_files = %w[README.rdoc LICENSE]
69
- s.add_dependency 'rack', '>= 0.4.0'
69
+ s.add_dependency 'rack', '~> 0.4.0'
70
70
 
71
71
  s.has_rdoc = true
72
72
  s.homepage = "http://sinatra.rubyforge.org"
@@ -96,6 +96,17 @@ context "An app returns" do
96
96
 
97
97
  end
98
98
 
99
+ specify "404 if NotFound is raised" do
100
+
101
+ get '/' do
102
+ raise Sinatra::NotFound
103
+ end
104
+
105
+ get_it '/'
106
+ should.be.not_found
107
+
108
+ end
109
+
99
110
  end
100
111
 
101
112
  context "Application#configure blocks" do
data/test/helper.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'rubygems'
2
2
  require 'mocha'
3
3
 
4
+ gem 'rack', '~> 0.4.0'
5
+
4
6
  $:.unshift File.dirname(File.dirname(__FILE__)) + "/lib"
5
7
 
6
8
  require 'sinatra'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Mizerany
@@ -18,7 +18,7 @@ dependencies:
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - ">="
21
+ - - ~>
22
22
  - !ruby/object:Gem::Version
23
23
  version: 0.4.0
24
24
  version:
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  requirements: []
107
107
 
108
108
  rubyforge_project: sinatra
109
- rubygems_version: 1.2.0
109
+ rubygems_version: 1.3.1
110
110
  signing_key:
111
111
  specification_version: 2
112
112
  summary: Classy web-development dressed in a DSL