sinatra-bundles 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/Rakefile +2 -1
  2. data/VERSION +1 -1
  3. data/lib/sinatra/bundles/bundle.rb +36 -0
  4. data/lib/sinatra/bundles/helpers.rb +22 -0
  5. data/lib/sinatra/bundles/javascript_bundle.rb +37 -0
  6. data/lib/sinatra/bundles/stylesheet_bundle.rb +36 -0
  7. data/lib/sinatra/bundles.rb +4 -114
  8. data/sinatra-bundles.gemspec +11 -58
  9. data/spec/app.rb +1 -1
  10. data/spec/production_app.rb +1 -1
  11. data/spec/public/javascripts/eval.js +5 -0
  12. data/spec/sinatra-bundles_spec.rb +10 -1
  13. data/spec/spec_helper.rb +5 -6
  14. metadata +17 -57
  15. data/vendor/cache/sinatra-0.10.1.gem +0 -0
  16. data/vendor/gems/sinatra-0.10.1/AUTHORS +0 -43
  17. data/vendor/gems/sinatra-0.10.1/CHANGES +0 -467
  18. data/vendor/gems/sinatra-0.10.1/LICENSE +0 -22
  19. data/vendor/gems/sinatra-0.10.1/README.jp.rdoc +0 -552
  20. data/vendor/gems/sinatra-0.10.1/README.rdoc +0 -622
  21. data/vendor/gems/sinatra-0.10.1/Rakefile +0 -129
  22. data/vendor/gems/sinatra-0.10.1/lib/sinatra/base.rb +0 -1143
  23. data/vendor/gems/sinatra-0.10.1/lib/sinatra/images/404.png +0 -0
  24. data/vendor/gems/sinatra-0.10.1/lib/sinatra/images/500.png +0 -0
  25. data/vendor/gems/sinatra-0.10.1/lib/sinatra/main.rb +0 -28
  26. data/vendor/gems/sinatra-0.10.1/lib/sinatra/showexceptions.rb +0 -303
  27. data/vendor/gems/sinatra-0.10.1/lib/sinatra/tilt.rb +0 -509
  28. data/vendor/gems/sinatra-0.10.1/lib/sinatra.rb +0 -7
  29. data/vendor/gems/sinatra-0.10.1/sinatra.gemspec +0 -86
  30. data/vendor/gems/sinatra-0.10.1/test/base_test.rb +0 -160
  31. data/vendor/gems/sinatra-0.10.1/test/builder_test.rb +0 -65
  32. data/vendor/gems/sinatra-0.10.1/test/contest.rb +0 -64
  33. data/vendor/gems/sinatra-0.10.1/test/erb_test.rb +0 -81
  34. data/vendor/gems/sinatra-0.10.1/test/erubis_test.rb +0 -82
  35. data/vendor/gems/sinatra-0.10.1/test/extensions_test.rb +0 -100
  36. data/vendor/gems/sinatra-0.10.1/test/filter_test.rb +0 -195
  37. data/vendor/gems/sinatra-0.10.1/test/haml_test.rb +0 -90
  38. data/vendor/gems/sinatra-0.10.1/test/helper.rb +0 -76
  39. data/vendor/gems/sinatra-0.10.1/test/helpers_test.rb +0 -573
  40. data/vendor/gems/sinatra-0.10.1/test/mapped_error_test.rb +0 -186
  41. data/vendor/gems/sinatra-0.10.1/test/middleware_test.rb +0 -68
  42. data/vendor/gems/sinatra-0.10.1/test/request_test.rb +0 -33
  43. data/vendor/gems/sinatra-0.10.1/test/response_test.rb +0 -42
  44. data/vendor/gems/sinatra-0.10.1/test/result_test.rb +0 -98
  45. data/vendor/gems/sinatra-0.10.1/test/route_added_hook_test.rb +0 -59
  46. data/vendor/gems/sinatra-0.10.1/test/routing_test.rb +0 -878
  47. data/vendor/gems/sinatra-0.10.1/test/sass_test.rb +0 -79
  48. data/vendor/gems/sinatra-0.10.1/test/server_test.rb +0 -47
  49. data/vendor/gems/sinatra-0.10.1/test/sinatra_test.rb +0 -13
  50. data/vendor/gems/sinatra-0.10.1/test/static_test.rb +0 -87
  51. data/vendor/gems/sinatra-0.10.1/test/templates_test.rb +0 -155
  52. data/vendor/gems/sinatra-0.10.1/test/views/error.builder +0 -3
  53. data/vendor/gems/sinatra-0.10.1/test/views/error.erb +0 -3
  54. data/vendor/gems/sinatra-0.10.1/test/views/error.erubis +0 -3
  55. data/vendor/gems/sinatra-0.10.1/test/views/error.haml +0 -3
  56. data/vendor/gems/sinatra-0.10.1/test/views/error.sass +0 -2
  57. data/vendor/gems/sinatra-0.10.1/test/views/foo/hello.test +0 -1
  58. data/vendor/gems/sinatra-0.10.1/test/views/hello.builder +0 -1
  59. data/vendor/gems/sinatra-0.10.1/test/views/hello.erb +0 -1
  60. data/vendor/gems/sinatra-0.10.1/test/views/hello.erubis +0 -1
  61. data/vendor/gems/sinatra-0.10.1/test/views/hello.haml +0 -1
  62. data/vendor/gems/sinatra-0.10.1/test/views/hello.sass +0 -2
  63. data/vendor/gems/sinatra-0.10.1/test/views/hello.test +0 -1
  64. data/vendor/gems/sinatra-0.10.1/test/views/layout2.builder +0 -3
  65. data/vendor/gems/sinatra-0.10.1/test/views/layout2.erb +0 -2
  66. data/vendor/gems/sinatra-0.10.1/test/views/layout2.erubis +0 -2
  67. data/vendor/gems/sinatra-0.10.1/test/views/layout2.haml +0 -2
  68. data/vendor/gems/sinatra-0.10.1/test/views/layout2.test +0 -1
  69. data/vendor/specifications/sinatra-0.10.1.gemspec +0 -40
@@ -1,195 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class BeforeFilterTest < Test::Unit::TestCase
4
- it "executes filters in the order defined" do
5
- count = 0
6
- mock_app do
7
- get('/') { 'Hello World' }
8
- before {
9
- assert_equal 0, count
10
- count = 1
11
- }
12
- before {
13
- assert_equal 1, count
14
- count = 2
15
- }
16
- end
17
-
18
- get '/'
19
- assert ok?
20
- assert_equal 2, count
21
- assert_equal 'Hello World', body
22
- end
23
-
24
- it "can modify the request" do
25
- mock_app {
26
- get('/foo') { 'foo' }
27
- get('/bar') { 'bar' }
28
- before { request.path_info = '/bar' }
29
- }
30
-
31
- get '/foo'
32
- assert ok?
33
- assert_equal 'bar', body
34
- end
35
-
36
- it "can modify instance variables available to routes" do
37
- mock_app {
38
- before { @foo = 'bar' }
39
- get('/foo') { @foo }
40
- }
41
-
42
- get '/foo'
43
- assert ok?
44
- assert_equal 'bar', body
45
- end
46
-
47
- it "allows redirects" do
48
- mock_app {
49
- before { redirect '/bar' }
50
- get('/foo') do
51
- fail 'before block should have halted processing'
52
- 'ORLY?!'
53
- end
54
- }
55
-
56
- get '/foo'
57
- assert redirect?
58
- assert_equal '/bar', response['Location']
59
- assert_equal '', body
60
- end
61
-
62
- it "does not modify the response with its return value" do
63
- mock_app {
64
- before { 'Hello World!' }
65
- get '/foo' do
66
- assert_equal [], response.body
67
- 'cool'
68
- end
69
- }
70
-
71
- get '/foo'
72
- assert ok?
73
- assert_equal 'cool', body
74
- end
75
-
76
- it "does modify the response with halt" do
77
- mock_app {
78
- before { halt 302, 'Hi' }
79
- get '/foo' do
80
- "should not happen"
81
- end
82
- }
83
-
84
- get '/foo'
85
- assert_equal 302, response.status
86
- assert_equal 'Hi', body
87
- end
88
-
89
- it "gives you access to params" do
90
- mock_app {
91
- before { @foo = params['foo'] }
92
- get('/foo') { @foo }
93
- }
94
-
95
- get '/foo?foo=cool'
96
- assert ok?
97
- assert_equal 'cool', body
98
- end
99
-
100
- it "runs filters defined in superclasses" do
101
- base = Class.new(Sinatra::Base)
102
- base.before { @foo = 'hello from superclass' }
103
-
104
- mock_app(base) {
105
- get('/foo') { @foo }
106
- }
107
-
108
- get '/foo'
109
- assert_equal 'hello from superclass', body
110
- end
111
- end
112
-
113
- class AfterFilterTest < Test::Unit::TestCase
114
- it "executes filters in the order defined" do
115
- invoked = 0
116
- mock_app do
117
- before { invoked = 2 }
118
- get('/') { invoked += 2 }
119
- after { invoked *= 2 }
120
- end
121
-
122
- get '/'
123
- assert ok?
124
-
125
- assert_equal 8, invoked
126
- end
127
-
128
- it "executes filters in the order defined" do
129
- count = 0
130
- mock_app do
131
- get('/') { 'Hello World' }
132
- after {
133
- assert_equal 0, count
134
- count = 1
135
- }
136
- after {
137
- assert_equal 1, count
138
- count = 2
139
- }
140
- end
141
-
142
- get '/'
143
- assert ok?
144
- assert_equal 2, count
145
- assert_equal 'Hello World', body
146
- end
147
-
148
- it "allows redirects" do
149
- mock_app {
150
- get('/foo') { 'ORLY' }
151
- after { redirect '/bar' }
152
- }
153
-
154
- get '/foo'
155
- assert redirect?
156
- assert_equal '/bar', response['Location']
157
- assert_equal '', body
158
- end
159
-
160
- it "does not modify the response with its return value" do
161
- mock_app {
162
- get('/foo') { 'cool' }
163
- after { 'Hello World!' }
164
- }
165
-
166
- get '/foo'
167
- assert ok?
168
- assert_equal 'cool', body
169
- end
170
-
171
- it "does modify the response with halt" do
172
- mock_app {
173
- get '/foo' do
174
- "should not be returned"
175
- end
176
- after { halt 302, 'Hi' }
177
- }
178
-
179
- get '/foo'
180
- assert_equal 302, response.status
181
- assert_equal 'Hi', body
182
- end
183
-
184
- it "runs filters defined in superclasses" do
185
- count = 2
186
- base = Class.new(Sinatra::Base)
187
- base.after { count *= 2 }
188
- mock_app(base) {
189
- get('/foo') { count += 2 }
190
- }
191
-
192
- get '/foo'
193
- assert_equal 8, count
194
- end
195
- end
@@ -1,90 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
- require 'haml'
3
-
4
- class HAMLTest < Test::Unit::TestCase
5
- def haml_app(&block)
6
- mock_app {
7
- set :views, File.dirname(__FILE__) + '/views'
8
- get '/', &block
9
- }
10
- get '/'
11
- end
12
-
13
- it 'renders inline HAML strings' do
14
- haml_app { haml '%h1 Hiya' }
15
- assert ok?
16
- assert_equal "<h1>Hiya</h1>\n", body
17
- end
18
-
19
- it 'renders .haml files in views path' do
20
- haml_app { haml :hello }
21
- assert ok?
22
- assert_equal "<h1>Hello From Haml</h1>\n", body
23
- end
24
-
25
- it "renders with inline layouts" do
26
- mock_app {
27
- layout { %q(%h1= 'THIS. IS. ' + yield.upcase) }
28
- get('/') { haml '%em Sparta' }
29
- }
30
- get '/'
31
- assert ok?
32
- assert_equal "<h1>THIS. IS. <EM>SPARTA</EM></h1>\n", body
33
- end
34
-
35
- it "renders with file layouts" do
36
- haml_app {
37
- haml 'Hello World', :layout => :layout2
38
- }
39
- assert ok?
40
- assert_equal "<h1>HAML Layout!</h1>\n<p>Hello World</p>\n", body
41
- end
42
-
43
- it "raises error if template not found" do
44
- mock_app {
45
- get('/') { haml :no_such_template }
46
- }
47
- assert_raise(Errno::ENOENT) { get('/') }
48
- end
49
-
50
- it "passes HAML options to the Haml engine" do
51
- mock_app {
52
- get '/' do
53
- haml "!!!\n%h1 Hello World", :format => :html5
54
- end
55
- }
56
- get '/'
57
- assert ok?
58
- assert_equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n", body
59
- end
60
-
61
- it "passes default HAML options to the Haml engine" do
62
- mock_app {
63
- set :haml, {:format => :html5}
64
- get '/' do
65
- haml "!!!\n%h1 Hello World"
66
- end
67
- }
68
- get '/'
69
- assert ok?
70
- assert_equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n", body
71
- end
72
-
73
- it "merges the default HAML options with the overrides and passes them to the Haml engine" do
74
- mock_app {
75
- set :haml, {:format => :html5, :attr_wrapper => '"'} # default HAML attr are <tag attr='single-quoted'>
76
- get '/' do
77
- haml "!!!\n%h1{:class => :header} Hello World"
78
- end
79
- get '/html4' do
80
- haml "!!!\n%h1{:class => 'header'} Hello World", :format => :html4
81
- end
82
- }
83
- get '/'
84
- assert ok?
85
- assert_equal "<!DOCTYPE html>\n<h1 class=\"header\">Hello World</h1>\n", body
86
- get '/html4'
87
- assert ok?
88
- assert_match(/^<!DOCTYPE html PUBLIC (.*) HTML 4.01/, body)
89
- end
90
- end
@@ -1,76 +0,0 @@
1
- ENV['RACK_ENV'] = 'test'
2
-
3
- begin
4
- require 'rack'
5
- rescue LoadError
6
- require 'rubygems'
7
- require 'rack'
8
- end
9
-
10
- testdir = File.dirname(__FILE__)
11
- $LOAD_PATH.unshift testdir unless $LOAD_PATH.include?(testdir)
12
-
13
- libdir = File.dirname(File.dirname(__FILE__)) + '/lib'
14
- $LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)
15
-
16
- require 'contest'
17
- require 'rack/test'
18
- require 'sinatra/base'
19
-
20
- class Sinatra::Base
21
- # Allow assertions in request context
22
- include Test::Unit::Assertions
23
- end
24
-
25
- Sinatra::Base.set :environment, :test
26
-
27
- class Test::Unit::TestCase
28
- include Rack::Test::Methods
29
-
30
- class << self
31
- alias_method :it, :test
32
- end
33
-
34
- alias_method :response, :last_response
35
-
36
- setup do
37
- Sinatra::Base.set :environment, :test
38
- end
39
-
40
- # Sets up a Sinatra::Base subclass defined with the block
41
- # given. Used in setup or individual spec methods to establish
42
- # the application.
43
- def mock_app(base=Sinatra::Base, &block)
44
- @app = Sinatra.new(base, &block)
45
- end
46
-
47
- def app
48
- Rack::Lint.new(@app)
49
- end
50
-
51
- def body
52
- response.body.to_s
53
- end
54
-
55
- # Delegate other missing methods to response.
56
- def method_missing(name, *args, &block)
57
- if response && response.respond_to?(name)
58
- response.send(name, *args, &block)
59
- else
60
- super
61
- end
62
- end
63
-
64
- # Also check response since we delegate there.
65
- def respond_to?(symbol, include_private=false)
66
- super || (response && response.respond_to?(symbol, include_private))
67
- end
68
-
69
- # Do not output warnings for the duration of the block.
70
- def silence_warnings
71
- $VERBOSE, v = nil, $VERBOSE
72
- yield
73
- ensure
74
- $VERBOSE = v
75
- end
76
- end