jekyll-assets 0.7.7 → 0.7.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.rubocop.yml +30 -4
- data/.travis.yml +8 -1
- data/Gemfile +4 -0
- data/Gemfile.jekyll-1.0 +2 -0
- data/HISTORY.md +20 -0
- data/README.md +5 -0
- data/jekyll-assets.gemspec +6 -2
- data/lib/jekyll-assets.rb +1 -0
- data/lib/jekyll-assets/bootstrap.rb +1 -1
- data/lib/jekyll/assets_plugin/asset_path.rb +4 -2
- data/lib/jekyll/assets_plugin/configuration.rb +5 -5
- data/lib/jekyll/assets_plugin/filters.rb +1 -1
- data/lib/jekyll/assets_plugin/patches/processed_asset_patch.rb +2 -2
- data/lib/jekyll/assets_plugin/renderer.rb +1 -1
- data/lib/jekyll/assets_plugin/tag.rb +1 -1
- data/lib/jekyll/assets_plugin/version.rb +1 -1
- data/spec/lib/jekyll-assets/bootstrap_spec.rb +3 -5
- data/spec/lib/jekyll-assets/bourbon_spec.rb +3 -5
- data/spec/lib/jekyll-assets/compass_spec.rb +3 -5
- data/spec/lib/jekyll-assets/neat_spec.rb +3 -5
- data/spec/lib/jekyll/assets_plugin/configuration_spec.rb +125 -125
- data/spec/lib/jekyll/assets_plugin/environment_spec.rb +15 -13
- data/spec/lib/jekyll/assets_plugin/filters_spec.rb +75 -77
- data/spec/lib/jekyll/assets_plugin/patches/site_patch_spec.rb +130 -134
- data/spec/lib/jekyll/assets_plugin/renderer_spec.rb +32 -35
- data/spec/lib/jekyll/assets_plugin/tag_spec.rb +75 -77
- data/spec/spec_helper.rb +9 -4
- data/spec/support/fixtures_helpers.rb +7 -0
- metadata +89 -39
- checksums.yaml +0 -7
- data/spec/support/fixtures_path.rb +0 -11
@@ -1,19 +1,21 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
module Jekyll
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
module Jekyll
|
4
|
+
module AssetsPlugin
|
5
|
+
describe Environment do
|
6
|
+
context "#asset_path of context" do
|
7
|
+
it "should properly handle query params" do
|
8
|
+
css = @site.assets["vapor.css"].to_s
|
9
|
+
css.should match(/fonts\/vapor-[a-f0-9]{32}\.eot\?#iefix/)
|
10
|
+
css.should match(/fonts\/vapor-[a-f0-9]{32}\.svg#iefix/)
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
it "should properly handle relative paths" do
|
14
|
+
css = @site.assets["lib/relative.css"].to_s
|
15
|
+
css.should =~ %r{/assets/fonts/vapor-[a-f0-9]{32}\.eot\?#iefix}
|
16
|
+
css.should =~ %r{/assets/fonts/vapor-[a-f0-9]{32}\.svg#iefix}
|
17
|
+
puts css
|
18
|
+
end
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
@@ -1,105 +1,103 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
let(:context) { { :registers => { :site => @site } } }
|
3
|
+
describe Jekyll::AssetsPlugin::Filters do
|
4
|
+
let(:context) { { :registers => { :site => @site } } }
|
6
5
|
|
7
|
-
|
8
|
-
|
6
|
+
def render(content)
|
7
|
+
::Liquid::Template.parse(content).render({}, context)
|
8
|
+
end
|
9
|
+
|
10
|
+
context "{{ '<file>' | image }}" do
|
11
|
+
def tag_re(name)
|
12
|
+
file = "/assets/#{name}-[a-f0-9]{32}\.png"
|
13
|
+
Regexp.new "^#{Jekyll::AssetsPlugin::Renderer::IMAGE % file}$"
|
9
14
|
end
|
10
15
|
|
11
|
-
context "
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
+
context "when <file> exists" do
|
17
|
+
subject { render("{{ 'noise.png' | image }}") }
|
18
|
+
it { should match tag_re("noise") }
|
19
|
+
end
|
16
20
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
context "when <file> does not exists" do
|
22
|
+
subject { render("{{ 'not-found.png' | image }}") }
|
23
|
+
it { should match "Liquid error: Couldn't find file 'not-found.png'" }
|
24
|
+
end
|
25
|
+
end
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
27
|
+
context "{{ '<file>' | stylesheet }}" do
|
28
|
+
def tag_re(name)
|
29
|
+
file = "/assets/#{name}-[a-f0-9]{32}\.css"
|
30
|
+
Regexp.new "^#{Jekyll::AssetsPlugin::Renderer::STYLESHEET % file}$"
|
26
31
|
end
|
27
32
|
|
28
|
-
context "
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
+
context "when <file> exists" do
|
34
|
+
subject { render("{{ 'app.css' | stylesheet }}") }
|
35
|
+
it { should match tag_re("app") }
|
36
|
+
end
|
33
37
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
context "when <file> extension is omited" do
|
39
|
+
subject { render("{{ 'app' | stylesheet }}") }
|
40
|
+
it { should match tag_re("app") }
|
41
|
+
end
|
38
42
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
+
context "when <file> does not exists" do
|
44
|
+
subject { render("{{ 'not-found.css' | stylesheet }}") }
|
45
|
+
it { should match "Liquid error: Couldn't find file 'not-found.css'" }
|
46
|
+
end
|
47
|
+
end
|
43
48
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
49
|
+
context "{{ '<file>' | javascript }}" do
|
50
|
+
def tag_re(name)
|
51
|
+
file = "/assets/#{name}-[a-f0-9]{32}\.js"
|
52
|
+
Regexp.new "^#{Jekyll::AssetsPlugin::Renderer::JAVASCRIPT % file}$"
|
48
53
|
end
|
49
54
|
|
50
|
-
context "
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
55
|
+
context "when <file> exists" do
|
56
|
+
subject { render("{{ 'app.js' | javascript }}") }
|
57
|
+
it { should match tag_re("app") }
|
58
|
+
end
|
55
59
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
+
context "when <file> extension omited" do
|
61
|
+
subject { render("{{ 'app' | javascript }}") }
|
62
|
+
it { should match tag_re("app") }
|
63
|
+
end
|
60
64
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
+
context "when <file> does not exists" do
|
66
|
+
subject { render("{{ 'not-found.js' | javascript }}") }
|
67
|
+
it { should match "Liquid error: Couldn't find file 'not-found.js'" }
|
68
|
+
end
|
69
|
+
end
|
65
70
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
71
|
+
context "{{ '<file.ext>' | asset_path }}" do
|
72
|
+
context "when <file> exists" do
|
73
|
+
subject { render("{{ 'app.css' | asset_path }}") }
|
74
|
+
it { should match(%r{^/assets/app-[a-f0-9]{32}\.css$}) }
|
70
75
|
end
|
71
76
|
|
72
|
-
context "
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
77
|
+
context "when <file> does not exists" do
|
78
|
+
subject { render("{{ 'not-found.css' | asset_path }}") }
|
79
|
+
it { should match "Liquid error: Couldn't find file 'not-found.css'" }
|
80
|
+
end
|
77
81
|
|
78
|
-
|
79
|
-
|
80
|
-
|
82
|
+
context "with baseurl given as /foobar/" do
|
83
|
+
before do
|
84
|
+
context[:registers][:site].assets_config.baseurl = "/foobar/"
|
81
85
|
end
|
82
86
|
|
83
|
-
|
84
|
-
|
85
|
-
context[:registers][:site].assets_config.baseurl = "/foobar/"
|
86
|
-
end
|
87
|
-
|
88
|
-
subject { render("{{ 'app.css' | asset_path }}") }
|
89
|
-
it { should match(%r{^/foobar/app-[a-f0-9]{32}\.css$}) }
|
90
|
-
end
|
87
|
+
subject { render("{{ 'app.css' | asset_path }}") }
|
88
|
+
it { should match(%r{^/foobar/app-[a-f0-9]{32}\.css$}) }
|
91
89
|
end
|
90
|
+
end
|
92
91
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
92
|
+
context "{{ '<file.ext>' | asset }}" do
|
93
|
+
context "when <file> exists" do
|
94
|
+
subject { render("{{ 'app.css' | asset }}") }
|
95
|
+
it { should match(/body \{ background-image: url\(.+?\) \}/) }
|
96
|
+
end
|
98
97
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
98
|
+
context "when <file> does not exists" do
|
99
|
+
subject { render("{{ 'not-found.js' | asset }}") }
|
100
|
+
it { should match "Liquid error: Couldn't find file 'not-found.js'" }
|
103
101
|
end
|
104
102
|
end
|
105
103
|
end
|
@@ -1,172 +1,168 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
})
|
14
|
-
end
|
3
|
+
describe Jekyll::AssetsPlugin::Patches::SitePatch do
|
4
|
+
let(:site) do
|
5
|
+
Jekyll::Site.new Jekyll.configuration({
|
6
|
+
"source" => fixtures_path.to_s,
|
7
|
+
"dirname" => "foobar",
|
8
|
+
"assets" => {
|
9
|
+
"sources" => %w[foobar _assets]
|
10
|
+
}
|
11
|
+
})
|
12
|
+
end
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
context "#assets" do
|
15
|
+
subject { site.assets }
|
16
|
+
it { should be_a_kind_of ::Sprockets::Environment }
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
context "#cache_path" do
|
19
|
+
let(:source_path) { Pathname.new site.source }
|
20
|
+
subject { site.assets.cache_path }
|
23
21
|
|
24
|
-
|
25
|
-
|
22
|
+
it { should eq source_path.join(".jekyll-assets-cache") }
|
23
|
+
end
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "when requested file found" do
|
36
|
-
it "should have proper asset path" do
|
37
|
-
expect(site.assets["app.css"].to_s)
|
38
|
-
.to match(%r{url\(/assets/noise-[a-f0-9]{32}\.png\)})
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context "when passed a blank path" do
|
43
|
-
it "should be blank" do
|
44
|
-
expect(site.assets["should_be_blank.css"].to_s)
|
45
|
-
.to match(/url\(\)/)
|
46
|
-
end
|
47
|
-
end
|
25
|
+
context "calling #asset_path within assets" do
|
26
|
+
context "when requested file not found" do
|
27
|
+
it "raises a NotFound error" do
|
28
|
+
expect { site.assets["should_fail.css"] }
|
29
|
+
.to raise_error Jekyll::AssetsPlugin::Environment::AssetNotFound
|
48
30
|
end
|
49
31
|
end
|
50
32
|
|
51
|
-
context "
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
before { site.assets_config.cachebust = :none }
|
56
|
-
it { should match(%r{^/assets/app\.css$}) }
|
57
|
-
end
|
58
|
-
|
59
|
-
context "with soft cachebust" do
|
60
|
-
before { site.assets_config.cachebust = :soft }
|
61
|
-
it { should match(%r{^/assets/app\.css\?cb=[a-f0-9]{32}$}) }
|
33
|
+
context "when requested file found" do
|
34
|
+
it "should have proper asset path" do
|
35
|
+
expect(site.assets["app.css"].to_s)
|
36
|
+
.to match(%r{url\(/assets/noise-[a-f0-9]{32}\.png\)})
|
62
37
|
end
|
38
|
+
end
|
63
39
|
|
64
|
-
|
65
|
-
|
66
|
-
|
40
|
+
context "when passed a blank path" do
|
41
|
+
it "should be blank" do
|
42
|
+
expect(site.assets["should_be_blank.css"].to_s)
|
43
|
+
.to match(/url\(\)/)
|
67
44
|
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
68
48
|
|
69
|
-
|
70
|
-
|
71
|
-
it "should raise error" do
|
72
|
-
expect { site.asset_path "app.css" }.to raise_error
|
73
|
-
end
|
74
|
-
end
|
49
|
+
context "#asset_path" do
|
50
|
+
subject { site.asset_path "app.css" }
|
75
51
|
|
76
|
-
|
77
|
-
|
52
|
+
context "with none cachebust" do
|
53
|
+
before { site.assets_config.cachebust = :none }
|
54
|
+
it { should match(%r{^/assets/app\.css$}) }
|
55
|
+
end
|
78
56
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
57
|
+
context "with soft cachebust" do
|
58
|
+
before { site.assets_config.cachebust = :soft }
|
59
|
+
it { should match(%r{^/assets/app\.css\?cb=[a-f0-9]{32}$}) }
|
60
|
+
end
|
83
61
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
62
|
+
context "with hard cachebust" do
|
63
|
+
before { site.assets_config.cachebust = :hard }
|
64
|
+
it { should match(%r{^/assets/app-[a-f0-9]{32}\.css$}) }
|
65
|
+
end
|
88
66
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
67
|
+
context "with unknown cachebust" do
|
68
|
+
before { site.assets_config.cachebust = :wtf }
|
69
|
+
it "should raise error" do
|
70
|
+
expect { site.asset_path "app.css" }.to raise_error
|
71
|
+
end
|
72
|
+
end
|
94
73
|
|
95
|
-
|
96
|
-
|
74
|
+
context "with query part in requested filename" do
|
75
|
+
subject { site.asset_path "app.css?foo=bar" }
|
97
76
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
77
|
+
context "and none cachebust" do
|
78
|
+
before { site.assets_config.cachebust = :none }
|
79
|
+
it { should match(%r{^/assets/app\.css\?foo=bar$}) }
|
80
|
+
end
|
102
81
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
82
|
+
context "and soft cachebust" do
|
83
|
+
before { site.assets_config.cachebust = :soft }
|
84
|
+
it { should match %r{^/assets/app\.css\?cb=[a-f0-9]{32}&foo=bar$} }
|
85
|
+
end
|
107
86
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
end
|
112
|
-
end
|
87
|
+
context "and hard cachebust" do
|
88
|
+
before { site.assets_config.cachebust = :hard }
|
89
|
+
it { should match(%r{^/assets/app-[a-f0-9]{32}\.css\?foo=bar$}) }
|
113
90
|
end
|
91
|
+
end
|
114
92
|
|
115
|
-
|
116
|
-
|
117
|
-
it { should be_an_instance_of Configuration }
|
93
|
+
context "with anchor part in requested filename" do
|
94
|
+
subject { site.asset_path "app.css#foobar" }
|
118
95
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
end
|
96
|
+
context "and none cachebust" do
|
97
|
+
before { site.assets_config.cachebust = :none }
|
98
|
+
it { should match(%r{^/assets/app\.css#foobar$}) }
|
123
99
|
end
|
124
100
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
@dest.join("assets", "app.css").exist?.should be_true
|
101
|
+
context "and soft cachebust" do
|
102
|
+
before { site.assets_config.cachebust = :soft }
|
103
|
+
it { should match(%r{^/assets/app\.css\?cb=[a-f0-9]{32}#foobar$}) }
|
129
104
|
end
|
130
105
|
|
131
|
-
context "
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
}))
|
138
|
-
end
|
106
|
+
context "and hard cachebust" do
|
107
|
+
before { site.assets_config.cachebust = :hard }
|
108
|
+
it { should match(%r{^/assets/app-[a-f0-9]{32}\.css#foobar$}) }
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
139
112
|
|
140
|
-
|
141
|
-
|
142
|
-
|
113
|
+
context "#assets_config" do
|
114
|
+
subject { site.assets_config }
|
115
|
+
it { should be_an_instance_of Jekyll::AssetsPlugin::Configuration }
|
143
116
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
117
|
+
it "should been populated with `assets` section of config" do
|
118
|
+
site.assets_config.dirname.should_not eq "foobar"
|
119
|
+
site.assets_config.sources.should include "foobar"
|
120
|
+
end
|
121
|
+
end
|
149
122
|
|
150
|
-
|
151
|
-
|
123
|
+
it "should regenerate assets upon multiple #process" do
|
124
|
+
@site.assets_config.cachebust = :none
|
125
|
+
2.times { @site.process }
|
126
|
+
@dest.join("assets", "app.css").exist?.should be_true
|
127
|
+
end
|
152
128
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
129
|
+
context "with cache" do
|
130
|
+
def site
|
131
|
+
Jekyll::Site.new(Jekyll.configuration({
|
132
|
+
"source" => fixtures_path.to_s,
|
133
|
+
"assets" => { "cache" => true, "cachebust" => :none },
|
134
|
+
"destination" => @dest.to_s
|
135
|
+
}))
|
136
|
+
end
|
158
137
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
@dest.join("assets", "app.css.gz").exist?.should be_false
|
163
|
-
end
|
138
|
+
after do
|
139
|
+
site.assets.cache_path.rmtree if site.assets.cache_path.exist?
|
140
|
+
end
|
164
141
|
|
165
|
-
|
142
|
+
it "should regenerate static assets upon multiple #process" do
|
143
|
+
2.times { site.process }
|
144
|
+
@dest.join("assets", "noise.png").exist?.should be_true
|
145
|
+
end
|
146
|
+
end
|
166
147
|
|
167
|
-
|
168
|
-
|
169
|
-
|
148
|
+
context "#gzip" do
|
149
|
+
subject { site.assets_config }
|
150
|
+
|
151
|
+
it "should generate a static assets if gzip is enabled" do
|
152
|
+
@site.assets_config.gzip = true
|
153
|
+
@site.process
|
154
|
+
@dest.join("assets", "app.css.gz").exist?.should be_true
|
170
155
|
end
|
156
|
+
|
157
|
+
it "should not generate a static assets if gzip is enabled" do
|
158
|
+
@site.assets_config.gzip = false
|
159
|
+
@site.process
|
160
|
+
@dest.join("assets", "app.css.gz").exist?.should be_false
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should be included into Jekyll::Site" do
|
166
|
+
Jekyll::Site.included_modules.should include described_class
|
171
167
|
end
|
172
168
|
end
|