jekyll-assets 0.3.5 → 0.3.6

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 832045a15d6f254fb11848378bf00c5b94894515
4
+ data.tar.gz: 2985a2194b2393f21199d8faf70a22d33e6f133a
5
+ SHA512:
6
+ metadata.gz: 217c2da729697c4e7cc95aa0e7c424ae234423ce8b94ac0ee27e8d1a47069316bd1342f189d0c2a54fa52ac8ac3eab1bbdac59d4c2610e9349f9a7c7af0cebce
7
+ data.tar.gz: 118175635e6306e85929ff95549a927b695600416417f549310d6333e3ab1d0adb4778623165aa1bb6846a3350bea4902f205d5b147678e1ee42cff899811d06
@@ -1,2 +1,2 @@
1
1
  language: ruby
2
- rvm: [ 1.9.3 ]
2
+ rvm: [ 1.9.3, 2.0.0 ]
data/Gemfile CHANGED
@@ -1,4 +1,11 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+
4
+ group :test do
5
+ gem 'coveralls', :require => false
6
+ gem 'simplecov', :require => false
7
+ end
8
+
9
+
3
10
  # Specify your gem's dependencies in jekyll-assets.gemspec
4
11
  gemspec
data/HISTORY.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### 0.3.6 (2013-04-28)
2
+
3
+ * Ruby 2.0.0 support. See #16.
4
+
5
+
1
6
  ### 0.3.5 (2013-03-03)
2
7
 
3
8
  * Add buil-tim neat support as `require "jekyll-assets/neat"`. See #18.
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # Jekyll::AssetsPlugin
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/jekyll-assets.png)](http://badge.fury.io/rb/jekyll-assets)
3
4
  [![Build Status](https://secure.travis-ci.org/ixti/jekyll-assets.png)](http://travis-ci.org/ixti/jekyll-assets)
4
5
  [![Dependency Status](https://gemnasium.com/ixti/jekyll-assets.png)](https://gemnasium.com/ixti/jekyll-assets)
5
6
  [![Code Climate](https://codeclimate.com/github/ixti/jekyll-assets.png)](https://codeclimate.com/github/ixti/jekyll-assets)
7
+ [![Coverage Status](https://coveralls.io/repos/ixti/jekyll-assets/badge.png)](https://coveralls.io/r/ixti/jekyll-assets)
6
8
 
7
9
  Jekyll plugin, that adds Rails-alike assets pipeline, that means that:
8
10
 
@@ -1,4 +1,4 @@
1
- require "jekyll/assets_plugin/site_patch"
1
+ require "jekyll/assets_plugin/patches"
2
2
  require "jekyll/assets_plugin/filters"
3
3
  require "jekyll/assets_plugin/tag"
4
4
  require "jekyll/assets_plugin/version"
@@ -18,10 +18,6 @@ module Jekyll
18
18
  end
19
19
 
20
20
 
21
- autoload :ContextPatch, "jekyll/assets_plugin/environment/context_patch"
22
- autoload :IndexPatch, "jekyll/assets_plugin/environment/index_patch"
23
-
24
-
25
21
  attr_reader :site
26
22
 
27
23
 
@@ -42,7 +38,7 @@ module Jekyll
42
38
  # bind jekyll and Sprockets context together
43
39
  context_class.instance_variable_set :@site, @site
44
40
 
45
- context_class.send :include, ContextPatch
41
+ context_class.send :include, Patches::ContextPatch
46
42
  end
47
43
 
48
44
 
@@ -50,11 +46,6 @@ module Jekyll
50
46
  super or raise AssetNotFound, path
51
47
  end
52
48
 
53
-
54
- def index
55
- super.tap { |index| index.singleton_class.send :include, IndexPatch }
56
- end
57
-
58
49
  end
59
50
  end
60
51
  end
@@ -0,0 +1 @@
1
+ Dir[File.join File.dirname(__FILE__), "patches/**/*.rb"].each { |f| require f }
@@ -1,6 +1,6 @@
1
1
  module Jekyll
2
2
  module AssetsPlugin
3
- class Environment
3
+ module Patches
4
4
  module ContextPatch
5
5
 
6
6
  def site
@@ -0,0 +1,30 @@
1
+ # 3rd-party
2
+ require "sprockets"
3
+
4
+
5
+ module Jekyll
6
+ module AssetsPlugin
7
+ module Patches
8
+ module IndexPatch
9
+
10
+ def self.included base
11
+ base.class_eval do
12
+ alias_method :find_asset_without_jekyll, :find_asset
13
+ alias_method :find_asset, :find_asset_with_jekyll
14
+ end
15
+ end
16
+
17
+
18
+ def find_asset_with_jekyll path, options = {}
19
+ asset = find_asset_without_jekyll path, options
20
+ @environment.site.bundle_asset! asset if asset and options[:bundle]
21
+ asset
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+
30
+ Sprockets::Index.send :include, Jekyll::AssetsPlugin::Patches::IndexPatch
@@ -0,0 +1,73 @@
1
+ # 3rd-party
2
+ require "jekyll"
3
+
4
+
5
+ # internal
6
+ require "jekyll/assets_plugin/configuration"
7
+ require "jekyll/assets_plugin/environment"
8
+
9
+
10
+ module Jekyll
11
+ module AssetsPlugin
12
+ module Patches
13
+ module SitePatch
14
+
15
+ def self.included base
16
+ base.class_eval do
17
+ alias_method :write_without_assets, :write
18
+ alias_method :write, :write_with_assets
19
+ end
20
+ end
21
+
22
+
23
+ def assets_config
24
+ @assets_config ||= Configuration.new(self.config["assets"] || {})
25
+ end
26
+
27
+
28
+ def assets
29
+ @assets ||= Environment.new self
30
+ end
31
+
32
+
33
+ def asset_files
34
+ @asset_files ||= []
35
+ end
36
+
37
+
38
+ def asset_path *args
39
+ asset = assets[*args]
40
+ baseurl = "#{assets_config.baseurl}/"
41
+ cachebust = assets_config.cachebust
42
+
43
+ case cachebust
44
+ when :none then baseurl << asset.logical_path
45
+ when :soft then baseurl << asset.logical_path << "?cb=#{asset.digest}"
46
+ when :hard then baseurl << asset.digest_path
47
+ else raise "Unknown cachebust strategy: #{cachebust.inspect}"
48
+ end
49
+ end
50
+
51
+
52
+ def bundle_asset! asset
53
+ if not asset_files.include? asset
54
+ file = AssetFile.new self, asset
55
+
56
+ asset_files << file
57
+ static_files << file
58
+ end
59
+ end
60
+
61
+
62
+ def write_with_assets
63
+ static_files.push(*asset_files).uniq!
64
+ write_without_assets
65
+ end
66
+
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+
73
+ Jekyll::Site.send :include, Jekyll::AssetsPlugin::Patches::SitePatch
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module AssetsPlugin
3
- VERSION = "0.3.5"
3
+ VERSION = "0.3.6"
4
4
  end
5
5
  end
@@ -0,0 +1,133 @@
1
+ require "spec_helper"
2
+
3
+
4
+ module Jekyll::AssetsPlugin
5
+ module Patches
6
+ describe SitePatch do
7
+ let(:site) do
8
+ Class.new(Jekyll::Site) do
9
+ include SitePatch
10
+
11
+ def initialize
12
+ self.reset
13
+ end
14
+
15
+ def config
16
+ @config ||= {
17
+ "dirname" => "foobar",
18
+ "assets" => {
19
+ "sources" => [ "foobar", "_assets" ]
20
+ }
21
+ }
22
+ end
23
+
24
+ def source
25
+ @source ||= RSpecHelpers.fixtures_path.to_s
26
+ end
27
+ end.new
28
+ end
29
+
30
+ context "#assets" do
31
+ subject { site.assets }
32
+ it { should be_a_kind_of Sprockets::Environment }
33
+
34
+ context "calling #asset_path within assets" do
35
+ context "when requested file not found" do
36
+ it "should raise a NotFound error" do
37
+ Proc.new do
38
+ site.assets["should_fail.css"]
39
+ end.should raise_error(Environment::AssetNotFound)
40
+ end
41
+ end
42
+
43
+ context "when requested file found" do
44
+ it "should have proper asset path" do
45
+ noise_img_re = %r{url\(/assets/noise-[a-f0-9]{32}\.png\)}
46
+ site.assets["app.css"].to_s.should match(noise_img_re)
47
+ end
48
+
49
+ it "should be appended to the static_files list" do
50
+ asset = site.assets["app.css"] # make sure main asset was compiled
51
+ asset = site.assets["noise.png"]
52
+
53
+ site.static_files.include?(asset).should be_true
54
+ end
55
+ end
56
+ end
57
+
58
+ context "with Liquid markup within assets" do
59
+ it "should be rendered" do
60
+ site.assets["app.js"].to_s.should match(/noise-[a-f0-9]{32}\.png/)
61
+ end
62
+ end
63
+ end
64
+
65
+
66
+ context "#asset_path" do
67
+ subject { site.asset_path "app.css" }
68
+
69
+ context "with none cachebust" do
70
+ before { site.assets_config.cachebust = :none }
71
+ it { should match(%r{^/assets/app\.css$}) }
72
+ end
73
+
74
+ context "with soft cachebust" do
75
+ before { site.assets_config.cachebust = :soft }
76
+ it { should match(%r{^/assets/app\.css\?cb=[a-f0-9]{32}$}) }
77
+ end
78
+
79
+ context "with hard cachebust" do
80
+ before { site.assets_config.cachebust = :hard }
81
+ it { should match(%r{^/assets/app-[a-f0-9]{32}\.css$}) }
82
+ end
83
+
84
+ context "with unknown cachebust" do
85
+ before { site.assets_config.cachebust = :wtf }
86
+ it "should raise error" do
87
+ expect { site.asset_path "app.css" }.to raise_error
88
+ end
89
+ end
90
+ end
91
+
92
+
93
+ context "#assets_config" do
94
+ subject { site.assets_config }
95
+ it { should be_an_instance_of Configuration }
96
+
97
+ it "should been populated with `assets` section of config" do
98
+ site.assets_config.dirname.should_not == "foobar"
99
+ site.assets_config.sources.should include "foobar"
100
+ end
101
+ end
102
+
103
+
104
+ it "should regenerate assets upon multiple #process" do
105
+ @site.assets_config.cachebust = :none
106
+ 2.times { @site.process }
107
+
108
+ @dest.join("assets", "app.css").exist?.should be_true
109
+ end
110
+
111
+ context "#gzip" do
112
+ subject { site.assets_config }
113
+
114
+ it "should generate a static assets if gzip is enabled" do
115
+ @site.assets_config.gzip = true
116
+ @site.process
117
+ @dest.join("assets", "app.css.gz").exist?.should be_true
118
+ end
119
+
120
+ it "should not generate a static assets if gzip is enabled" do
121
+ @site.assets_config.gzip = false
122
+ @site.process
123
+ @dest.join("assets", "app.css.gz").exist?.should be_false
124
+ end
125
+
126
+ end
127
+
128
+ it "should be included into Jekyll::Site" do
129
+ Jekyll::Site.included_modules.should include SitePatch
130
+ end
131
+ end
132
+ end
133
+ end
@@ -1,6 +1,17 @@
1
1
  require "rubygems"
2
2
 
3
3
 
4
+ require 'simplecov'
5
+ require "coveralls"
6
+
7
+
8
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
9
+ SimpleCov::Formatter::HTMLFormatter,
10
+ Coveralls::SimpleCov::Formatter
11
+ ]
12
+ SimpleCov.start
13
+
14
+
4
15
  require "jekyll"
5
16
  require "liquid"
6
17
  require "sprockets"
metadata CHANGED
@@ -1,36 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
5
- prerelease:
4
+ version: 0.3.6
6
5
  platform: ruby
7
6
  authors:
8
7
  - Aleksey V Zapparov
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-02 00:00:00.000000000 Z
11
+ date: 2013-04-28 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: jekyll
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: sprockets
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,118 +41,105 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: guard-rspec
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: rb-inotify
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: compass
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - '>='
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - '>='
124
109
  - !ruby/object:Gem::Version
125
110
  version: '0'
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: bourbon
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
- - - ! '>='
115
+ - - '>='
132
116
  - !ruby/object:Gem::Version
133
117
  version: '0'
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
- - - ! '>='
122
+ - - '>='
140
123
  - !ruby/object:Gem::Version
141
124
  version: '0'
142
125
  - !ruby/object:Gem::Dependency
143
126
  name: neat
144
127
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
128
  requirements:
147
- - - ! '>='
129
+ - - '>='
148
130
  - !ruby/object:Gem::Version
149
131
  version: '0'
150
132
  type: :development
151
133
  prerelease: false
152
134
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
135
  requirements:
155
- - - ! '>='
136
+ - - '>='
156
137
  - !ruby/object:Gem::Version
157
138
  version: '0'
158
- description: ! " Jekyll plugin, that allows you to write javascript/css assets in\n
159
- \ other languages such as CoffeeScript, Sass, Less and ERB, concatenate\n them,
160
- respecting dependencies, minify and many more.\n"
139
+ description: |2
140
+ Jekyll plugin, that allows you to write javascript/css assets in
141
+ other languages such as CoffeeScript, Sass, Less and ERB, concatenate
142
+ them, respecting dependencies, minify and many more.
161
143
  email:
162
144
  - ixti@member.fsf.org
163
145
  executables: []
@@ -183,12 +165,13 @@ files:
183
165
  - lib/jekyll/assets_plugin/asset_file.rb
184
166
  - lib/jekyll/assets_plugin/configuration.rb
185
167
  - lib/jekyll/assets_plugin/environment.rb
186
- - lib/jekyll/assets_plugin/environment/context_patch.rb
187
- - lib/jekyll/assets_plugin/environment/index_patch.rb
188
168
  - lib/jekyll/assets_plugin/filters.rb
189
169
  - lib/jekyll/assets_plugin/liquid_processor.rb
170
+ - lib/jekyll/assets_plugin/patches.rb
171
+ - lib/jekyll/assets_plugin/patches/context_patch.rb
172
+ - lib/jekyll/assets_plugin/patches/index_patch.rb
173
+ - lib/jekyll/assets_plugin/patches/site_patch.rb
190
174
  - lib/jekyll/assets_plugin/renderer.rb
191
- - lib/jekyll/assets_plugin/site_patch.rb
192
175
  - lib/jekyll/assets_plugin/tag.rb
193
176
  - lib/jekyll/assets_plugin/version.rb
194
177
  - spec/fixtures/.gitignore
@@ -211,41 +194,34 @@ files:
211
194
  - spec/lib/jekyll/assets_plugin/asset_file_spec.rb
212
195
  - spec/lib/jekyll/assets_plugin/configuration_spec.rb
213
196
  - spec/lib/jekyll/assets_plugin/filters_spec.rb
214
- - spec/lib/jekyll/assets_plugin/site_patch_spec.rb
197
+ - spec/lib/jekyll/assets_plugin/patches/site_patch_spec.rb
215
198
  - spec/lib/jekyll/assets_plugin/tag_spec.rb
216
199
  - spec/spec_helper.rb
217
200
  - spec/support/fixtures_path.rb
218
201
  homepage: http://ixti.github.com/jekyll-assets
219
202
  licenses:
220
203
  - MIT
204
+ metadata: {}
221
205
  post_install_message:
222
206
  rdoc_options: []
223
207
  require_paths:
224
208
  - lib
225
209
  required_ruby_version: !ruby/object:Gem::Requirement
226
- none: false
227
210
  requirements:
228
- - - ! '>='
211
+ - - '>='
229
212
  - !ruby/object:Gem::Version
230
213
  version: '0'
231
- segments:
232
- - 0
233
- hash: -3616688251786802351
234
214
  required_rubygems_version: !ruby/object:Gem::Requirement
235
- none: false
236
215
  requirements:
237
- - - ! '>='
216
+ - - '>='
238
217
  - !ruby/object:Gem::Version
239
218
  version: '0'
240
- segments:
241
- - 0
242
- hash: -3616688251786802351
243
219
  requirements: []
244
220
  rubyforge_project:
245
- rubygems_version: 1.8.23
221
+ rubygems_version: 2.0.0
246
222
  signing_key:
247
- specification_version: 3
248
- summary: jekyll-assets-0.3.5
223
+ specification_version: 4
224
+ summary: jekyll-assets-0.3.6
249
225
  test_files:
250
226
  - spec/fixtures/.gitignore
251
227
  - spec/fixtures/_assets/app.css.erb
@@ -267,7 +243,7 @@ test_files:
267
243
  - spec/lib/jekyll/assets_plugin/asset_file_spec.rb
268
244
  - spec/lib/jekyll/assets_plugin/configuration_spec.rb
269
245
  - spec/lib/jekyll/assets_plugin/filters_spec.rb
270
- - spec/lib/jekyll/assets_plugin/site_patch_spec.rb
246
+ - spec/lib/jekyll/assets_plugin/patches/site_patch_spec.rb
271
247
  - spec/lib/jekyll/assets_plugin/tag_spec.rb
272
248
  - spec/spec_helper.rb
273
249
  - spec/support/fixtures_path.rb
@@ -1,15 +0,0 @@
1
- module Jekyll
2
- module AssetsPlugin
3
- class Environment
4
- module IndexPatch
5
-
6
- def find_asset path, options = {}
7
- asset = super
8
- @environment.site.bundle_asset! asset if asset and options[:bundle]
9
- asset
10
- end
11
-
12
- end
13
- end
14
- end
15
- end
@@ -1,71 +0,0 @@
1
- # 3rd-party
2
- require "jekyll"
3
-
4
-
5
- # internal
6
- require "jekyll/assets_plugin/configuration"
7
- require "jekyll/assets_plugin/environment"
8
-
9
-
10
- module Jekyll
11
- module AssetsPlugin
12
- module SitePatch
13
-
14
- def self.included base
15
- base.class_eval do
16
- alias_method :write_without_assets, :write
17
- alias_method :write, :write_with_assets
18
- end
19
- end
20
-
21
-
22
- def assets_config
23
- @assets_config ||= Configuration.new(self.config["assets"] || {})
24
- end
25
-
26
-
27
- def assets
28
- @assets ||= Environment.new self
29
- end
30
-
31
-
32
- def asset_files
33
- @asset_files ||= []
34
- end
35
-
36
-
37
- def asset_path *args
38
- asset = assets[*args]
39
- baseurl = "#{assets_config.baseurl}/"
40
- cachebust = assets_config.cachebust
41
-
42
- case cachebust
43
- when :none then baseurl << asset.logical_path
44
- when :soft then baseurl << asset.logical_path << "?cb=#{asset.digest}"
45
- when :hard then baseurl << asset.digest_path
46
- else raise "Unknown cachebust strategy: #{cachebust.inspect}"
47
- end
48
- end
49
-
50
-
51
- def bundle_asset! asset
52
- if not asset_files.include? asset
53
- file = AssetFile.new self, asset
54
-
55
- asset_files << file
56
- static_files << file
57
- end
58
- end
59
-
60
-
61
- def write_with_assets
62
- static_files.push(*asset_files).uniq!
63
- write_without_assets
64
- end
65
-
66
- end
67
- end
68
- end
69
-
70
-
71
- Jekyll::Site.send :include, Jekyll::AssetsPlugin::SitePatch
@@ -1,131 +0,0 @@
1
- require "spec_helper"
2
-
3
-
4
- module Jekyll::AssetsPlugin
5
- describe SitePatch do
6
- let(:site) do
7
- Class.new(Jekyll::Site) do
8
- include SitePatch
9
-
10
- def initialize
11
- self.reset
12
- end
13
-
14
- def config
15
- @config ||= {
16
- "dirname" => "foobar",
17
- "assets" => {
18
- "sources" => [ "foobar", "_assets" ]
19
- }
20
- }
21
- end
22
-
23
- def source
24
- @source ||= RSpecHelpers.fixtures_path.to_s
25
- end
26
- end.new
27
- end
28
-
29
- context "#assets" do
30
- subject { site.assets }
31
- it { should be_a_kind_of Sprockets::Environment }
32
-
33
- context "calling #asset_path within assets" do
34
- context "when requested file not found" do
35
- it "should raise a NotFound error" do
36
- Proc.new do
37
- site.assets["should_fail.css"]
38
- end.should raise_error(Environment::AssetNotFound)
39
- end
40
- end
41
-
42
- context "when requested file found" do
43
- it "should have proper asset path" do
44
- noise_img_re = %r{url\(/assets/noise-[a-f0-9]{32}\.png\)}
45
- site.assets["app.css"].to_s.should match(noise_img_re)
46
- end
47
-
48
- it "should be appended to the static_files list" do
49
- asset = site.assets["app.css"] # make sure main asset was compiled
50
- asset = site.assets["noise.png"]
51
-
52
- site.static_files.include?(asset).should be_true
53
- end
54
- end
55
- end
56
-
57
- context "with Liquid markup within assets" do
58
- it "should be rendered" do
59
- site.assets["app.js"].to_s.should match(/noise-[a-f0-9]{32}\.png/)
60
- end
61
- end
62
- end
63
-
64
-
65
- context "#asset_path" do
66
- subject { site.asset_path "app.css" }
67
-
68
- context "with none cachebust" do
69
- before { site.assets_config.cachebust = :none }
70
- it { should match(%r{^/assets/app\.css$}) }
71
- end
72
-
73
- context "with soft cachebust" do
74
- before { site.assets_config.cachebust = :soft }
75
- it { should match(%r{^/assets/app\.css\?cb=[a-f0-9]{32}$}) }
76
- end
77
-
78
- context "with hard cachebust" do
79
- before { site.assets_config.cachebust = :hard }
80
- it { should match(%r{^/assets/app-[a-f0-9]{32}\.css$}) }
81
- end
82
-
83
- context "with unknown cachebust" do
84
- before { site.assets_config.cachebust = :wtf }
85
- it "should raise error" do
86
- expect { site.asset_path "app.css" }.to raise_error
87
- end
88
- end
89
- end
90
-
91
-
92
- context "#assets_config" do
93
- subject { site.assets_config }
94
- it { should be_an_instance_of Configuration }
95
-
96
- it "should been populated with `assets` section of config" do
97
- site.assets_config.dirname.should_not == "foobar"
98
- site.assets_config.sources.should include "foobar"
99
- end
100
- end
101
-
102
-
103
- it "should regenerate assets upon multiple #process" do
104
- @site.assets_config.cachebust = :none
105
- 2.times { @site.process }
106
-
107
- @dest.join("assets", "app.css").exist?.should be_true
108
- end
109
-
110
- context "#gzip" do
111
- subject { site.assets_config }
112
-
113
- it "should generate a static assets if gzip is enabled" do
114
- @site.assets_config.gzip = true
115
- @site.process
116
- @dest.join("assets", "app.css.gz").exist?.should be_true
117
- end
118
-
119
- it "should not generate a static assets if gzip is enabled" do
120
- @site.assets_config.gzip = false
121
- @site.process
122
- @dest.join("assets", "app.css.gz").exist?.should be_false
123
- end
124
-
125
- end
126
-
127
- it "should be included into Jekyll::Site" do
128
- Jekyll::Site.included_modules.should include SitePatch
129
- end
130
- end
131
- end