juicer 1.0.22 → 1.1.0
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/VERSION +1 -1
- data/lib/juicer.rb +1 -1
- data/lib/juicer/cache_buster.rb +17 -2
- data/lib/juicer/command/merge.rb +3 -3
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
data/lib/juicer.rb
CHANGED
data/lib/juicer/cache_buster.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
require 'digest/md5'
|
2
3
|
|
3
4
|
module Juicer
|
4
5
|
#
|
@@ -80,7 +81,7 @@ module Juicer
|
|
80
81
|
#
|
81
82
|
def self.path(file, type = :soft, parameter = DEFAULT_PARAMETER)
|
82
83
|
return file if file =~ /data:.*;base64/
|
83
|
-
type = [:soft, :hard, :rails].include?(type) ? type : :soft
|
84
|
+
type = [:soft, :hard, :rails, :md5].include?(type) ? type : :soft
|
84
85
|
parameter = nil if type == :rails
|
85
86
|
file = self.clean(file, parameter)
|
86
87
|
filename = file.split("?").first
|
@@ -92,11 +93,25 @@ module Juicer
|
|
92
93
|
return "#{file}#{file.index('?') ? '&' : '?'}#{parameter}#{mtime}"
|
93
94
|
elsif type == :rails
|
94
95
|
return "#{file}#{file.index('?') ? '' : "?#{mtime}"}"
|
96
|
+
elsif type == :md5
|
97
|
+
md5 = Digest::MD5.hexdigest(File.read(filename))
|
98
|
+
return file.sub(/(\.[^\.]+$)/, "-#{parameter}#{md5}" + '\1')
|
95
99
|
end
|
96
100
|
|
97
101
|
file.sub(/(\.[^\.]+$)/, "-#{parameter}#{mtime}" + '\1')
|
98
102
|
end
|
99
103
|
|
104
|
+
#
|
105
|
+
# Add a md5 cache buster to a filename. The parameter is an optional prefix
|
106
|
+
# that is added before the md5 digest. It results in filenames of the form:
|
107
|
+
# <tt>file-[parameter name][md5].suffix</tt>, ie
|
108
|
+
# <tt>images/logo-cb4fdbd4c637ad377adf0fc0c88f6854b3.png</tt> which is the case for the default
|
109
|
+
# parameter name "cb" (as in *c*ache *b*uster).
|
110
|
+
#
|
111
|
+
def self.md5(file, parameter = DEFAULT_PARAMETER)
|
112
|
+
self.path(file, :md5, parameter)
|
113
|
+
end
|
114
|
+
|
100
115
|
#
|
101
116
|
# Add a hard cache buster to a filename. The parameter is an optional prefix
|
102
117
|
# that is added before the mtime timestamp. It results in filenames of the form:
|
@@ -140,7 +155,7 @@ module Juicer
|
|
140
155
|
new_file = file.sub(/#{query_param}\d+&?/, "").sub(/(\?|&)$/, "")
|
141
156
|
return new_file unless new_file == file
|
142
157
|
|
143
|
-
file.sub(/-#{parameter}
|
158
|
+
file.sub(/-#{parameter}[0-9a-f]+(\.\w+)($|\?)/, '\1\2')
|
144
159
|
end
|
145
160
|
end
|
146
161
|
end
|
data/lib/juicer/command/merge.rb
CHANGED
@@ -75,11 +75,11 @@ the compressor the path should be the path to where the jar file is found.
|
|
75
75
|
opt.on("-b", "--absolute-urls", "Convert all referenced URLs to absolute URLs. Requires --document-root.\n" +
|
76
76
|
(" " * 37) + "Works with cycled asset hosts. Only valid for CSS files") { |t| @absolute_urls = true }
|
77
77
|
opt.on("-d", "--document-root dir", "Path to resolve absolute URLs relative to") { |path| @document_root = path }
|
78
|
-
opt.on("-c", "--cache-buster type", "none, soft, rails, or
|
78
|
+
opt.on("-c", "--cache-buster type", "none, soft, rails, hard or md5. Default is soft, which adds timestamps to\n" +
|
79
79
|
(" " * 37) + "reference URLs as query parameters. None leaves URLs untouched, rails adds\n" +
|
80
|
-
(" " * 37) + "timestamps in the same format as Rails' image_tag helper
|
80
|
+
(" " * 37) + "timestamps in the same format as Rails' image_tag helper. Hard and md5 alters\n" +
|
81
81
|
(" " * 37) + "file names") do |type|
|
82
|
-
@cache_buster = [:soft, :hard, :rails].include?(type.to_sym) ? type.to_sym : nil
|
82
|
+
@cache_buster = [:soft, :hard, :rails, :md5].include?(type.to_sym) ? type.to_sym : nil
|
83
83
|
end
|
84
84
|
opt.on("-e", "--embed-images type", "none or data_uri. Default is none. Data_uri embeds images using Base64 encoding\n" +
|
85
85
|
(" " * 37) + "None leaves URLs untouched. Candiate images must be flagged with '?embed=true to be considered") do |embed|
|