sprockets-image_compressor 0.1.0 → 0.1.1
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/.gitignore +1 -0
- data/CHANGELOG.md +10 -0
- data/Rakefile +5 -0
- data/lib/sprockets/image_compressor.rb +1 -0
- data/lib/sprockets/image_compressor/integration.rb +17 -0
- data/lib/sprockets/image_compressor/jpg_compressor.rb +1 -0
- data/lib/sprockets/image_compressor/png_compressor.rb +4 -1
- data/lib/sprockets/image_compressor/railtie.rb +1 -11
- data/lib/sprockets/image_compressor/version.rb +1 -1
- data/spec/fixtures/largejpg.jpg +0 -0
- data/spec/fixtures/largepng.png +0 -0
- data/spec/fixtures/smalljpg.jpg +0 -0
- data/spec/fixtures/smallpng.png +0 -0
- data/spec/integration/sprockets_integration_spec.rb +26 -0
- data/sprockets-image_compressor.gemspec +5 -3
- metadata +71 -7
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
0.1.1 (12/26/2011)
|
2
|
+
-------------------------
|
3
|
+
|
4
|
+
* Bugfix: make sure we're using binary encoding when dealing with the image files
|
5
|
+
* Bugfix: Add basic sprockets integration tests
|
6
|
+
|
7
|
+
0.1.0 (09/21/2011)
|
8
|
+
-------------------------
|
9
|
+
|
10
|
+
* Initial public release!
|
data/Rakefile
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Sprockets
|
2
|
+
module ImageCompressor
|
3
|
+
class Integration
|
4
|
+
def self.setup env
|
5
|
+
env.register_mime_type 'image/png', '.png'
|
6
|
+
env.register_postprocessor 'image/png', :png_compressor do |context, data|
|
7
|
+
PngCompressor.new.compress data
|
8
|
+
end
|
9
|
+
|
10
|
+
env.register_mime_type 'image/jpeg', '.jpg'
|
11
|
+
env.register_postprocessor 'image/jpeg', :jpg_compressor do |context, data|
|
12
|
+
JpgCompressor.new.compress data
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -4,13 +4,16 @@ module Sprockets
|
|
4
4
|
def compress(content)
|
5
5
|
compressed_png_data = ""
|
6
6
|
Tempfile.open ["in_file", ".png"] do |in_file|
|
7
|
+
in_file.binmode
|
7
8
|
out_file_path = in_file.path + ".optimized.png"
|
8
9
|
in_file.write content
|
9
10
|
in_file.close
|
10
11
|
out = `pngcrush #{in_file.path} #{out_file_path} 2>&1`
|
11
12
|
in_file.delete
|
12
13
|
|
13
|
-
|
14
|
+
File.open out_file_path, "rb" do |out_file|
|
15
|
+
compressed_png_data = out_file.read
|
16
|
+
end
|
14
17
|
File.unlink out_file_path
|
15
18
|
end
|
16
19
|
compressed_png_data
|
@@ -2,17 +2,7 @@ module Sprockets
|
|
2
2
|
module ImageCompressor
|
3
3
|
class Railtie < Rails::Engine
|
4
4
|
initializer :setup_image_compressors do |app|
|
5
|
-
if app.config.assets.compress
|
6
|
-
app.assets.register_mime_type 'image/png', '.png'
|
7
|
-
app.assets.register_postprocessor 'image/png', :png_compressor do |context, data|
|
8
|
-
PngCompressor.new.compress data
|
9
|
-
end
|
10
|
-
|
11
|
-
app.assets.register_mime_type 'image/jpeg', '.jpg'
|
12
|
-
app.assets.register_postprocessor 'image/jpeg', :jpg_compressor do |context, data|
|
13
|
-
JpgCompressor.new.compress data
|
14
|
-
end
|
15
|
-
end
|
5
|
+
Integration.setup app.assets if app.config.assets.compress
|
16
6
|
end
|
17
7
|
end
|
18
8
|
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "rack/test"
|
2
|
+
require "sprockets"
|
3
|
+
require "sprockets/image_compressor"
|
4
|
+
|
5
|
+
describe "sprockets integration" do
|
6
|
+
include Rack::Test::Methods
|
7
|
+
|
8
|
+
let(:app) do
|
9
|
+
Sprockets::Environment.new.tap do |env|
|
10
|
+
Sprockets::ImageCompressor::Integration.setup env
|
11
|
+
env.append_path "spec/fixtures"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should compress pngs" do
|
16
|
+
get "/largepng.png"
|
17
|
+
last_response.should be_ok
|
18
|
+
last_response.headers["Content-Length"].should == "116773"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should compress jpgs" do
|
22
|
+
get "/largejpg.jpg"
|
23
|
+
last_response.should be_ok
|
24
|
+
last_response.headers["Content-Length"].should == "4000"
|
25
|
+
end
|
26
|
+
end
|
@@ -18,7 +18,9 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
s.add_runtime_dependency "sprockets"
|
22
|
+
|
23
|
+
s.add_development_dependency "ruby-debug"
|
24
|
+
s.add_development_dependency "rspec"
|
25
|
+
s.add_development_dependency "rack-test"
|
24
26
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-image_compressor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Micah Geisel
|
@@ -15,9 +15,65 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
19
|
-
|
20
|
-
|
18
|
+
date: 2011-12-26 00:00:00 -08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: sprockets
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: ruby-debug
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rspec
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rack-test
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :development
|
76
|
+
version_requirements: *id004
|
21
77
|
description: Losslessly compress images in the Rails asset pipeline
|
22
78
|
email:
|
23
79
|
- micah@botandrose.com
|
@@ -29,16 +85,24 @@ extra_rdoc_files: []
|
|
29
85
|
|
30
86
|
files:
|
31
87
|
- .gitignore
|
88
|
+
- CHANGELOG.md
|
32
89
|
- Gemfile
|
33
90
|
- README.md
|
34
91
|
- Rakefile
|
35
92
|
- lib/sprockets-image_compressor.rb
|
36
93
|
- lib/sprockets/image_compressor.rb
|
94
|
+
- lib/sprockets/image_compressor/integration.rb
|
37
95
|
- lib/sprockets/image_compressor/jpg_compressor.rb
|
38
96
|
- lib/sprockets/image_compressor/png_compressor.rb
|
39
97
|
- lib/sprockets/image_compressor/railtie.rb
|
40
98
|
- lib/sprockets/image_compressor/version.rb
|
99
|
+
- spec/fixtures/largejpg.jpg
|
100
|
+
- spec/fixtures/largepng.png
|
101
|
+
- spec/fixtures/smalljpg.jpg
|
102
|
+
- spec/fixtures/smallpng.png
|
103
|
+
- spec/integration/sprockets_integration_spec.rb
|
41
104
|
- sprockets-image_compressor.gemspec
|
105
|
+
has_rdoc: true
|
42
106
|
homepage: ""
|
43
107
|
licenses: []
|
44
108
|
|
@@ -68,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
132
|
requirements: []
|
69
133
|
|
70
134
|
rubyforge_project: sprockets-image_compressor
|
71
|
-
rubygems_version: 1.
|
135
|
+
rubygems_version: 1.6.2
|
72
136
|
signing_key:
|
73
137
|
specification_version: 3
|
74
138
|
summary: Losslessly compress images in the Rails asset pipeline
|