rails2_asset_pipeline 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/Readme.md +9 -3
- data/lib/rails2_asset_pipeline/version.rb +1 -1
- data/lib/rails2_asset_pipeline/view_helpers.rb +15 -1
- data/spec/rails2_asset_pipeline/view_helpers_spec.rb +56 -15
- data/spec/spec_helper.rb +1 -0
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
@@ -7,7 +7,7 @@ Familiar asset handling for those stuck on Rails 2.
|
|
7
7
|
- application-MD5.js for production (and development without config.ru)
|
8
8
|
- old asset versions can stay around during deploys
|
9
9
|
- converter for jammit asset.yml
|
10
|
-
- no monkey-patching, everything is opt-in
|
10
|
+
- no forced monkey-patching, everything is opt-in
|
11
11
|
|
12
12
|
[Example application](https://github.com/grosser/rails2_asset_pipeline_exmaple)
|
13
13
|
|
@@ -21,8 +21,11 @@ rake assets:convert_jammit # reads config/assets.yml and converts packs into `a
|
|
21
21
|
```
|
22
22
|
|
23
23
|
```Erb
|
24
|
-
|
25
|
-
<%=
|
24
|
+
With ViewHelpers included you can:
|
25
|
+
<%= stylesheet_link_tag "application" %>
|
26
|
+
<%= javascript_include_tag "application" %>
|
27
|
+
From good old public <%= javascript_include_tag "/javascripts/application.js" %>
|
28
|
+
Just a path: <%= asset_path "application.js" %>
|
26
29
|
```
|
27
30
|
|
28
31
|
|
@@ -80,6 +83,9 @@ module ApplicationHelper
|
|
80
83
|
end
|
81
84
|
```
|
82
85
|
|
86
|
+
### Static code
|
87
|
+
You can also use `Rails2AssetPipeline::ViewHelpers.asset_path("application.js")`
|
88
|
+
|
83
89
|
### Sass
|
84
90
|
- add `sass` to your gems for sass parsing
|
85
91
|
- add `sprockets-sass` to your gems for sass @import support
|
@@ -1,6 +1,19 @@
|
|
1
1
|
module Rails2AssetPipeline
|
2
2
|
module ViewHelpers
|
3
|
-
|
3
|
+
# Overwrite rails helper to use pipeline path for all relative assets
|
4
|
+
# args: source, 'javascripts', 'js'
|
5
|
+
def compute_public_path(*args)
|
6
|
+
source = args[0]
|
7
|
+
source_is_relative = (source.is_a?(String) and source =~ /^[a-z]+(\/|\.|$)/) # xxx or xxx.js or xxx/yyy, not /xxx or http://
|
8
|
+
if source_is_relative
|
9
|
+
source = "#{source}.#{args[2]}" unless source.include?(".")
|
10
|
+
super(asset_path(source), *args[1..-1])
|
11
|
+
else
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def asset_path(asset)
|
4
17
|
data = Rails2AssetPipeline.env[asset]
|
5
18
|
return "/assets/NOT_FOUND" unless data
|
6
19
|
asset = "/assets/#{asset}"
|
@@ -11,5 +24,6 @@ module Rails2AssetPipeline
|
|
11
24
|
"#{asset}?#{data.mtime.to_i}"
|
12
25
|
end
|
13
26
|
end
|
27
|
+
module_function :asset_path
|
14
28
|
end
|
15
29
|
end
|
@@ -1,33 +1,41 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Rails2AssetPipeline::ViewHelpers do
|
4
|
+
module FakeSuper
|
5
|
+
def compute_public_path(*args)
|
6
|
+
@compute_public_path = args
|
7
|
+
:super
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
include FakeSuper
|
4
12
|
include Rails2AssetPipeline::ViewHelpers
|
5
13
|
|
6
|
-
|
7
|
-
let(:env){ {} }
|
14
|
+
let(:env){ {} }
|
8
15
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
16
|
+
before do
|
17
|
+
Rails2AssetPipeline.stub(:env).and_return env
|
18
|
+
Rails2AssetPipeline.dynamic_assets_available = true
|
19
|
+
env["xxx.js"] = mock(:digest => "abc", :mtime => Time.at(123456))
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#asset" do
|
23
|
+
it "is also static" do
|
24
|
+
Rails2AssetPipeline::ViewHelpers.asset_path("xxx.js").should_not == nil
|
13
25
|
end
|
14
26
|
|
15
27
|
it "silently fails with unfound assets" do
|
16
|
-
|
28
|
+
asset_path("yyy.js").should == "/assets/NOT_FOUND"
|
17
29
|
end
|
18
30
|
|
19
31
|
context "development" do
|
20
|
-
before do
|
21
|
-
Rails.env = "development"
|
22
|
-
end
|
23
|
-
|
24
32
|
it "returns a path with query" do
|
25
|
-
|
33
|
+
asset_path("xxx.js").should == "/assets/xxx.js?123456"
|
26
34
|
end
|
27
35
|
|
28
36
|
it "returns a path with digest when dynamic loader is not available" do
|
29
37
|
Rails2AssetPipeline.dynamic_assets_available = false
|
30
|
-
|
38
|
+
asset_path("xxx.js").should == "/assets/xxx-abc.js"
|
31
39
|
end
|
32
40
|
end
|
33
41
|
|
@@ -37,13 +45,46 @@ describe Rails2AssetPipeline::ViewHelpers do
|
|
37
45
|
end
|
38
46
|
|
39
47
|
it "returns a path with md5" do
|
40
|
-
|
48
|
+
asset_path("xxx.js").should == "/assets/xxx-abc.js"
|
41
49
|
end
|
42
50
|
|
43
51
|
it "returns a path with md5 on production and complicated file" do
|
44
52
|
env["xxx.yy.js"] = env["xxx.js"]
|
45
|
-
|
53
|
+
asset_path("xxx.yy.js").should == "/assets/xxx-abc.yy.js"
|
46
54
|
end
|
47
55
|
end
|
48
56
|
end
|
57
|
+
|
58
|
+
describe "#compute_public_path" do
|
59
|
+
it "does nothing for symbols" do
|
60
|
+
compute_public_path(:xxx, "a", "b").should == :super
|
61
|
+
@compute_public_path.should == [:xxx, "a", "b"]
|
62
|
+
end
|
63
|
+
|
64
|
+
it "does nothing for paths starting with /" do
|
65
|
+
compute_public_path("/xxx", "a", "b").should == :super
|
66
|
+
@compute_public_path.should == ["/xxx", "a", "b"]
|
67
|
+
end
|
68
|
+
|
69
|
+
it "does nothing for urls" do
|
70
|
+
compute_public_path("http://xxx", "a", "b").should == :super
|
71
|
+
@compute_public_path.should == ["http://xxx", "a", "b"]
|
72
|
+
end
|
73
|
+
|
74
|
+
it "converts relative, nested paths without extension" do
|
75
|
+
env["xxx/yyy.js"] = env["xxx.js"]
|
76
|
+
compute_public_path("xxx/yyy", "a", "js").should == :super
|
77
|
+
@compute_public_path.should == ["/assets/xxx/yyy.js?123456", "a", "js"]
|
78
|
+
end
|
79
|
+
|
80
|
+
it "converts relative paths with extension" do
|
81
|
+
compute_public_path("xxx.js", "a", "b").should == :super
|
82
|
+
@compute_public_path.should == ["/assets/xxx.js?123456", "a", "b"]
|
83
|
+
end
|
84
|
+
|
85
|
+
it "converts relative paths without extension" do
|
86
|
+
compute_public_path("xxx", "a", "js").should == :super
|
87
|
+
@compute_public_path.should == ["/assets/xxx.js?123456", "a", "js"]
|
88
|
+
end
|
89
|
+
end
|
49
90
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails2_asset_pipeline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
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: 2012-05-
|
12
|
+
date: 2012-05-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sprockets
|
@@ -67,7 +67,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
67
|
version: '0'
|
68
68
|
segments:
|
69
69
|
- 0
|
70
|
-
hash:
|
70
|
+
hash: 3123271431630063706
|
71
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
version: '0'
|
77
77
|
segments:
|
78
78
|
- 0
|
79
|
-
hash:
|
79
|
+
hash: 3123271431630063706
|
80
80
|
requirements: []
|
81
81
|
rubyforge_project:
|
82
82
|
rubygems_version: 1.8.24
|