nanoc-cachebuster 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,5 +1,12 @@
1
- # 0.0.1
1
+ # 0.1.1
2
+
3
+ * Bugfix: no longer raise exception when an item has no content_filename attribute.
4
+
5
+ # 0.1.0
2
6
 
3
7
  * No more re-calculation of fingerprints, just use the routed filename.
8
+
9
+ # 0.1.0
10
+
4
11
  * Refactored into separate strategies.
5
- * First, direct extraction.
12
+ * First, direct extraction.
data/README.md CHANGED
@@ -34,31 +34,31 @@ Then load it via your project Gemfile or in `./lib/default.rb`:
34
34
  Usage
35
35
  =====
36
36
 
37
- This gem provides a Nanoc filter you can use to rewrite references to static
38
- assets in your source files. These will be picked up automatically.
37
+ This gem provides a simple helper method you can use to rewrite the output
38
+ filename of your static assets to include a content-based fingerprint.
39
+ A simple filter will look up the output filename you have generated, and
40
+ replace any references to the regularly-named file to the rewritten one.
39
41
 
40
42
  So, when you include a stylesheet:
41
43
 
42
44
  <link rel="stylesheet" href="styles.css">
43
45
 
44
- This filter will change that on compilation to:
45
-
46
- <link rel="stylesheet" href="styles-cb7a4bb98ef.css">
47
-
48
- The adjusted filename changes every time the file itself changes, so you don't
49
- want to code that by hand in your Rules file. Instead, use the helper methods
50
- provided. First, include the helpers in your ./lib/default.rb:
46
+ And you rewrite the output of the file to include a fingerprint:
51
47
 
48
+ # in your ./lib/default.rb
52
49
  include Nanoc3::Helpers::CacheBusting
50
+ # in ./Rules
51
+ route '/styles/' do
52
+ fp = fingerprint(item[:filename])
53
+ item.identifier.chop + fp + '.css'
54
+ end
53
55
 
54
- Then you can use `#should_cachebust?` and `#cachebusting_hash` in your routing
55
- rules to determine whether an item needs cachebusting, and get the fingerprint
56
- for it. So you can do something like:
56
+ The filter will change your HTML on compilation to:
57
57
 
58
- route 'styles' do
59
- fp = cachebust?(item) ? fingerprint(item[:filename]) : ''
60
- item.identifier.chop + fp + '.' + item[:extension]
61
- end
58
+ <link rel="stylesheet" href="styles-cb7a4bb98ef.css">
59
+
60
+ You get simple, content-based cachebusters for free. All that is left for you
61
+ to do is set some far-future expires header in your server configuration.
62
62
 
63
63
  Development
64
64
  ===========
data/Rakefile CHANGED
@@ -10,10 +10,6 @@ task :install => :build do
10
10
  sh "gem install nanoc-cachebuster-#{Nanoc3::Cachebuster::VERSION}.gem"
11
11
  end
12
12
 
13
- task :tag do
14
- sh "git tag -a #{Nanoc3::Cachebuster::VERSION}"
15
- end
16
-
17
13
  task :push do
18
14
  sh 'git push origin master'
19
15
  sh 'git push --tags'
@@ -37,7 +33,7 @@ end
37
33
 
38
34
  desc 'Tag the code, push upstream, build and push the gem'
39
35
  task :release => [:install, :push] do
40
- sh "gem push nanoc-cachebuster-#{Nanoc3::Cachebuster::VERSION}"
36
+ sh "gem push nanoc-cachebuster-#{Nanoc3::Cachebuster::VERSION}.gem"
41
37
  end
42
38
 
43
39
  desc 'Print current version number'
@@ -97,9 +97,16 @@ module Nanoc3
97
97
  # an input file, such as a stylesheet or HTML page.
98
98
  # @return <String> path to the same file as the input path but relative
99
99
  # to the site root.
100
+ # @todo make proper test case for this bug: items generated on the fly
101
+ # do not have a content_filename attribute. Infer path from output
102
+ # path.
100
103
  def absolutize(path)
101
104
  return path if path =~ /^\//
102
- File.join(File.dirname(current_item[:content_filename]), path).sub(/^content/, '')
105
+ if current_item[:content_filename]
106
+ File.join(File.dirname(current_item[:content_filename]), path).sub(/^content/, '')
107
+ else
108
+ File.join(File.dirname(current_item.path), path)
109
+ end
103
110
  end
104
111
  end
105
112
 
@@ -1,5 +1,5 @@
1
1
  module Nanoc3
2
2
  module Cachebuster
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
@@ -3,6 +3,10 @@ require 'ostruct'
3
3
  class MockItem
4
4
  attr_reader :path, :content
5
5
 
6
+ def self.generated_css_file
7
+ new '/styles-cb123456789.css', 'example content', { :extension => 'css' }
8
+ end
9
+
6
10
  def self.css_file(content = 'example content')
7
11
  new '/styles-cb123456789.css', content, { :extension => 'css', :content_filename => 'content/styles.css' }
8
12
  end
@@ -133,6 +137,13 @@ describe Nanoc3::Filters::CacheBuster do
133
137
 
134
138
  it_should_not_filter %Q{background: url(foo.png);}
135
139
  end
140
+
141
+ describe 'when the current item has no content path' do
142
+ let(:target) { MockItem.image_file '/foo.png', '/../images/foo-cb123456789.png' }
143
+ let(:item) { MockItem.generated_css_file }
144
+
145
+ it_should_filter %Q{background: url("../images/foo.png");} => %Q{background: url("../images/foo-cb123456789.png");}
146
+ end
136
147
  end
137
148
 
138
149
  describe 'filtering HTML' do
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc-cachebuster
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 25
4
5
  prerelease:
5
- version: 0.1.0
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
6
11
  platform: ruby
7
12
  authors:
8
13
  - Arjan van der Gaag
@@ -10,7 +15,7 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2011-05-21 00:00:00 Z
18
+ date: 2011-05-24 00:00:00 Z
14
19
  dependencies: []
15
20
 
16
21
  description: |
@@ -66,12 +71,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
71
  requirements:
67
72
  - - ">="
68
73
  - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
69
77
  version: "0"
70
78
  required_rubygems_version: !ruby/object:Gem::Requirement
71
79
  none: false
72
80
  requirements:
73
81
  - - ">="
74
82
  - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
75
86
  version: "0"
76
87
  requirements: []
77
88
 
@@ -84,3 +95,4 @@ test_files:
84
95
  - spec/nanoc3/filters/cache_buster_spec.rb
85
96
  - spec/nanoc3/helpers/cache_busting_spec.rb
86
97
  - spec/spec_helper.rb
98
+ has_rdoc: