sprockets-helpers 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -0
- data/lib/sprockets/helpers.rb +16 -5
- data/lib/sprockets/helpers/version.rb +1 -1
- data/spec/sprockets-helpers_spec.rb +86 -17
- metadata +4 -4
data/README.md
CHANGED
@@ -43,6 +43,11 @@ class App < Sinatra::Base
|
|
43
43
|
config.prefix = assets_prefix
|
44
44
|
config.digest = digest_assets
|
45
45
|
config.public_path = public_folder
|
46
|
+
|
47
|
+
# Force to debug mode in development mode
|
48
|
+
# Debug mode automatically sets
|
49
|
+
# expand = true, digest = false, manifest = false
|
50
|
+
config.debug = true if development?
|
46
51
|
end
|
47
52
|
end
|
48
53
|
|
data/lib/sprockets/helpers.rb
CHANGED
@@ -18,6 +18,13 @@ module Sprockets
|
|
18
18
|
# When true, expand assets.
|
19
19
|
attr_accessor :expand
|
20
20
|
|
21
|
+
# When true, force debug mode
|
22
|
+
# :debug => true equals
|
23
|
+
# :expand => true
|
24
|
+
# :digest => false
|
25
|
+
# :manifest => false
|
26
|
+
attr_accessor :debug
|
27
|
+
|
21
28
|
# Set the Sprockets environment to search for assets.
|
22
29
|
# This defaults to the context's #environment method.
|
23
30
|
attr_accessor :environment
|
@@ -114,7 +121,7 @@ module Sprockets
|
|
114
121
|
uri = URI.parse(source)
|
115
122
|
return source if uri.absolute?
|
116
123
|
|
117
|
-
if options[:debug]
|
124
|
+
if Helpers.debug || options[:debug]
|
118
125
|
options[:manifest] = false
|
119
126
|
options[:digest] = false
|
120
127
|
options[:asset_host] = false
|
@@ -136,13 +143,17 @@ module Sprockets
|
|
136
143
|
|
137
144
|
def asset_tag(source, options = {}, &block)
|
138
145
|
raise ::ArgumentError, 'block missing' unless block
|
139
|
-
options = { :expand => Helpers.expand }.merge(options)
|
140
|
-
|
141
|
-
|
142
|
-
|
146
|
+
options = { :expand => Helpers.debug || Helpers.expand, :debug => Helpers.debug }.merge(options)
|
147
|
+
|
148
|
+
path = asset_path(source, options)
|
149
|
+
output = if options[:expand] && path.respond_to?(:map)
|
150
|
+
path.map(&block).join("\n")
|
143
151
|
else
|
144
152
|
yield path
|
145
153
|
end
|
154
|
+
|
155
|
+
output = output.html_safe if output.respond_to?(:html_safe)
|
156
|
+
output
|
146
157
|
end
|
147
158
|
|
148
159
|
def javascript_tag(source, options = {})
|
@@ -284,24 +284,49 @@ describe Sprockets::Helpers do
|
|
284
284
|
end
|
285
285
|
|
286
286
|
context 'when debuging' do
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
287
|
+
context 'when set individually' do
|
288
|
+
it 'does not read the path from the manifest file' do
|
289
|
+
within_construct do |c|
|
290
|
+
asset_file = c.file 'assets/application.js'
|
291
|
+
manifest_file = c.join 'manifest.json'
|
292
|
+
|
293
|
+
manifest = Sprockets::Manifest.new(env, manifest_file)
|
294
|
+
manifest.compile 'application.js'
|
295
|
+
|
296
|
+
Sprockets::Helpers.configure do |config|
|
297
|
+
config.digest = true
|
298
|
+
config.prefix = '/assets'
|
299
|
+
config.manifest = Sprockets::Manifest.new(env, manifest_file)
|
300
|
+
end
|
301
|
+
|
302
|
+
expect(context.asset_path('application.js', :debug => true)).to eq('/assets/application.js')
|
303
|
+
|
304
|
+
Sprockets::Helpers.digest = nil
|
305
|
+
Sprockets::Helpers.prefix = nil
|
299
306
|
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
context 'when set globally' do
|
311
|
+
it 'does not read the path from the manifest file' do
|
312
|
+
within_construct do |c|
|
313
|
+
asset_file = c.file 'assets/application.js'
|
314
|
+
manifest_file = c.join 'manifest.json'
|
315
|
+
|
316
|
+
manifest = Sprockets::Manifest.new(env, manifest_file)
|
317
|
+
manifest.compile 'application.js'
|
318
|
+
|
319
|
+
Sprockets::Helpers.debug = true
|
320
|
+
Sprockets::Helpers.configure do |config|
|
321
|
+
config.prefix = '/assets'
|
322
|
+
config.manifest = Sprockets::Manifest.new(env, manifest_file)
|
323
|
+
end
|
300
324
|
|
301
|
-
|
325
|
+
expect(context.asset_path('application.js')).to eq('/assets/application.js')
|
302
326
|
|
303
|
-
|
304
|
-
|
327
|
+
Sprockets::Helpers.debug = nil
|
328
|
+
Sprockets::Helpers.prefix = nil
|
329
|
+
end
|
305
330
|
end
|
306
331
|
end
|
307
332
|
end
|
@@ -385,10 +410,24 @@ describe Sprockets::Helpers do
|
|
385
410
|
Sprockets::Helpers.expand = true
|
386
411
|
c = context
|
387
412
|
c.stub(:asset_path).and_return(context.asset_path('main.js')) # Spy
|
388
|
-
c.should_receive(:asset_path).with('main.js', {:expand => true})
|
413
|
+
c.should_receive(:asset_path).with('main.js', {:expand => true, :debug => nil})
|
389
414
|
c.asset_tag('main.js') {}
|
390
415
|
Sprockets::Helpers.expand = false
|
391
|
-
c.should_receive(:asset_path).with('main.js', {:expand => false})
|
416
|
+
c.should_receive(:asset_path).with('main.js', {:expand => false, :debug => nil})
|
417
|
+
c.asset_tag('main.js') {}
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
it 'force to be debug mode when globally configured' do
|
422
|
+
within_construct do |construct|
|
423
|
+
assets_layout(construct)
|
424
|
+
Sprockets::Helpers.debug = true
|
425
|
+
c = context
|
426
|
+
c.stub(:asset_path).and_return(context.asset_path('main.js')) # Spy
|
427
|
+
c.should_receive(:asset_path).with('main.js', {:expand => true, :debug => true})
|
428
|
+
c.asset_tag('main.js') {}
|
429
|
+
Sprockets::Helpers.debug = false
|
430
|
+
c.should_receive(:asset_path).with('main.js', {:expand => false, :debug => false})
|
392
431
|
c.asset_tag('main.js') {}
|
393
432
|
end
|
394
433
|
end
|
@@ -410,7 +449,37 @@ describe Sprockets::Helpers do
|
|
410
449
|
expect(tags).to include('<script src="/assets/b.js?body=1"></script>')
|
411
450
|
end
|
412
451
|
end
|
452
|
+
end
|
453
|
+
|
454
|
+
if defined?(Sprockets::Manifest)
|
455
|
+
describe 'when globally debug mode is set' do
|
456
|
+
it 'generates tag for each asset without reading the path from manifest file' do
|
457
|
+
within_construct do |construct|
|
458
|
+
assets_layout(construct)
|
459
|
+
manifest_file = construct.join 'manifest.json'
|
460
|
+
|
461
|
+
manifest = Sprockets::Manifest.new(env, manifest_file)
|
462
|
+
manifest.compile 'main.js'
|
463
|
+
Sprockets::Helpers.debug = true
|
464
|
+
Sprockets::Helpers.configure do |config|
|
465
|
+
config.prefix = '/assets'
|
466
|
+
config.manifest = Sprockets::Manifest.new(env, manifest_file)
|
467
|
+
end
|
468
|
+
|
469
|
+
tags = context.asset_tag('main.js') do |path|
|
470
|
+
"<script src=\"#{path}\"></script>"
|
471
|
+
end
|
472
|
+
expect(tags.split('</script>')).to have(3).scripts
|
473
|
+
expect(tags).to include('<script src="/assets/main.js?body=1"></script>')
|
474
|
+
expect(tags).to include('<script src="/assets/a.js?body=1"></script>')
|
475
|
+
expect(tags).to include('<script src="/assets/b.js?body=1"></script>')
|
413
476
|
|
477
|
+
Sprockets::Helpers.debug = false
|
478
|
+
Sprockets::Helpers.prefix = nil
|
479
|
+
Sprockets::Helpers.manifest = nil
|
480
|
+
end
|
481
|
+
end
|
482
|
+
end
|
414
483
|
end
|
415
484
|
end
|
416
485
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sprockets
|
@@ -156,7 +156,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
156
156
|
version: '0'
|
157
157
|
segments:
|
158
158
|
- 0
|
159
|
-
hash:
|
159
|
+
hash: 1829303642401758750
|
160
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
161
|
none: false
|
162
162
|
requirements:
|
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
165
|
version: '0'
|
166
166
|
segments:
|
167
167
|
- 0
|
168
|
-
hash:
|
168
|
+
hash: 1829303642401758750
|
169
169
|
requirements: []
|
170
170
|
rubyforge_project: sprockets-helpers
|
171
171
|
rubygems_version: 1.8.23
|