sinatra-respond_to 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/.rspec +2 -0
- data/Gemfile.lock +21 -17
- data/README.md +5 -8
- data/Rakefile +5 -7
- data/lib/sinatra/respond_to.rb +2 -11
- data/lib/sinatra/respond_to/version.rb +1 -1
- data/sinatra-respond_to.gemspec +7 -6
- data/spec/extension_spec.rb +4 -28
- metadata +30 -41
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile.lock
CHANGED
@@ -2,38 +2,42 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
sinatra-respond_to (0.5.0)
|
5
|
-
sinatra (~> 1.
|
5
|
+
sinatra (~> 1.1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
10
|
builder (2.1.2)
|
11
11
|
diff-lcs (1.1.2)
|
12
|
-
haml (3.0.
|
12
|
+
haml (3.0.22)
|
13
13
|
rack (1.2.1)
|
14
|
-
rack-test (0.5.
|
14
|
+
rack-test (0.5.6)
|
15
15
|
rack (>= 1.0)
|
16
|
-
rcov (0.9.
|
17
|
-
rspec (2.0.
|
18
|
-
rspec-core (
|
19
|
-
rspec-expectations (
|
20
|
-
rspec-mocks (
|
21
|
-
rspec-core (2.0.
|
22
|
-
rspec-expectations (2.0.
|
16
|
+
rcov (0.9.9)
|
17
|
+
rspec (2.0.1)
|
18
|
+
rspec-core (~> 2.0.1)
|
19
|
+
rspec-expectations (~> 2.0.1)
|
20
|
+
rspec-mocks (~> 2.0.1)
|
21
|
+
rspec-core (2.0.1)
|
22
|
+
rspec-expectations (2.0.1)
|
23
23
|
diff-lcs (>= 1.1.2)
|
24
|
-
rspec-mocks (2.0.
|
25
|
-
|
26
|
-
|
24
|
+
rspec-mocks (2.0.1)
|
25
|
+
rspec-core (~> 2.0.1)
|
26
|
+
rspec-expectations (~> 2.0.1)
|
27
|
+
sinatra (1.1.0)
|
28
|
+
rack (~> 1.1)
|
29
|
+
tilt (~> 1.1)
|
30
|
+
tilt (1.1)
|
27
31
|
|
28
32
|
PLATFORMS
|
29
33
|
ruby
|
30
34
|
|
31
35
|
DEPENDENCIES
|
32
36
|
builder (>= 2.0)
|
33
|
-
bundler (~> 1.0.0
|
37
|
+
bundler (~> 1.0.0)
|
34
38
|
haml (>= 2.0)
|
35
|
-
rack-test (~> 0.5.
|
39
|
+
rack-test (~> 0.5.6)
|
36
40
|
rcov (~> 0.9.8)
|
37
|
-
rspec (~> 2.0.
|
38
|
-
sinatra (~> 1.
|
41
|
+
rspec (~> 2.0.1)
|
42
|
+
sinatra (~> 1.1)
|
39
43
|
sinatra-respond_to!
|
data/README.md
CHANGED
@@ -8,7 +8,6 @@ A respond\_to style Rails block for baked-in web service support in Sinatra
|
|
8
8
|
|
9
9
|
## FEATURES/PROBLEMS:
|
10
10
|
|
11
|
-
* Handles setting charset for appropriate types
|
12
11
|
* Handles setting the content type depending on what is being served
|
13
12
|
* Automatically can adjust XMLHttpRequests to return Javascript
|
14
13
|
|
@@ -70,9 +69,6 @@ To change the character set of the response, there is a `charset` helper. For e
|
|
70
69
|
|
71
70
|
There a few options available for configuring the default behavior of respond\_to using Sinatra's `set` utility.
|
72
71
|
|
73
|
-
* **default\_charset - utf-8**
|
74
|
-
Assumes all text documents are encoded using this character set.
|
75
|
-
This can be overridden within the respond_to block for the appropriate format
|
76
72
|
* **default\_content - :html**
|
77
73
|
When a user vists a url without an extension, for example /post this will be
|
78
74
|
the assumed content to serve first. Expects a symbol as used in setting content_type.
|
@@ -83,7 +79,9 @@ There a few options available for configuring the default behavior of respond\_t
|
|
83
79
|
|
84
80
|
## REQUIREMENTS:
|
85
81
|
|
86
|
-
* sinatra 1.
|
82
|
+
* sinatra 1.1
|
83
|
+
|
84
|
+
If you would like to use Sinatra 1.0, use version `0.5.0`.
|
87
85
|
|
88
86
|
## INSTALL:
|
89
87
|
|
@@ -93,11 +91,10 @@ There a few options available for configuring the default behavior of respond\_t
|
|
93
91
|
Due to the way respond\_to works, all incoming requests have the extension striped from the request.path\_info. This causes routes like the following to fail.
|
94
92
|
|
95
93
|
get '/style.css' do
|
96
|
-
content_type :css, :charset => 'utf-8'
|
97
94
|
sass :style # => renders views/style.sass
|
98
95
|
end
|
99
96
|
|
100
|
-
They need to be changed to the following.
|
97
|
+
They need to be changed to the following.
|
101
98
|
|
102
99
|
get '/style' do
|
103
100
|
sass :style # => renders views/style.css.sass
|
@@ -114,7 +111,7 @@ If you want to ensure the route only gets called for css requests try this. Thi
|
|
114
111
|
After checking out the source, run:
|
115
112
|
|
116
113
|
$ bundle install
|
117
|
-
$ rake spec
|
114
|
+
$ rake spec
|
118
115
|
|
119
116
|
This task will install any missing dependencies, run the tests/specs, and generate the RDoc.
|
120
117
|
|
data/Rakefile
CHANGED
@@ -3,13 +3,11 @@ Bundler::GemHelper.install_tasks
|
|
3
3
|
|
4
4
|
begin
|
5
5
|
require 'rspec/core/rake_task'
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
t.rcov_opts << "--comments --exclude spec,pkg,#{ENV['GEM_HOME']}"
|
12
|
-
end
|
6
|
+
desc 'Run specs'
|
7
|
+
RSpec::Core::RakeTask.new do |t|
|
8
|
+
t.rcov = true
|
9
|
+
t.rcov_opts = ['--sort coverage --text-summary --sort-reverse']
|
10
|
+
t.rcov_opts << "--comments --exclude spec,pkg,#{ENV['GEM_HOME']}"
|
13
11
|
end
|
14
12
|
rescue LoadError
|
15
13
|
puts 'RSpec not available, try a bundle install'
|
data/lib/sinatra/respond_to.rb
CHANGED
@@ -16,16 +16,9 @@ module Sinatra
|
|
16
16
|
def code; 500 end
|
17
17
|
end
|
18
18
|
|
19
|
-
TEXT_MIME_TYPES = [:txt, :html, :js, :json, :xml, :rss, :atom, :css, :asm, :c, :cc, :conf,
|
20
|
-
:csv, :cxx, :diff, :dtd, :f, :f77, :f90, :for, :gemspec, :h, :hh, :htm,
|
21
|
-
:log, :mathml, :mml, :p, :pas, :pl, :pm, :py, :rake, :rb, :rdf, :rtf, :ru,
|
22
|
-
:s, :sgm, :sgml, :sh, :svg, :svgz, :text, :wsdl, :xhtml, :xsl, :xslt, :yaml,
|
23
|
-
:yml, :ics]
|
24
|
-
|
25
19
|
def self.registered(app)
|
26
20
|
app.helpers RespondTo::Helpers
|
27
21
|
|
28
|
-
app.set :default_charset, 'utf-8'
|
29
22
|
app.set :default_content, :html
|
30
23
|
app.set :assume_xhr_is_js, true
|
31
24
|
|
@@ -51,7 +44,6 @@ module Sinatra
|
|
51
44
|
|
52
45
|
format request.xhr? && options.assume_xhr_is_js? ? :js : $1 || options.default_content
|
53
46
|
end
|
54
|
-
charset options.default_charset if Sinatra::RespondTo::TEXT_MIME_TYPES.include? format
|
55
47
|
end
|
56
48
|
end
|
57
49
|
|
@@ -157,9 +149,8 @@ module Sinatra
|
|
157
149
|
klass.class_eval do
|
158
150
|
alias :content_type_without_save :content_type
|
159
151
|
def content_type(*args)
|
160
|
-
content_type_without_save *args
|
161
152
|
@_format = args.first.to_sym
|
162
|
-
|
153
|
+
content_type_without_save *args
|
163
154
|
end
|
164
155
|
end
|
165
156
|
end
|
@@ -170,7 +161,7 @@ module Sinatra
|
|
170
161
|
fail "Unknown media type #{val}\nTry registering the extension with a mime type" if mime_type.nil?
|
171
162
|
|
172
163
|
@_format = val.to_sym
|
173
|
-
response['Content-Type'].sub!(/^[^;]+/, mime_type)
|
164
|
+
response['Content-Type'] ? response['Content-Type'].sub!(/^[^;]+/, mime_type) : content_type(@_format)
|
174
165
|
end
|
175
166
|
|
176
167
|
@_format
|
data/sinatra-respond_to.gemspec
CHANGED
@@ -12,16 +12,17 @@ Gem::Specification.new do |s|
|
|
12
12
|
|
13
13
|
s.required_rubygems_version = '>= 1.3.6'
|
14
14
|
|
15
|
-
s.add_runtime_dependency 'sinatra', '~> 1.
|
15
|
+
s.add_runtime_dependency 'sinatra', '~> 1.1'
|
16
16
|
|
17
|
-
s.add_development_dependency '
|
18
|
-
s.add_development_dependency '
|
19
|
-
s.add_development_dependency 'rack-test', '~> 0.5.4'
|
17
|
+
s.add_development_dependency 'rspec', '~> 2.0.1'
|
18
|
+
s.add_development_dependency 'rack-test', '~> 0.5.6'
|
20
19
|
s.add_development_dependency 'rcov', '~> 0.9.8'
|
21
20
|
s.add_development_dependency 'builder', '>= 2.0'
|
22
21
|
s.add_development_dependency 'haml', '>= 2.0'
|
22
|
+
s.add_development_dependency 'bundler', '~> 1.0.0'
|
23
23
|
|
24
|
-
s.
|
25
|
-
s.
|
24
|
+
s.files = `git ls-files`.split("\n")
|
25
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
26
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
26
27
|
s.require_path = 'lib'
|
27
28
|
end
|
data/spec/extension_spec.rb
CHANGED
@@ -6,10 +6,6 @@ describe Sinatra::RespondTo do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
describe "options" do
|
9
|
-
it "should initialize with :default_charset set to 'utf-8'" do
|
10
|
-
TestApp.default_charset.should == 'utf-8'
|
11
|
-
end
|
12
|
-
|
13
9
|
it "should initialize with :default_content set to :html" do
|
14
10
|
TestApp.default_content.should == :html
|
15
11
|
end
|
@@ -84,24 +80,12 @@ describe Sinatra::RespondTo do
|
|
84
80
|
last_response['Content-Type'].should =~ %r{#{mime_type(:xml)}}
|
85
81
|
end
|
86
82
|
|
87
|
-
it "should set the character set to the default character set" do
|
88
|
-
get "/default_charset"
|
89
|
-
|
90
|
-
last_response['Content-Type'].should =~ %r{charset=#{TestApp.default_charset}}
|
91
|
-
end
|
92
|
-
|
93
83
|
it "should honor a change in character set in block" do
|
94
84
|
get "/iso-8859-1"
|
95
85
|
|
96
86
|
last_response['Content-Type'].should =~ %r{charset=iso-8859-1}
|
97
87
|
end
|
98
88
|
|
99
|
-
it "should not set the character set when requesting a non text resource" do
|
100
|
-
get "/resource.png"
|
101
|
-
|
102
|
-
last_response['Content-Type'].should_not =~ /charset/
|
103
|
-
end
|
104
|
-
|
105
89
|
it "should return not found when path does not exist" do
|
106
90
|
get "/nonexistant-path.txt"
|
107
91
|
|
@@ -149,23 +133,11 @@ describe Sinatra::RespondTo do
|
|
149
133
|
last_response['Content-Type'].should =~ %r{#{mime_type(TestApp.default_content)}}
|
150
134
|
end
|
151
135
|
|
152
|
-
it "should set the default character when no extension" do
|
153
|
-
get "/normal-no-respond_to"
|
154
|
-
|
155
|
-
last_response['Content-Type'].should =~ %r{charset=#{TestApp.default_charset}}
|
156
|
-
end
|
157
|
-
|
158
136
|
it "should set the appropriate content type when given an extension" do
|
159
137
|
get "/normal-no-respond_to.css"
|
160
138
|
|
161
139
|
last_response['Content-Type'].should =~ %r{#{mime_type(:css)}}
|
162
140
|
end
|
163
|
-
|
164
|
-
it "should set the default charset when given an extension" do
|
165
|
-
get "/normal-no-respond_to.css"
|
166
|
-
|
167
|
-
last_response['Content-Type'].should =~ %r{charset=#{TestApp.default_charset}}
|
168
|
-
end
|
169
141
|
end
|
170
142
|
|
171
143
|
describe "error pages in production" do
|
@@ -340,6 +312,10 @@ describe Sinatra::RespondTo do
|
|
340
312
|
end
|
341
313
|
|
342
314
|
it "should not return nil when only content_type sets headers" do
|
315
|
+
settings = mock('settings')
|
316
|
+
settings.should_receive(:default_encoding).and_return('utf-8')
|
317
|
+
stub!(:settings).and_return(settings)
|
318
|
+
|
343
319
|
content_type :xhtml
|
344
320
|
|
345
321
|
format.should == :xhtml
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-respond_to
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 11
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
|
-
-
|
7
|
+
- 6
|
9
8
|
- 0
|
10
|
-
version: 0.
|
9
|
+
version: 0.6.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Chris Hoffman
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-11-04 00:00:00 -05:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,90 +25,79 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ~>
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 15
|
30
28
|
segments:
|
31
29
|
- 1
|
32
|
-
-
|
33
|
-
version: "1.
|
30
|
+
- 1
|
31
|
+
version: "1.1"
|
34
32
|
type: :runtime
|
35
33
|
version_requirements: *id001
|
36
34
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
35
|
+
name: rspec
|
38
36
|
prerelease: false
|
39
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
38
|
none: false
|
41
39
|
requirements:
|
42
40
|
- - ~>
|
43
41
|
- !ruby/object:Gem::Version
|
44
|
-
hash: 15424063
|
45
42
|
segments:
|
46
|
-
-
|
47
|
-
- 0
|
43
|
+
- 2
|
48
44
|
- 0
|
49
|
-
-
|
50
|
-
|
51
|
-
version: 1.0.0.rc.5
|
45
|
+
- 1
|
46
|
+
version: 2.0.1
|
52
47
|
type: :development
|
53
48
|
version_requirements: *id002
|
54
49
|
- !ruby/object:Gem::Dependency
|
55
|
-
name:
|
50
|
+
name: rack-test
|
56
51
|
prerelease: false
|
57
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
58
53
|
none: false
|
59
54
|
requirements:
|
60
55
|
- - ~>
|
61
56
|
- !ruby/object:Gem::Version
|
62
|
-
hash: 62196421
|
63
57
|
segments:
|
64
|
-
- 2
|
65
|
-
- 0
|
66
58
|
- 0
|
67
|
-
-
|
68
|
-
-
|
69
|
-
version:
|
59
|
+
- 5
|
60
|
+
- 6
|
61
|
+
version: 0.5.6
|
70
62
|
type: :development
|
71
63
|
version_requirements: *id003
|
72
64
|
- !ruby/object:Gem::Dependency
|
73
|
-
name:
|
65
|
+
name: rcov
|
74
66
|
prerelease: false
|
75
67
|
requirement: &id004 !ruby/object:Gem::Requirement
|
76
68
|
none: false
|
77
69
|
requirements:
|
78
70
|
- - ~>
|
79
71
|
- !ruby/object:Gem::Version
|
80
|
-
hash: 3
|
81
72
|
segments:
|
82
73
|
- 0
|
83
|
-
-
|
84
|
-
-
|
85
|
-
version: 0.
|
74
|
+
- 9
|
75
|
+
- 8
|
76
|
+
version: 0.9.8
|
86
77
|
type: :development
|
87
78
|
version_requirements: *id004
|
88
79
|
- !ruby/object:Gem::Dependency
|
89
|
-
name:
|
80
|
+
name: builder
|
90
81
|
prerelease: false
|
91
82
|
requirement: &id005 !ruby/object:Gem::Requirement
|
92
83
|
none: false
|
93
84
|
requirements:
|
94
|
-
- -
|
85
|
+
- - ">="
|
95
86
|
- !ruby/object:Gem::Version
|
96
|
-
hash: 43
|
97
87
|
segments:
|
88
|
+
- 2
|
98
89
|
- 0
|
99
|
-
|
100
|
-
- 8
|
101
|
-
version: 0.9.8
|
90
|
+
version: "2.0"
|
102
91
|
type: :development
|
103
92
|
version_requirements: *id005
|
104
93
|
- !ruby/object:Gem::Dependency
|
105
|
-
name:
|
94
|
+
name: haml
|
106
95
|
prerelease: false
|
107
96
|
requirement: &id006 !ruby/object:Gem::Requirement
|
108
97
|
none: false
|
109
98
|
requirements:
|
110
99
|
- - ">="
|
111
100
|
- !ruby/object:Gem::Version
|
112
|
-
hash: 3
|
113
101
|
segments:
|
114
102
|
- 2
|
115
103
|
- 0
|
@@ -117,18 +105,18 @@ dependencies:
|
|
117
105
|
type: :development
|
118
106
|
version_requirements: *id006
|
119
107
|
- !ruby/object:Gem::Dependency
|
120
|
-
name:
|
108
|
+
name: bundler
|
121
109
|
prerelease: false
|
122
110
|
requirement: &id007 !ruby/object:Gem::Requirement
|
123
111
|
none: false
|
124
112
|
requirements:
|
125
|
-
- -
|
113
|
+
- - ~>
|
126
114
|
- !ruby/object:Gem::Version
|
127
|
-
hash: 3
|
128
115
|
segments:
|
129
|
-
-
|
116
|
+
- 1
|
130
117
|
- 0
|
131
|
-
|
118
|
+
- 0
|
119
|
+
version: 1.0.0
|
132
120
|
type: :development
|
133
121
|
version_requirements: *id007
|
134
122
|
description:
|
@@ -141,6 +129,8 @@ extensions: []
|
|
141
129
|
extra_rdoc_files: []
|
142
130
|
|
143
131
|
files:
|
132
|
+
- .gitignore
|
133
|
+
- .rspec
|
144
134
|
- Changelog.rdoc
|
145
135
|
- Gemfile
|
146
136
|
- Gemfile.lock
|
@@ -174,7 +164,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
174
164
|
requirements:
|
175
165
|
- - ">="
|
176
166
|
- !ruby/object:Gem::Version
|
177
|
-
hash: 3
|
178
167
|
segments:
|
179
168
|
- 0
|
180
169
|
version: "0"
|
@@ -183,7 +172,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
172
|
requirements:
|
184
173
|
- - ">="
|
185
174
|
- !ruby/object:Gem::Version
|
186
|
-
hash: 23
|
187
175
|
segments:
|
188
176
|
- 1
|
189
177
|
- 3
|
@@ -198,6 +186,7 @@ specification_version: 3
|
|
198
186
|
summary: A respond_to style Rails block for baked-in web service support in Sinatra
|
199
187
|
test_files:
|
200
188
|
- spec/app/production_error_app.rb
|
189
|
+
- spec/app/public/static folder/.keep
|
201
190
|
- spec/app/public/static.txt
|
202
191
|
- spec/app/test_app.rb
|
203
192
|
- spec/app/unreachable_static.txt
|