sprockets-image_compressor 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sprockets-image_compressor.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # Image compressor processor for Sprockets
2
+
3
+ Sprockets preprocessor to losslessly compress images. Requires [pngcrush](http://pmt.sourceforge.net/pngcrush/) to be installed and in your PATH.
4
+
5
+ ## Integration with Rails 3.1+
6
+
7
+ Just add this gem to your Gemfile:
8
+
9
+ ```ruby
10
+ gem 'sprockets-image_compressor'
11
+ ````
12
+
13
+ The gem ships with a Railtie which will automatically register the compressor preprocessor.
14
+
15
+ ## Caveats
16
+
17
+ For the first release, it only compresses pngs with [pngcrush](http://pmt.sourceforge.net/pngcrush/). But don't worry, support for compressing jpegs via jpegoptim will be added shortly!
18
+
19
+ It doesn't even bother to make sure you have pngcrush installed.
20
+
21
+ Also, no tests.
22
+
23
+ ### License
24
+
25
+ (MIT License) - Copyright (c) 2011 Micah Geisel
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ module Sprockets
2
+ module ImageCompressor
3
+ class PngCompressor
4
+ def compress(content)
5
+ compressed_png_data = ""
6
+ Tempfile.open ["in_file", ".png"] do |in_file|
7
+ out_file_path = in_file.path + ".optimized.png"
8
+ in_file.write content
9
+ in_file.close
10
+ out = `pngcrush #{in_file.path} #{out_file_path}`
11
+ in_file.delete
12
+
13
+ compressed_png_data = File.read out_file_path
14
+ File.unlink out_file_path
15
+ end
16
+ compressed_png_data
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ module Sprockets
2
+ module ImageCompressor
3
+ class Railtie < Rails::Engine
4
+ initializer :setup_png_compressor 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
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Sprockets
2
+ module Imagecompressor
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require "sprockets/image_compressor/version"
2
+ require "sprockets/image_compressor/png_compressor"
3
+ require "sprockets/image_compressor/railtie" if defined?(Rails)
@@ -0,0 +1 @@
1
+ require "sprockets/image_compressor"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sprockets/image_compressor/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sprockets-image_compressor"
7
+ s.version = Sprockets::Imagecompressor::VERSION
8
+ s.authors = ["Micah Geisel"]
9
+ s.email = ["micah@botandrose.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Losslessly compress images in the Rails asset pipeline}
12
+ s.description = %q{Losslessly compress images in the Rails asset pipeline}
13
+
14
+ s.rubyforge_project = "sprockets-image_compressor"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sprockets-image_compressor
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Micah Geisel
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-20 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Losslessly compress images in the Rails asset pipeline
22
+ email:
23
+ - micah@botandrose.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - README.md
34
+ - Rakefile
35
+ - lib/sprockets-image_compressor.rb
36
+ - lib/sprockets/image_compressor.rb
37
+ - lib/sprockets/image_compressor/png_compressor.rb
38
+ - lib/sprockets/image_compressor/railtie.rb
39
+ - lib/sprockets/image_compressor/version.rb
40
+ - sprockets-image_compressor.gemspec
41
+ homepage: ""
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options: []
46
+
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ hash: 3
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ requirements: []
68
+
69
+ rubyforge_project: sprockets-image_compressor
70
+ rubygems_version: 1.8.10
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Losslessly compress images in the Rails asset pipeline
74
+ test_files: []
75
+