jekyll-assets 0.3.1 → 0.3.2

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/HISTORY.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### 0.3.2 (2013-02-10)
2
+
3
+ * Allow choose cachebusting strategy (hard/soft/none). See #11.
4
+
5
+
1
6
  ### 0.3.1 (2013-02-02)
2
7
 
3
8
  * Preprocess CSS/JS assets with Liquid processor.
data/README.md CHANGED
@@ -204,14 +204,6 @@ assets:
204
204
  [amazon-s3]: http://aws.amazon.com/s3
205
205
 
206
206
 
207
- That's all. Feel free to ask questions if any on [twitter][twitter],
208
- [jabber][jabber] or [e-mail][e-mail].
209
-
210
- [twitter]: https://twitter.com/zapparov
211
- [jabber]: xmpp://zapparov@jabber.ru
212
- [e-mail]: mailto://ixti@member.fsf.org
213
-
214
-
215
207
  ## Custom Vendors
216
208
 
217
209
  Sometimes you would like to have some 3rd-party vendors. For this purposes,
@@ -402,13 +394,6 @@ You can fine-tune configuration by editing your `_config.yml`:
402
394
  css: ~
403
395
 
404
396
 
405
- ## "Ben, I need help!" (c) Brother 2
406
-
407
- Feel free to send me any comments, recommendations, suggestions. Improve this
408
- README, as I really suck in documenting things (thanks @imathis for pointing
409
- this out).
410
-
411
-
412
397
  ## Contributing
413
398
 
414
399
  1. Fork it
@@ -418,6 +403,16 @@ this out).
418
403
  5. Create new Pull Request
419
404
 
420
405
 
406
+ ## "Th-th-th-that's all folks!"
407
+
408
+ Feel free to follow me on [twitter][twitter], chat via [jabber][jabber] or
409
+ write an [e-mail][e-mail]. :D
410
+
411
+ [twitter]: https://twitter.com/zapparov
412
+ [jabber]: xmpp://zapparov@jabber.ru
413
+ [e-mail]: mailto://ixti@member.fsf.org
414
+
415
+
421
416
  ## License
422
417
 
423
418
  Copyright (C) 2012 Aleksey V Zapparov (http://ixti.net/)
@@ -6,9 +6,10 @@ module Jekyll
6
6
  module AssetsPlugin
7
7
  class Configuration
8
8
  DEFAULTS = {
9
- :dirname => "assets",
10
- :sources => %w{_assets/javascripts _assets/stylesheets _assets/images},
11
- :compress => { :css => nil, :js => nil }
9
+ :dirname => "assets",
10
+ :sources => %w{_assets/javascripts _assets/stylesheets _assets/images},
11
+ :compress => { :css => nil, :js => nil },
12
+ :cachebust => :hard
12
13
  }.freeze
13
14
 
14
15
 
@@ -30,18 +31,36 @@ module Jekyll
30
31
 
31
32
 
32
33
  def js_compressor
33
- @data.compress.js ? @data.compress.js.to_sym : false
34
+ compressor @data.compress.js
34
35
  end
35
36
 
36
37
 
37
38
  def css_compressor
38
- @data.compress.css ? @data.compress.css.to_sym : false
39
+ compressor @data.compress.css
40
+ end
41
+
42
+
43
+ def cachebust
44
+ none?(@data.cachebust) ? :none : @data.cachebust.to_sym
39
45
  end
40
46
 
41
47
 
42
48
  def method_missing name, *args, &block
43
49
  @data.send name, *args, &block
44
50
  end
51
+
52
+
53
+ protected
54
+
55
+
56
+ def none? val
57
+ val.nil? || val.empty? || "none" == val.to_s.downcase
58
+ end
59
+
60
+
61
+ def compressor val
62
+ none?(val) ? nil : val.to_sym
63
+ end
45
64
  end
46
65
  end
47
66
  end
@@ -9,7 +9,7 @@ module Jekyll
9
9
 
10
10
 
11
11
  def asset_path *args
12
- "#{site.assets_config.baseurl}/#{site.assets[*args].digest_path}"
12
+ site.asset_path(*args)
13
13
  end
14
14
 
15
15
  end
@@ -18,7 +18,7 @@ module Jekyll
18
18
 
19
19
 
20
20
  def render_asset_path
21
- "#{@site.assets_config.baseurl}/#{@site.assets[@path].digest_path}"
21
+ @site.asset_path @path
22
22
  end
23
23
 
24
24
 
@@ -20,6 +20,19 @@ module Jekyll
20
20
  @assets ||= Environment.new self
21
21
  end
22
22
 
23
+
24
+ def asset_path *args
25
+ asset = assets[*args]
26
+ baseurl = "#{assets_config.baseurl}/"
27
+
28
+ case assets_config.cachebust
29
+ when :none then baseurl << asset.logical_path
30
+ when :soft then baseurl << asset.logical_path << "?cb=#{asset.digest}"
31
+ when :hard then baseurl << asset.digest_path
32
+ else raise "Unknown cachebast strategy: #{assets_config.cachebust}"
33
+ end
34
+ end
35
+
23
36
  end
24
37
  end
25
38
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module AssetsPlugin
3
- VERSION = "0.3.1"
3
+ VERSION = "0.3.2"
4
4
  end
5
5
  end
@@ -21,6 +21,11 @@ module Jekyll::AssetsPlugin
21
21
  it { should =~ Configuration::DEFAULTS[:sources] }
22
22
  end
23
23
 
24
+ context "cachebust" do
25
+ subject { config.cachebust }
26
+ it { should == :hard }
27
+ end
28
+
24
29
  context "js compressor" do
25
30
  subject { config.compress.js }
26
31
  it { should be_nil }
@@ -61,6 +61,34 @@ module Jekyll::AssetsPlugin
61
61
  end
62
62
  end
63
63
 
64
+
65
+ context "#asset_path" do
66
+ context "with none cachebust" do
67
+ before { site.assets_config.cachebust = :none }
68
+ subject { site.asset_path "app.css" }
69
+ it { should match(%r{^/assets/app\.css$}) }
70
+ end
71
+
72
+ context "with soft cachebust" do
73
+ before { site.assets_config.cachebust = :soft }
74
+ subject { site.asset_path "app.css" }
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
+ subject { site.asset_path "app.css" }
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
+
64
92
  context "#assets_config" do
65
93
  subject { site.assets_config }
66
94
  it { should be_an_instance_of Configuration }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
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: 2013-02-02 00:00:00.000000000 Z
12
+ date: 2013-02-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jekyll
@@ -218,7 +218,7 @@ rubyforge_project:
218
218
  rubygems_version: 1.8.23
219
219
  signing_key:
220
220
  specification_version: 3
221
- summary: jekyll-assets-0.3.1
221
+ summary: jekyll-assets-0.3.2
222
222
  test_files:
223
223
  - spec/fixtures/.gitignore
224
224
  - spec/fixtures/_assets/app.css.erb