sprockets-image_compressor 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
2
  .bundle
3
+ .rvmrc
3
4
  Gemfile.lock
4
5
  pkg/*
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
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -1,4 +1,5 @@
1
1
  require "sprockets/image_compressor/version"
2
2
  require "sprockets/image_compressor/png_compressor"
3
3
  require "sprockets/image_compressor/jpg_compressor"
4
+ require "sprockets/image_compressor/integration"
4
5
  require "sprockets/image_compressor/railtie" if defined?(Rails)
@@ -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,6 +4,7 @@ module Sprockets
4
4
  def compress(content)
5
5
  compressed_jpg_data = ""
6
6
  Tempfile.open ["file", ".jpg"] do |file|
7
+ file.binmode
7
8
  file.write content
8
9
  file.close
9
10
 
@@ -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
- compressed_png_data = File.read out_file_path
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
@@ -1,5 +1,5 @@
1
1
  module Sprockets
2
2
  module Imagecompressor
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  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
- # specify any dependencies here; for example:
22
- # s.add_development_dependency "rspec"
23
- # s.add_runtime_dependency "rest-client"
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: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
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-09-21 00:00:00 Z
19
- dependencies: []
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.8.10
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