jekyll-assets 0.7.7 → 0.7.8

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.
@@ -1,19 +1,21 @@
1
1
  require "spec_helper"
2
2
 
3
- module Jekyll::AssetsPlugin
4
- describe Environment do
5
- context "#asset_path of context" do
6
- it "should properly handle query params" do
7
- css = @site.assets["vapor.css"].to_s
8
- css.should match(/fonts\/vapor-[a-f0-9]{32}\.eot\?#iefix/)
9
- css.should match(/fonts\/vapor-[a-f0-9]{32}\.svg#iefix/)
10
- end
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
- it "should properly handle relative paths" do
13
- css = @site.assets["lib/relative.css"].to_s
14
- css.should =~ %r{/assets/fonts/vapor-[a-f0-9]{32}\.eot\?#iefix}
15
- css.should =~ %r{/assets/fonts/vapor-[a-f0-9]{32}\.svg#iefix}
16
- puts css
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
- module Jekyll::AssetsPlugin
4
- describe Filters do
5
- let(:context) { { :registers => { :site => @site } } }
3
+ describe Jekyll::AssetsPlugin::Filters do
4
+ let(:context) { { :registers => { :site => @site } } }
6
5
 
7
- def render(content)
8
- Liquid::Template.parse(content).render({}, context)
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 "{{ '<file>' | image }}" do
12
- def tag_re(name)
13
- file = "/assets/#{name}-[a-f0-9]{32}\.png"
14
- Regexp.new "^#{Renderer::IMAGE % file}$"
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
- context "when <file> exists" do
18
- subject { render("{{ 'noise.png' | image }}") }
19
- it { should match tag_re("noise") }
20
- end
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
- context "when <file> does not exists" do
23
- subject { render("{{ 'not-found.png' | image }}") }
24
- it { should match "Liquid error: Couldn't find file 'not-found.png'" }
25
- end
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 "{{ '<file>' | stylesheet }}" do
29
- def tag_re(name)
30
- file = "/assets/#{name}-[a-f0-9]{32}\.css"
31
- Regexp.new "^#{Renderer::STYLESHEET % file}$"
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
- context "when <file> exists" do
35
- subject { render("{{ 'app.css' | stylesheet }}") }
36
- it { should match tag_re("app") }
37
- end
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
- context "when <file> extension is omited" do
40
- subject { render("{{ 'app' | stylesheet }}") }
41
- it { should match tag_re("app") }
42
- end
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
- context "when <file> does not exists" do
45
- subject { render("{{ 'not-found.css' | stylesheet }}") }
46
- it { should match "Liquid error: Couldn't find file 'not-found.css'" }
47
- end
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 "{{ '<file>' | javascript }}" do
51
- def tag_re(name)
52
- file = "/assets/#{name}-[a-f0-9]{32}\.js"
53
- Regexp.new "^#{Renderer::JAVASCRIPT % file}$"
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
- context "when <file> exists" do
57
- subject { render("{{ 'app.js' | javascript }}") }
58
- it { should match tag_re("app") }
59
- end
60
+ context "when <file> extension omited" do
61
+ subject { render("{{ 'app' | javascript }}") }
62
+ it { should match tag_re("app") }
63
+ end
60
64
 
61
- context "when <file> extension omited" do
62
- subject { render("{{ 'app' | javascript }}") }
63
- it { should match tag_re("app") }
64
- end
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
- context "when <file> does not exists" do
67
- subject { render("{{ 'not-found.js' | javascript }}") }
68
- it { should match "Liquid error: Couldn't find file 'not-found.js'" }
69
- end
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 "{{ '<file.ext>' | asset_path }}" do
73
- context "when <file> exists" do
74
- subject { render("{{ 'app.css' | asset_path }}") }
75
- it { should match(%r{^/assets/app-[a-f0-9]{32}\.css$}) }
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
- context "when <file> does not exists" do
79
- subject { render("{{ 'not-found.css' | asset_path }}") }
80
- it { should match "Liquid error: Couldn't find file 'not-found.css'" }
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
- context "with baseurl given as /foobar/" do
84
- before do
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
- context "{{ '<file.ext>' | asset }}" do
94
- context "when <file> exists" do
95
- subject { render("{{ 'app.css' | asset }}") }
96
- it { should match(/body \{ background-image: url\(.+?\) \}/) }
97
- end
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
- context "when <file> does not exists" do
100
- subject { render("{{ 'not-found.js' | asset }}") }
101
- it { should match "Liquid error: Couldn't find file 'not-found.js'" }
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
- module Jekyll::AssetsPlugin
4
- module Patches
5
- describe SitePatch do
6
- let(:site) do
7
- Jekyll::Site.new Jekyll.configuration({
8
- "source" => RSpecHelpers.fixtures_path.to_s,
9
- "dirname" => "foobar",
10
- "assets" => {
11
- "sources" => %w{ foobar _assets }
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
- context "#assets" do
17
- subject { site.assets }
18
- it { should be_a_kind_of Sprockets::Environment }
14
+ context "#assets" do
15
+ subject { site.assets }
16
+ it { should be_a_kind_of ::Sprockets::Environment }
19
17
 
20
- context "#cache_path" do
21
- let(:source_path) { Pathname.new site.source }
22
- subject { site.assets.cache_path }
18
+ context "#cache_path" do
19
+ let(:source_path) { Pathname.new site.source }
20
+ subject { site.assets.cache_path }
23
21
 
24
- it { should eq source_path.join(".jekyll-assets-cache") }
25
- end
22
+ it { should eq source_path.join(".jekyll-assets-cache") }
23
+ end
26
24
 
27
- context "calling #asset_path within assets" do
28
- context "when requested file not found" do
29
- it "raises a NotFound error" do
30
- expect { site.assets["should_fail.css"] }
31
- .to raise_error Environment::AssetNotFound
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 "#asset_path" do
52
- subject { site.asset_path "app.css" }
53
-
54
- context "with none cachebust" do
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
- context "with hard cachebust" do
65
- before { site.assets_config.cachebust = :hard }
66
- it { should match(%r{^/assets/app-[a-f0-9]{32}\.css$}) }
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
- context "with unknown cachebust" do
70
- before { site.assets_config.cachebust = :wtf }
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
- context "with query part in requested filename" do
77
- subject { site.asset_path "app.css?foo=bar" }
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
- context "and none cachebust" do
80
- before { site.assets_config.cachebust = :none }
81
- it { should match(%r{^/assets/app\.css\?foo=bar$}) }
82
- end
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
- context "and soft cachebust" do
85
- before { site.assets_config.cachebust = :soft }
86
- it { should match %r{^/assets/app\.css\?cb=[a-f0-9]{32}&foo=bar$} }
87
- end
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
- context "and hard cachebust" do
90
- before { site.assets_config.cachebust = :hard }
91
- it { should match(%r{^/assets/app-[a-f0-9]{32}\.css\?foo=bar$}) }
92
- end
93
- end
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
- context "with anchor part in requested filename" do
96
- subject { site.asset_path "app.css#foobar" }
74
+ context "with query part in requested filename" do
75
+ subject { site.asset_path "app.css?foo=bar" }
97
76
 
98
- context "and none cachebust" do
99
- before { site.assets_config.cachebust = :none }
100
- it { should match(%r{^/assets/app\.css#foobar$}) }
101
- end
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
- context "and soft cachebust" do
104
- before { site.assets_config.cachebust = :soft }
105
- it { should match(%r{^/assets/app\.css\?cb=[a-f0-9]{32}#foobar$}) }
106
- end
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
- context "and hard cachebust" do
109
- before { site.assets_config.cachebust = :hard }
110
- it { should match(%r{^/assets/app-[a-f0-9]{32}\.css#foobar$}) }
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
- context "#assets_config" do
116
- subject { site.assets_config }
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
- it "should been populated with `assets` section of config" do
120
- site.assets_config.dirname.should_not eq "foobar"
121
- site.assets_config.sources.should include "foobar"
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
- it "should regenerate assets upon multiple #process" do
126
- @site.assets_config.cachebust = :none
127
- 2.times { @site.process }
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 "with cache" do
132
- def site
133
- Jekyll::Site.new(Jekyll.configuration({
134
- "source" => fixtures_path.to_s,
135
- "assets" => { "cache" => true, "cachebust" => :none },
136
- "destination" => @dest.to_s
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
- after do
141
- site.assets.cache_path.rmtree if site.assets.cache_path.exist?
142
- end
113
+ context "#assets_config" do
114
+ subject { site.assets_config }
115
+ it { should be_an_instance_of Jekyll::AssetsPlugin::Configuration }
143
116
 
144
- it "should regenerate static assets upon multiple #process" do
145
- 2.times { site.process }
146
- @dest.join("assets", "noise.png").exist?.should be_true
147
- end
148
- end
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
- context "#gzip" do
151
- subject { site.assets_config }
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
- it "should generate a static assets if gzip is enabled" do
154
- @site.assets_config.gzip = true
155
- @site.process
156
- @dest.join("assets", "app.css.gz").exist?.should be_true
157
- end
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
- it "should not generate a static assets if gzip is enabled" do
160
- @site.assets_config.gzip = false
161
- @site.process
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
- end
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
- it "should be included into Jekyll::Site" do
168
- Jekyll::Site.included_modules.should include SitePatch
169
- end
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