cehoffman-sinatra-respond_to 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -5,7 +5,6 @@
5
5
 
6
6
  require 'sinatra'
7
7
  require 'sinatra/respond_to'
8
- register Sinatra::RespondTo # => Due to bug in sinatra for classic applications and extensions, see Issues
9
8
 
10
9
  get '/posts' do
11
10
  @posts = Post.recent
@@ -80,8 +79,8 @@ If you want to ensure the route only gets called for css requests try this
80
79
  ## Issues
81
80
 
82
81
  Sinatra has a bug that affects Classic style applications and extensions see [#215][215] and [#180][180].
83
- For this reason you'll have explicitly register Sinatra::RespondTo for classic applications just like for
84
- non-classic applications.
82
+ I have worked around this by explicitly registering RespondTo with the top level Sinatra::Application when
83
+ requiring sinatra/respond\_to.
85
84
 
86
85
  [215]: https://sinatra.lighthouseapp.com/projects/9779/tickets/215-extensions-cannot-define-before-filters-for-classic-apps "Extensions cannot define before filters for classic apps"
87
86
  [180]: https://sinatra.lighthouseapp.com/projects/9779/tickets/180-better-route-inheritence "Better route inheritence"
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ begin
7
7
  spec.homepage = 'http://github.com/cehoffman/sinatra-respond_to'
8
8
  spec.description = spec.summary
9
9
  spec.authors = ["Chris Hoffman"]
10
- spec.add_dependency('sinatra', '>=0.9.1.3')
10
+ spec.add_dependency('sinatra-sinatra', '>= 0.9.1.3')
11
11
  end
12
12
  rescue LoadError
13
13
  puts "Jewler not available. Install it with sugo gem install technicalpickles-jeweler -s http://gems.github.com"
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 1
2
+ :patch: 3
3
3
  :major: 0
4
4
  :minor: 3
@@ -41,7 +41,7 @@ module Sinatra
41
41
  unless options.static? && options.public? && ["GET", "HEAD"].include?(request.request_method) && static_file?(unescape(request.path_info))
42
42
  request.path_info.gsub! %r{\.([^\./]+)$}, ''
43
43
  format $1 || options.default_content
44
-
44
+
45
45
  # For the oh so common case of actually wanting Javascript from an XmlHttpRequest
46
46
  format :js if request.xhr? && options.assume_xhr_is_js?
47
47
  end
@@ -92,6 +92,7 @@ module Sinatra
92
92
 
93
93
  engine = request.env['sinatra.error'].message[/\.([^\.]+)$/, 1]
94
94
  path = request.path_info[/([^\/]+)$/, 1]
95
+ path = "root" if path.nil? || path.empty?
95
96
 
96
97
  layout = case engine
97
98
  when 'haml' then "!!!\n%html\n %body= yield"
@@ -133,14 +134,21 @@ module Sinatra
133
134
 
134
135
  app.class_eval do
135
136
  private
136
- def lookup_template_with_format(*args)
137
+ def render_with_format(*args)
137
138
  args[1] = "#{args[1]}.#{format}".to_sym
138
- lookup_template_without_format *args
139
+ render_without_format *args
139
140
  rescue Errno::ENOENT
140
141
  raise MissingTemplate, "#{args[1]}.#{args[0]}"
141
142
  end
142
- alias_method :lookup_template_without_format, :lookup_template
143
- alias_method :lookup_template, :lookup_template_with_format
143
+ alias_method :render_without_format, :render
144
+ alias_method :render, :render_with_format
145
+
146
+ def lookup_layout_with_format(*args)
147
+ args[1] = "#{args[1]}.#{format}".to_sym if args
148
+ lookup_layout_without_format *args
149
+ end
150
+ alias_method :lookup_layout_without_format, :lookup_layout
151
+ alias_method :lookup_layout, :lookup_layout_with_format
144
152
  end
145
153
  end
146
154
 
@@ -170,16 +178,16 @@ module Sinatra
170
178
 
171
179
  handler = wants[format]
172
180
  raise UnhandledFormat if handler.nil?
173
-
181
+
174
182
  opts = [format]
175
183
  opts << {:charset => options.default_charset} if TEXT_MIME_TYPES.include? format && response['Content-Type'] !~ /charset=/
176
184
 
177
185
  content_type *opts
178
-
186
+
179
187
  handler.call
180
188
  end
181
189
  end
182
190
  end
183
191
 
184
- register RespondTo
192
+ Sinatra::Application.register RespondTo
185
193
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cehoffman-sinatra-respond_to
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Hoffman
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-11 00:00:00 -07:00
12
+ date: 2009-05-12 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: sinatra
16
+ name: sinatra-sinatra
17
17
  type: :runtime
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement