juicer 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Readme.rdoc +3 -0
- data/VERSION +1 -1
- data/lib/juicer/command/merge.rb +1 -1
- data/lib/juicer/image_embed.rb +18 -20
- data/lib/juicer.rb +1 -1
- data/test/unit/juicer/image_embed_test.rb +35 -0
- metadata +3 -3
data/History.txt
CHANGED
data/Readme.rdoc
CHANGED
@@ -9,6 +9,7 @@ Christian Johansen (http://www.cjohansen.no) and contributors:
|
|
9
9
|
* Daniel Stockman (http://evocateur.org/)
|
10
10
|
* Aaron Suggs (http://ktheory.com)
|
11
11
|
* Olle Jonsson (http://ollehost.dk/blog/)
|
12
|
+
* Jakub Pawlowicz (http://blog.jakubpawlowicz.com)
|
12
13
|
|
13
14
|
== DESCRIPTION:
|
14
15
|
|
@@ -295,6 +296,8 @@ Will tell you about other dependencies that might be missing on your system.
|
|
295
296
|
* Elliott Wood (http://two-fish.com)
|
296
297
|
Added "rails" cache buster type
|
297
298
|
Fixed issues with asset host cycling
|
299
|
+
* Jakub Pawlowicz (http://blog.jakubpawlowicz.com)
|
300
|
+
Fixed issue with embedding images that weren't found
|
298
301
|
|
299
302
|
== LICENSE:
|
300
303
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.6
|
data/lib/juicer/command/merge.rb
CHANGED
@@ -193,7 +193,7 @@ the compressor the path should be the path to where the jar file is found.
|
|
193
193
|
#
|
194
194
|
def image_embed(file)
|
195
195
|
return nil if !file || file !~ /\.css$/ || @image_embed_type.nil?
|
196
|
-
Juicer::ImageEmbed.new( :type => @image_embed_type )
|
196
|
+
Juicer::ImageEmbed.new(:document_root => @document_root, :type => @image_embed_type )
|
197
197
|
end
|
198
198
|
|
199
199
|
#
|
data/lib/juicer/image_embed.rb
CHANGED
@@ -62,13 +62,13 @@ module Juicer
|
|
62
62
|
begin
|
63
63
|
next if used.include?(asset) || duplicates.include?(asset.path)
|
64
64
|
used << asset
|
65
|
-
|
65
|
+
|
66
66
|
# make sure we do not exceed SIZE_LIMIT
|
67
67
|
new_path = embed_data_uri(asset.filename)
|
68
68
|
|
69
69
|
if new_path.length < SIZE_LIMIT
|
70
70
|
# replace the url in the css file with the data uri
|
71
|
-
@contents.gsub!(asset.path, embed_data_uri(asset.
|
71
|
+
@contents.gsub!(asset.path, embed_data_uri(asset.filename)) if asset.filename.match( /\?embed=true$/ )
|
72
72
|
else
|
73
73
|
Juicer::LOGGER.warn("The final data uri for the image located at #{asset.path.gsub('?embed=true', '')} exceeds #{SIZE_LIMIT} and will not be embedded to maintain compatability.")
|
74
74
|
end
|
@@ -86,25 +86,23 @@ module Juicer
|
|
86
86
|
def embed_data_uri( path )
|
87
87
|
new_path = path
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
89
|
+
supported_file_matches = path.match( /(?:\.)(png|gif|jpg|jpeg)(?:\?embed=true)$/i )
|
90
|
+
filetype = supported_file_matches[1] if supported_file_matches
|
91
|
+
|
92
|
+
if ( filetype )
|
93
|
+
filename = path.gsub('?embed=true','')
|
92
94
|
|
93
|
-
if
|
94
|
-
|
95
|
-
|
96
|
-
#
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
new_path = Datafy::make_data_uri( content, content_type )
|
105
|
-
else
|
106
|
-
puts "Unable to locate file #{filename} on local file system, skipping image embedding"
|
107
|
-
end
|
95
|
+
# check if file exists, throw an error if it doesn't exist
|
96
|
+
if File.exist?( filename )
|
97
|
+
|
98
|
+
# read contents of file into memory
|
99
|
+
content = File.read( filename )
|
100
|
+
content_type = "image/#{filetype}"
|
101
|
+
|
102
|
+
# encode the url
|
103
|
+
new_path = Datafy::make_data_uri( content, content_type )
|
104
|
+
else
|
105
|
+
puts "Unable to locate file #{filename} on local file system, skipping image embedding"
|
108
106
|
end
|
109
107
|
end
|
110
108
|
return new_path
|
data/lib/juicer.rb
CHANGED
@@ -73,6 +73,41 @@ class TestImageEmbed < Test::Unit::TestCase
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
+
context "non empty document root" do
|
77
|
+
setup do
|
78
|
+
@document_root = '/path/to/public/dir'
|
79
|
+
@another_embedder = Juicer::ImageEmbed.new(:type => :data_uri, :document_root => @document_root)
|
80
|
+
@files = [{ :path => "#{@document_root}/images/custom-file.png", :filename => '/images/custom-file.png', :content => "hello png!" }]
|
81
|
+
create_files(@files)
|
82
|
+
end
|
83
|
+
|
84
|
+
should "embed urls with embedder" do
|
85
|
+
stylesheets = [{ :path => "#{@document_root}/stylesheets/test_absolute_path.css", :content => "body: { background: url(#{@files.first[:filename]}?embed=true); }" }]
|
86
|
+
create_files(stylesheets)
|
87
|
+
|
88
|
+
@another_embedder.save stylesheets.first[:path]
|
89
|
+
css_contents = File.read(stylesheets.first[:path])
|
90
|
+
|
91
|
+
# encode the image
|
92
|
+
image_contents = File.read(@files.first[:path])
|
93
|
+
data_uri = Datafy::make_data_uri(image_contents, 'image/png')
|
94
|
+
|
95
|
+
# make sure the encoded data_uri is present in the stylesheet
|
96
|
+
assert css_contents.include?(data_uri)
|
97
|
+
end
|
98
|
+
|
99
|
+
should "not embed urls with embedder" do
|
100
|
+
stylesheets = [{ :path => "#{@document_root}/stylesheets/test_absolute_path.css", :content => "body: { background: url(#{@files.first[:filename]}?embed=false); }" }]
|
101
|
+
create_files(stylesheets)
|
102
|
+
|
103
|
+
@another_embedder.save stylesheets.first[:path]
|
104
|
+
css_contents = File.read(stylesheets.first[:path])
|
105
|
+
|
106
|
+
# encode the image
|
107
|
+
assert css_contents.include?(@files.first[:filename])
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
76
111
|
context "with duplicated urls" do
|
77
112
|
setup do
|
78
113
|
@stylesheets = [{
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 6
|
9
|
+
version: 1.0.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Christian Johansen
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-06-
|
17
|
+
date: 2010-06-29 00:00:00 +02:00
|
18
18
|
default_executable: juicer
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|