nanoc-cachebuster 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,12 +1,5 @@
1
- # 0.1.1
2
-
3
- * Bugfix: no longer raise exception when an item has no content_filename attribute.
4
-
5
- # 0.1.0
1
+ # 0.0.1
6
2
 
7
3
  * No more re-calculation of fingerprints, just use the routed filename.
8
-
9
- # 0.1.0
10
-
11
4
  * Refactored into separate strategies.
12
- * First, direct extraction.
5
+ * First, direct extraction.
data/Rakefile CHANGED
@@ -31,7 +31,7 @@ task :log do
31
31
  end
32
32
  end
33
33
 
34
- desc 'Tag the code, push upstream, build and push the gem'
34
+ desc 'Push code upstream, build and publish the gem'
35
35
  task :release => [:install, :push] do
36
36
  sh "gem push nanoc-cachebuster-#{Nanoc3::Cachebuster::VERSION}.gem"
37
37
  end
@@ -1,3 +1,5 @@
1
+ require 'pathname'
2
+
1
3
  module Nanoc3
2
4
  module Cachebuster
3
5
  # The Strategy is a way to deal with an input file. The Cache busting filter
@@ -76,11 +78,14 @@ module Nanoc3
76
78
  raise Nanoc3::Cachebuster::NoSuchSourceFile, 'No source file found matching ' + input_path
77
79
  end
78
80
 
79
- # Make sure to keep or remove the first slash, as the input path
80
- # does.
81
- matching_item.path.tap do |p|
82
- p.sub!(/^\//, '') unless input_path =~ /^\//
83
- end
81
+ # keep using an absolute path if the input reference did so...
82
+ return matching_item.path if input_path =~ /^\//
83
+
84
+ # ... if not, recreate the relative path to referenced file from
85
+ # the current file path.
86
+ current_path = Pathname.new(File.dirname(current_item.path))
87
+ target_path = Pathname.new(File.dirname(matching_item.path))
88
+ output_reference = target_path.relative_path_from(current_path).join(File.basename(matching_item.path))
84
89
  end
85
90
 
86
91
  # Get the absolute path to a file, whereby absolute means relative to the root.
@@ -103,9 +108,9 @@ module Nanoc3
103
108
  def absolutize(path)
104
109
  return path if path =~ /^\//
105
110
  if current_item[:content_filename]
106
- File.join(File.dirname(current_item[:content_filename]), path).sub(/^content/, '')
111
+ File.expand_path(File.join(File.dirname(current_item[:content_filename]), path)).sub(/^#{Dir.pwd}/, '').sub(/^\/content/, '')
107
112
  else
108
- File.join(File.dirname(current_item.path), path)
113
+ File.dirname(current_item.path)
109
114
  end
110
115
  end
111
116
  end
@@ -1,5 +1,5 @@
1
1
  module Nanoc3
2
2
  module Cachebuster
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  end
@@ -3,18 +3,22 @@ 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
-
10
6
  def self.css_file(content = 'example content')
11
7
  new '/styles-cb123456789.css', content, { :extension => 'css', :content_filename => 'content/styles.css' }
12
8
  end
13
9
 
10
+ def self.css_file_in_folder(folder_name = 'assets')
11
+ new "/#{folder_name}/styles-cb123456789.css", 'example content', { :extension => 'css', :content_filename => "content/#{folder_name}/styles.css" }
12
+ end
13
+
14
14
  def self.html_file(content = 'example content')
15
15
  new '/output_file.html', content, { :extension => 'html', :content_filename => 'content/input_file.html' }
16
16
  end
17
17
 
18
+ def self.html_file_in_folder(folder_name = 'baz', content = 'example content')
19
+ new "/#{folder_name}/output_file.html", content, { :extension => 'html', :content_filename => "content/#{folder_name}/input_file.html" }
20
+ end
21
+
18
22
  def self.image_file(input = '/foo.png', output = '/foo-cb123456789.png')
19
23
  new output, 'hello, world', { :extension => 'png', :content_filename => input }
20
24
  end
@@ -117,10 +121,11 @@ describe Nanoc3::Filters::CacheBuster do
117
121
  end
118
122
 
119
123
  describe 'when using a relative path' do
120
- let(:target) { MockItem.image_file '/foo.png', '/../images/foo-cb123456789.png' }
124
+ let(:item) { MockItem.css_file_in_folder }
125
+ let(:target) { MockItem.image_file '/images/foo.png', '/images/foo-cb123456789.png' }
121
126
 
122
127
  before(:each) do
123
- File.stub!(:read).with(File.join(Dir.pwd, 'content', 'foo.png')).and_return(context[:content])
128
+ File.stub!(:read).with(File.join(Dir.pwd, 'content', 'images', 'foo.png')).and_return(context[:content])
124
129
  end
125
130
 
126
131
  it_should_filter %Q{background: url("../images/foo.png");} => %Q{background: url("../images/foo-cb123456789.png");}
@@ -137,13 +142,6 @@ describe Nanoc3::Filters::CacheBuster do
137
142
 
138
143
  it_should_not_filter %Q{background: url(foo.png);}
139
144
  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
147
145
  end
148
146
 
149
147
  describe 'filtering HTML' do
@@ -179,7 +177,8 @@ describe Nanoc3::Filters::CacheBuster do
179
177
  end
180
178
 
181
179
  describe 'when using a relative path' do
182
- let(:target) { MockItem.image_file '/foo.png', '/../images/foo-cb123456789.png' }
180
+ let(:item) { MockItem.html_file_in_folder }
181
+ let(:target) { MockItem.image_file '/foo.png', '/images/foo-cb123456789.png' }
183
182
 
184
183
  before(:each) do
185
184
  File.stub!(:read).with(File.join(Dir.pwd, 'content', 'foo.png')).and_return(context[:content])
@@ -233,7 +232,8 @@ describe Nanoc3::Filters::CacheBuster do
233
232
  end
234
233
 
235
234
  describe 'when using a relative path' do
236
- let(:target) { MockItem.image_file '/foo.png', '/../images/foo-cb123456789.png' }
235
+ let(:item) { MockItem.html_file_in_folder }
236
+ let(:target) { MockItem.image_file '/foo.png', '/images/foo-cb123456789.png' }
237
237
 
238
238
  before(:each) do
239
239
  File.stub!(:read).with(File.join(Dir.pwd, 'content', 'foo.png')).and_return(context[:content])
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc-cachebuster
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Arjan van der Gaag
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-24 00:00:00 Z
18
+ date: 2011-05-27 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: |