sprockets-rails 1.0.0 → 2.0.0.backport1

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.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +155 -0
  3. data/lib/sprockets/rails.rb +3 -0
  4. data/lib/sprockets/rails/helper.rb +145 -0
  5. data/lib/sprockets/rails/legacy_asset_tag_helper.rb +32 -0
  6. data/lib/sprockets/rails/legacy_asset_url_helper.rb +130 -0
  7. data/lib/sprockets/rails/task.rb +82 -0
  8. data/lib/sprockets/railtie.rb +125 -0
  9. metadata +52 -81
  10. data/MIT-LICENSE +0 -20
  11. data/README.rdoc +0 -3
  12. data/Rakefile +0 -24
  13. data/lib/sprockets-rails.rb +0 -7
  14. data/lib/sprockets/rails/bootstrap.rb +0 -41
  15. data/lib/sprockets/rails/compressors.rb +0 -87
  16. data/lib/sprockets/rails/helpers.rb +0 -8
  17. data/lib/sprockets/rails/helpers/isolated_helper.rb +0 -15
  18. data/lib/sprockets/rails/helpers/rails_helper.rb +0 -169
  19. data/lib/sprockets/rails/railtie.rb +0 -64
  20. data/lib/sprockets/rails/static_compiler.rb +0 -64
  21. data/lib/sprockets/rails/version.rb +0 -5
  22. data/lib/tasks/assets.rake +0 -105
  23. data/test/abstract_unit.rb +0 -145
  24. data/test/assets_debugging_test.rb +0 -65
  25. data/test/assets_test.rb +0 -532
  26. data/test/fixtures/alternate/stylesheets/style.css +0 -1
  27. data/test/fixtures/app/fonts/dir/font.ttf +0 -0
  28. data/test/fixtures/app/fonts/font.ttf +0 -0
  29. data/test/fixtures/app/images/logo.png +0 -0
  30. data/test/fixtures/app/javascripts/application.js +0 -1
  31. data/test/fixtures/app/javascripts/dir/xmlhr.js +0 -0
  32. data/test/fixtures/app/javascripts/extra.js +0 -0
  33. data/test/fixtures/app/javascripts/xmlhr.js +0 -0
  34. data/test/fixtures/app/stylesheets/application.css +0 -1
  35. data/test/fixtures/app/stylesheets/dir/style.css +0 -0
  36. data/test/fixtures/app/stylesheets/extra.css +0 -0
  37. data/test/fixtures/app/stylesheets/style.css +0 -0
  38. data/test/sprockets_compressors_test.rb +0 -27
  39. data/test/sprockets_helper_test.rb +0 -345
  40. data/test/sprockets_helper_with_routes_test.rb +0 -60
  41. data/test/test_helper.rb +0 -84
@@ -1 +0,0 @@
1
- /* Different from other style.css */
File without changes
File without changes
Binary file
@@ -1 +0,0 @@
1
- //= require xmlhr
File without changes
File without changes
File without changes
@@ -1 +0,0 @@
1
- /*= require style */
File without changes
File without changes
File without changes
@@ -1,27 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
-
3
- class CompressorsTest < ActiveSupport::TestCase
4
- def test_register_css_compressor
5
- Sprockets::Rails::Compressors.register_css_compressor(:null, Sprockets::Rails::NullCompressor)
6
- compressor = Sprockets::Rails::Compressors.registered_css_compressor(:null)
7
- assert_kind_of Sprockets::Rails::NullCompressor, compressor
8
- end
9
-
10
- def test_register_js_compressor
11
- Sprockets::Rails::Compressors.register_js_compressor(:uglifier, 'Uglifier', :require => 'uglifier')
12
- compressor = Sprockets::Rails::Compressors.registered_js_compressor(:uglifier)
13
- assert_kind_of Uglifier, compressor
14
- end
15
-
16
- def test_register_default_css_compressor
17
- Sprockets::Rails::Compressors.register_css_compressor(:null, Sprockets::Rails::NullCompressor, :default => true)
18
- compressor = Sprockets::Rails::Compressors.registered_css_compressor(:default)
19
- assert_kind_of Sprockets::Rails::NullCompressor, compressor
20
- end
21
-
22
- def test_register_default_js_compressor
23
- Sprockets::Rails::Compressors.register_js_compressor(:null, Sprockets::Rails::NullCompressor, :default => true)
24
- compressor = Sprockets::Rails::Compressors.registered_js_compressor(:default)
25
- assert_kind_of Sprockets::Rails::NullCompressor, compressor
26
- end
27
- end
@@ -1,345 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
-
3
- class SprocketsHelperTest < ActiveSupport::TestCase
4
- include Sprockets::Rails::Helpers::RailsHelper
5
-
6
- attr_accessor :assets, :controller, :params
7
-
8
- class MockRequest
9
- def protocol() 'http://' end
10
- def ssl?() false end
11
- def host_with_port() 'localhost' end
12
- def script_name() nil end
13
- end
14
-
15
- def setup
16
- @controller = BasicController.new
17
- @controller.request = MockRequest.new
18
-
19
- @assets = Sprockets::Environment.new
20
- @assets.append_path(FIXTURES.join("app/javascripts"))
21
- @assets.append_path(FIXTURES.join("app/stylesheets"))
22
- @assets.append_path(FIXTURES.join("app/images"))
23
- @assets.append_path(FIXTURES.join("app/fonts"))
24
-
25
- application = Struct.new(:config, :assets).new(config, @assets)
26
- ::Rails.stubs(:application).returns(application)
27
- @config = config
28
- @config.perform_caching = true
29
- @config.assets.digest = true
30
- @config.assets.compile = true
31
- @params = {}
32
- end
33
-
34
- def url_for(*args)
35
- "http://www.example.com"
36
- end
37
-
38
- def config
39
- @controller ? @controller.config : @config
40
- end
41
-
42
- def compute_host(source, request, options = {})
43
- raise "Should never get here"
44
- end
45
-
46
- test "asset_path" do
47
- assert_match %r{/assets/logo-[0-9a-f]+.png},
48
- asset_path("logo.png")
49
- assert_match %r{/assets/logo-[0-9a-f]+.png},
50
- asset_path("logo.png", :digest => true)
51
- assert_match %r{/assets/logo.png},
52
- asset_path("logo.png", :digest => false)
53
- end
54
-
55
- test "custom_asset_path" do
56
- @config.assets.prefix = '/s'
57
- assert_match %r{/s/logo-[0-9a-f]+.png},
58
- asset_path("logo.png")
59
- assert_match %r{/s/logo-[0-9a-f]+.png},
60
- asset_path("logo.png", :digest => true)
61
- assert_match %r{/s/logo.png},
62
- asset_path("logo.png", :digest => false)
63
- end
64
-
65
- test "asset_path with root relative assets" do
66
- assert_equal "/images/logo",
67
- asset_path("/images/logo")
68
- assert_equal "/images/logo.gif",
69
- asset_path("/images/logo.gif")
70
-
71
- assert_equal "/dir/audio",
72
- asset_path("/dir/audio")
73
- end
74
-
75
- test "asset_path with absolute urls" do
76
- assert_equal "http://www.example.com/video/play",
77
- asset_path("http://www.example.com/video/play")
78
- assert_equal "http://www.example.com/video/play.mp4",
79
- asset_path("http://www.example.com/video/play.mp4")
80
- end
81
-
82
- test "with a simple asset host the url should default to protocol relative" do
83
- @controller.config.default_asset_host_protocol = :relative
84
- @controller.config.asset_host = "assets-%d.example.com"
85
- assert_match %r{^//assets-\d.example.com/assets/logo-[0-9a-f]+.png},
86
- asset_path("logo.png")
87
- end
88
-
89
- test "with a simple asset host the url can be changed to use the request protocol" do
90
- @controller.config.asset_host = "assets-%d.example.com"
91
- @controller.config.default_asset_host_protocol = :request
92
- assert_match %r{http://assets-\d.example.com/assets/logo-[0-9a-f]+.png},
93
- asset_path("logo.png")
94
- end
95
-
96
- test "With a proc asset host that returns no protocol the url should be protocol relative" do
97
- @controller.config.default_asset_host_protocol = :relative
98
- @controller.config.asset_host = Proc.new do |asset|
99
- "assets-999.example.com"
100
- end
101
- assert_match %r{^//assets-999.example.com/assets/logo-[0-9a-f]+.png},
102
- asset_path("logo.png")
103
- end
104
-
105
- test "with a proc asset host that returns a protocol the url use it" do
106
- @controller.config.asset_host = Proc.new do |asset|
107
- "http://assets-999.example.com"
108
- end
109
- assert_match %r{http://assets-999.example.com/assets/logo-[0-9a-f]+.png},
110
- asset_path("logo.png")
111
- end
112
-
113
- test "stylesheets served with a controller in scope can access the request" do
114
- config.asset_host = Proc.new do |asset, request|
115
- assert_not_nil request
116
- "http://assets-666.example.com"
117
- end
118
- assert_match %r{http://assets-666.example.com/assets/logo-[0-9a-f]+.png},
119
- asset_path("logo.png")
120
- end
121
-
122
- test "stylesheets served without a controller in scope cannot access the request" do
123
- @controller = nil
124
- @config.asset_host = Proc.new do |asset, request|
125
- fail "This should not have been called."
126
- end
127
- assert_raises ActionController::RoutingError do
128
- asset_path("logo.png")
129
- end
130
- @config.asset_host = method :compute_host
131
- assert_raises ActionController::RoutingError do
132
- asset_path("logo.png")
133
- end
134
- end
135
-
136
- test "image_tag" do
137
- assert_dom_equal '<img alt="Xml" src="/assets/xml.png" />', image_tag("xml.png")
138
- end
139
-
140
- test "image_path" do
141
- assert_match %r{/assets/logo-[0-9a-f]+.png},
142
- image_path("logo.png")
143
-
144
- assert_match %r{/assets/logo-[0-9a-f]+.png},
145
- path_to_image("logo.png")
146
- end
147
-
148
- test "font_path" do
149
- assert_match %r{/assets/font-[0-9a-f]+.ttf},
150
- font_path("font.ttf")
151
-
152
- assert_match %r{/assets/font-[0-9a-f]+.ttf},
153
- path_to_font("font.ttf")
154
- end
155
-
156
- test "javascript_path" do
157
- assert_match %r{/assets/application-[0-9a-f]+.js},
158
- javascript_path("application")
159
-
160
- assert_match %r{/assets/application-[0-9a-f]+.js},
161
- javascript_path("application.js")
162
-
163
- assert_match %r{/assets/application-[0-9a-f]+.js},
164
- path_to_javascript("application.js")
165
- end
166
-
167
- test "stylesheet_path" do
168
- assert_match %r{/assets/application-[0-9a-f]+.css},
169
- stylesheet_path("application")
170
-
171
- assert_match %r{/assets/application-[0-9a-f]+.css},
172
- stylesheet_path("application.css")
173
-
174
- assert_match %r{/assets/application-[0-9a-f]+.css},
175
- path_to_stylesheet("application.css")
176
- end
177
-
178
- test "stylesheets served without a controller in do not use asset hosts when the default protocol is :request" do
179
- @controller = nil
180
- @config.asset_host = "assets-%d.example.com"
181
- @config.default_asset_host_protocol = :request
182
- @config.perform_caching = true
183
-
184
- assert_match %r{/assets/logo-[0-9a-f]+.png},
185
- asset_path("logo.png")
186
- end
187
-
188
- test "asset path with relative url root" do
189
- @controller.config.relative_url_root = "/collaboration/hieraki"
190
- assert_equal "/collaboration/hieraki/images/logo.gif",
191
- asset_path("/images/logo.gif")
192
- end
193
-
194
- test "asset path with relative url root when controller isn't present but relative_url_root is" do
195
- @controller = nil
196
- @config.relative_url_root = "/collaboration/hieraki"
197
- assert_equal "/collaboration/hieraki/images/logo.gif",
198
- asset_path("/images/logo.gif")
199
- end
200
-
201
- test "font path through asset_path" do
202
- assert_match %r{/assets/font-[0-9a-f]+.ttf},
203
- asset_path('font.ttf')
204
-
205
- assert_match %r{/assets/dir/font-[0-9a-f]+.ttf},
206
- asset_path("dir/font.ttf")
207
-
208
- assert_equal "http://www.example.com/fonts/font.ttf",
209
- asset_path("http://www.example.com/fonts/font.ttf")
210
- end
211
-
212
- test "javascript path through asset_path" do
213
- assert_match %r{/assets/application-[0-9a-f]+.js},
214
- asset_path(:application, :ext => "js")
215
-
216
- assert_match %r{/assets/xmlhr-[0-9a-f]+.js},
217
- asset_path("xmlhr", :ext => "js")
218
- assert_match %r{/assets/dir/xmlhr-[0-9a-f]+.js},
219
- asset_path("dir/xmlhr.js", :ext => "js")
220
-
221
- assert_equal "/dir/xmlhr.js",
222
- asset_path("/dir/xmlhr", :ext => "js")
223
-
224
- assert_equal "http://www.example.com/js/xmlhr",
225
- asset_path("http://www.example.com/js/xmlhr", :ext => "js")
226
- assert_equal "http://www.example.com/js/xmlhr.js",
227
- asset_path("http://www.example.com/js/xmlhr.js", :ext => "js")
228
- end
229
-
230
- test "javascript include tag" do
231
- assert_match %r{<script src="/assets/application-[0-9a-f]+.js" type="text/javascript"></script>},
232
- javascript_include_tag(:application)
233
- assert_match %r{<script src="/assets/application-[0-9a-f]+.js" type="text/javascript"></script>},
234
- javascript_include_tag(:application, :digest => true)
235
- assert_match %r{<script src="/assets/application.js" type="text/javascript"></script>},
236
- javascript_include_tag(:application, :digest => false)
237
-
238
- assert_match %r{<script src="/assets/xmlhr-[0-9a-f]+.js" type="text/javascript"></script>},
239
- javascript_include_tag("xmlhr")
240
- assert_match %r{<script src="/assets/xmlhr-[0-9a-f]+.js" type="text/javascript"></script>},
241
- javascript_include_tag("xmlhr.js")
242
- assert_equal '<script src="http://www.example.com/xmlhr" type="text/javascript"></script>',
243
- javascript_include_tag("http://www.example.com/xmlhr")
244
-
245
- assert_match %r{<script src=\"/assets/xmlhr-[0-9a-f]+.js" type=\"text/javascript\"></script>\n<script src=\"/assets/extra-[0-9a-f]+.js" type=\"text/javascript\"></script>},
246
- javascript_include_tag("xmlhr", "extra")
247
-
248
- assert_match %r{<script src="/assets/xmlhr-[0-9a-f]+.js\?body=1" type="text/javascript"></script>\n<script src="/assets/application-[0-9a-f]+.js\?body=1" type="text/javascript"></script>},
249
- javascript_include_tag(:application, :debug => true)
250
-
251
- assert_match %r{<script src="/assets/jquery.plugin.js" type="text/javascript"></script>},
252
- javascript_include_tag('jquery.plugin', :digest => false)
253
-
254
- @config.assets.compile = true
255
- @config.assets.debug = true
256
- assert_match %r{<script src="/javascripts/application.js" type="text/javascript"></script>},
257
- javascript_include_tag('/javascripts/application')
258
- assert_match %r{<script src="/assets/xmlhr-[0-9a-f]+.js\?body=1" type="text/javascript"></script>\n<script src="/assets/application-[0-9a-f]+.js\?body=1" type="text/javascript"></script>},
259
- javascript_include_tag(:application)
260
- end
261
-
262
- test "stylesheet path through asset_path" do
263
- assert_match %r{/assets/application-[0-9a-f]+.css}, asset_path(:application, :ext => "css")
264
-
265
- assert_match %r{/assets/style-[0-9a-f]+.css}, asset_path("style", :ext => "css")
266
- assert_match %r{/assets/dir/style-[0-9a-f]+.css}, asset_path("dir/style.css", :ext => "css")
267
- assert_equal "/dir/style.css", asset_path("/dir/style.css", :ext => "css")
268
-
269
- assert_equal "http://www.example.com/css/style",
270
- asset_path("http://www.example.com/css/style", :ext => "css")
271
- assert_equal "http://www.example.com/css/style.css",
272
- asset_path("http://www.example.com/css/style.css", :ext => "css")
273
- end
274
-
275
- test "stylesheet link tag" do
276
- assert_match %r{<link href="/assets/application-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />},
277
- stylesheet_link_tag(:application)
278
- assert_match %r{<link href="/assets/application-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />},
279
- stylesheet_link_tag(:application, :digest => true)
280
- assert_match %r{<link href="/assets/application.css" media="screen" rel="stylesheet" type="text/css" />},
281
- stylesheet_link_tag(:application, :digest => false)
282
-
283
- assert_match %r{<link href="/assets/style-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />},
284
- stylesheet_link_tag("style")
285
- assert_match %r{<link href="/assets/style-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />},
286
- stylesheet_link_tag("style.css")
287
-
288
- assert_equal '<link href="http://www.example.com/style.css" media="screen" rel="stylesheet" type="text/css" />',
289
- stylesheet_link_tag("http://www.example.com/style.css")
290
- assert_match %r{<link href="/assets/style-[0-9a-f]+.css" media="all" rel="stylesheet" type="text/css" />},
291
- stylesheet_link_tag("style", :media => "all")
292
- assert_match %r{<link href="/assets/style-[0-9a-f]+.css" media="print" rel="stylesheet" type="text/css" />},
293
- stylesheet_link_tag("style", :media => "print")
294
-
295
- assert_match %r{<link href="/assets/style-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/assets/extra-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />},
296
- stylesheet_link_tag("style", "extra")
297
-
298
- assert_match %r{<link href="/assets/style-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />\n<link href="/assets/application-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />},
299
- stylesheet_link_tag(:application, :debug => true)
300
-
301
- @config.assets.compile = true
302
- @config.assets.debug = true
303
- assert_match %r{<link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />},
304
- stylesheet_link_tag('/stylesheets/application')
305
-
306
- assert_match %r{<link href="/assets/style-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />\n<link href="/assets/application-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />},
307
- stylesheet_link_tag(:application)
308
-
309
- assert_match %r{<link href="/assets/style-[0-9a-f]+.css\?body=1" media="print" rel="stylesheet" type="text/css" />\n<link href="/assets/application-[0-9a-f]+.css\?body=1" media="print" rel="stylesheet" type="text/css" />},
310
- stylesheet_link_tag(:application, :media => "print")
311
- end
312
-
313
- test "alternate asset prefix" do
314
- stubs(:asset_prefix).returns("/themes/test")
315
- assert_match %r{/themes/test/style-[0-9a-f]+.css}, asset_path("style", :ext => "css")
316
- end
317
-
318
- test "alternate asset environment" do
319
- assets = Sprockets::Environment.new
320
- assets.append_path(FIXTURES.join("alternate/stylesheets"))
321
- stubs(:asset_environment).returns(assets)
322
- assert_match %r{/assets/style-[0-9a-f]+.css}, asset_path("style", :ext => "css")
323
- end
324
-
325
- test "alternate hash based on environment" do
326
- assets = Sprockets::Environment.new
327
- assets.version = 'development'
328
- assets.append_path(FIXTURES.join("alternate/stylesheets"))
329
- stubs(:asset_environment).returns(assets)
330
- dev_path = asset_path("style", :ext => "css")
331
-
332
- assets.version = 'production'
333
- prod_path = asset_path("style", :ext => "css")
334
-
335
- assert_not_equal prod_path, dev_path
336
- end
337
-
338
- test "precedence of `config.digest = false` over manifest.yml asset digests" do
339
- Rails.application.config.assets.digests = {'logo.png' => 'logo-d1g3st.png'}
340
- @config.assets.digest = false
341
-
342
- assert_equal '/assets/logo.png',
343
- asset_path("logo.png")
344
- end
345
- end
@@ -1,60 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
-
3
- class SprocketsHelperWithRoutesTest < ActiveSupport::TestCase
4
- include Sprockets::Rails::Helpers::RailsHelper
5
-
6
- attr_accessor :controller, :params
7
-
8
- # Let's bring in some named routes to test namespace conflicts with potential *_paths.
9
- # We have to do this after we bring in the Sprockets RailsHelper so if there are conflicts,
10
- # they'll fail in the way we expect in a real live Rails app.
11
- routes = ActionDispatch::Routing::RouteSet.new
12
- routes.draw do
13
- resources :assets
14
- end
15
- include routes.url_helpers
16
-
17
- def setup
18
- @controller = BasicController.new
19
-
20
- @assets = Sprockets::Environment.new
21
- @assets.append_path(FIXTURES.join("app/javascripts"))
22
- @assets.append_path(FIXTURES.join("app/stylesheets"))
23
- @assets.append_path(FIXTURES.join("app/images"))
24
-
25
- application = Struct.new(:config, :assets).new(config, @assets)
26
- ::Rails.stubs(:application).returns(application)
27
- @config = config
28
- @config.perform_caching = true
29
- @config.assets.digest = true
30
- @config.assets.compile = true
31
- @params = {}
32
- end
33
-
34
- def config
35
- @controller ? @controller.config : @config
36
- end
37
-
38
- test "namespace conflicts on a named route called asset_path" do
39
- # Testing this for sanity - asset_path is now a named route!
40
- assert_equal asset_path('test_asset'), '/assets/test_asset'
41
-
42
- assert_match %r{/assets/logo-[0-9a-f]+.png},
43
- path_to_asset("logo.png")
44
- assert_match %r{/assets/logo-[0-9a-f]+.png},
45
- path_to_asset("logo.png", :digest => true)
46
- assert_match %r{/assets/logo.png},
47
- path_to_asset("logo.png", :digest => false)
48
- end
49
-
50
- test "javascript_include_tag with a named_route named asset_path" do
51
- assert_match %r{<script src="/assets/application-[0-9a-f]+.js" type="text/javascript"></script>},
52
- javascript_include_tag(:application)
53
- end
54
-
55
- test "stylesheet_link_tag with a named_route named asset_path" do
56
- assert_match %r{<link href="/assets/application-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />},
57
- stylesheet_link_tag(:application)
58
- end
59
-
60
- end