dynamic_assets 0.3.1 → 0.4.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/app/helpers/dynamic_assets_helpers.rb +5 -5
- data/config/routes.rb +14 -6
- data/spec/helpers/dynamic_assets_helpers_spec.rb +18 -18
- data/spec/spec_helper.rb +1 -0
- metadata +5 -5
@@ -29,11 +29,13 @@ module DynamicAssetsHelpers
|
|
29
29
|
protected
|
30
30
|
|
31
31
|
def asset_path(asset_ref)
|
32
|
-
|
32
|
+
path_args = []
|
33
|
+
path_args << asset_ref.name
|
34
|
+
path_args << { :timestamp => asset_ref.mtime.to_i.to_s } if asset_ref.mtime.present?
|
33
35
|
|
34
36
|
case asset_ref
|
35
|
-
when DynamicAssets::StylesheetReference then stylesheet_asset_path
|
36
|
-
when DynamicAssets::JavascriptReference then javascript_asset_path
|
37
|
+
when DynamicAssets::StylesheetReference then stylesheet_asset_path *path_args
|
38
|
+
when DynamicAssets::JavascriptReference then javascript_asset_path *path_args
|
37
39
|
else raise "Unknown asset type: #{asset_ref}"
|
38
40
|
end
|
39
41
|
end
|
@@ -41,10 +43,8 @@ module DynamicAssetsHelpers
|
|
41
43
|
def asset_url(asset_ref)
|
42
44
|
path = asset_path asset_ref
|
43
45
|
path = "/" + path unless path[0,1] == "/"
|
44
|
-
path << "?#{asset_ref.mtime.to_i.to_s}" if asset_ref.mtime.present?
|
45
46
|
|
46
47
|
host = compute_asset_host path
|
47
|
-
|
48
48
|
host ? "#{host}#{path}" : path
|
49
49
|
end
|
50
50
|
|
data/config/routes.rb
CHANGED
@@ -1,12 +1,20 @@
|
|
1
1
|
|
2
2
|
Rails.application.routes.draw do
|
3
3
|
|
4
|
-
match '/assets/javascripts/:name
|
5
|
-
:
|
6
|
-
:
|
4
|
+
match '/assets/javascripts(/:timestamp)/:name.:format' => 'assets#show_javascript',
|
5
|
+
:as => :javascript_asset,
|
6
|
+
:format => "js", # Important for action-caching non-HTML resources
|
7
|
+
:constraints => {
|
8
|
+
:name => /[^ ]+/, # By default, route segments can't have dots. We allow all but space.
|
9
|
+
:timestamp => /\d+/
|
10
|
+
}
|
7
11
|
|
8
|
-
match '/assets/stylesheets/:name
|
9
|
-
:
|
10
|
-
:
|
12
|
+
match '/assets/stylesheets(/:timestamp)/:name.:format' => 'assets#show_stylesheet',
|
13
|
+
:as => :stylesheet_asset,
|
14
|
+
:format => "css", # Important for action-caching non-HTML resources
|
15
|
+
:constraints => { # By default, segments can't have dots. We allow all but space.
|
16
|
+
:name => /[^ ]+/,
|
17
|
+
:timestamp => /\d+/
|
18
|
+
}
|
11
19
|
|
12
20
|
end
|
@@ -57,9 +57,9 @@ describe DynamicAssetsHelpers do
|
|
57
57
|
before { helper.config.asset_host.should be_nil }
|
58
58
|
|
59
59
|
it "is three tags with hrefs derived from the asset name and mtime" do
|
60
|
-
should contain_string 'href="/assets/stylesheets/a.css
|
61
|
-
should contain_string 'href="/assets/stylesheets/b.css
|
62
|
-
should contain_string 'href="/assets/stylesheets/c.css
|
60
|
+
should contain_string 'href="/assets/stylesheets/123/a.css"'
|
61
|
+
should contain_string 'href="/assets/stylesheets/456/b.css"'
|
62
|
+
should contain_string 'href="/assets/stylesheets/789/c.css"'
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -67,9 +67,9 @@ describe DynamicAssetsHelpers do
|
|
67
67
|
before { helper.config.stub(:asset_host).and_return "http://a.example.com" }
|
68
68
|
|
69
69
|
it "is three tags with hrefs whose host is a.example.com" do
|
70
|
-
should contain_string 'href="http://a.example.com/assets/stylesheets/a.css
|
71
|
-
should contain_string 'href="http://a.example.com/assets/stylesheets/b.css
|
72
|
-
should contain_string 'href="http://a.example.com/assets/stylesheets/c.css
|
70
|
+
should contain_string 'href="http://a.example.com/assets/stylesheets/123/a.css"'
|
71
|
+
should contain_string 'href="http://a.example.com/assets/stylesheets/456/b.css"'
|
72
|
+
should contain_string 'href="http://a.example.com/assets/stylesheets/789/c.css"'
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -77,9 +77,9 @@ describe DynamicAssetsHelpers do
|
|
77
77
|
before { helper.config.stub(:asset_host).and_return "http://a%d.example.com" }
|
78
78
|
|
79
79
|
it "is three tags with hrefs whose host is a[0-3].example.com" do
|
80
|
-
should =~ /href="http:\/\/a[0-3].example.com\/assets\/stylesheets\/a.css
|
81
|
-
should =~ /href="http:\/\/a[0-3].example.com\/assets\/stylesheets\/b.css
|
82
|
-
should =~ /href="http:\/\/a[0-3].example.com\/assets\/stylesheets\/c.css
|
80
|
+
should =~ /href="http:\/\/a[0-3].example.com\/assets\/stylesheets\/123\/a.css"/
|
81
|
+
should =~ /href="http:\/\/a[0-3].example.com\/assets\/stylesheets\/456\/b.css"/
|
82
|
+
should =~ /href="http:\/\/a[0-3].example.com\/assets\/stylesheets\/789\/c.css"/
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
@@ -132,9 +132,9 @@ describe DynamicAssetsHelpers do
|
|
132
132
|
before { helper.config.asset_host.should be_nil }
|
133
133
|
|
134
134
|
it "is three tags with srcs derived from the asset name and mtime" do
|
135
|
-
should contain_string 'src="/assets/javascripts/a.js
|
136
|
-
should contain_string 'src="/assets/javascripts/b.js
|
137
|
-
should contain_string 'src="/assets/javascripts/c.js
|
135
|
+
should contain_string 'src="/assets/javascripts/123/a.js"'
|
136
|
+
should contain_string 'src="/assets/javascripts/456/b.js"'
|
137
|
+
should contain_string 'src="/assets/javascripts/789/c.js"'
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
@@ -142,9 +142,9 @@ describe DynamicAssetsHelpers do
|
|
142
142
|
before { helper.config.stub(:asset_host).and_return "http://a.example.com" }
|
143
143
|
|
144
144
|
it "is three tags with srcs whose host is a.example.com" do
|
145
|
-
should contain_string 'src="http://a.example.com/assets/javascripts/a.js
|
146
|
-
should contain_string 'src="http://a.example.com/assets/javascripts/b.js
|
147
|
-
should contain_string 'src="http://a.example.com/assets/javascripts/c.js
|
145
|
+
should contain_string 'src="http://a.example.com/assets/javascripts/123/a.js"'
|
146
|
+
should contain_string 'src="http://a.example.com/assets/javascripts/456/b.js"'
|
147
|
+
should contain_string 'src="http://a.example.com/assets/javascripts/789/c.js"'
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
@@ -152,9 +152,9 @@ describe DynamicAssetsHelpers do
|
|
152
152
|
before { helper.config.stub(:asset_host).and_return "http://a%d.example.com" }
|
153
153
|
|
154
154
|
it "is three tags with srcs whose host is a[0-3].example.com" do
|
155
|
-
should =~ /src="http:\/\/a[0-3].example.com\/assets\/javascripts\/a.js
|
156
|
-
should =~ /src="http:\/\/a[0-3].example.com\/assets\/javascripts\/b.js
|
157
|
-
should =~ /src="http:\/\/a[0-3].example.com\/assets\/javascripts\/c.js
|
155
|
+
should =~ /src="http:\/\/a[0-3].example.com\/assets\/javascripts\/123\/a.js"/
|
156
|
+
should =~ /src="http:\/\/a[0-3].example.com\/assets\/javascripts\/456\/b.js"/
|
157
|
+
should =~ /src="http:\/\/a[0-3].example.com\/assets\/javascripts\/789\/c.js"/
|
158
158
|
end
|
159
159
|
end
|
160
160
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamic_assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Robert Davis
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-04-
|
18
|
+
date: 2011-04-27 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|