sprockets-images 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +5 -0
- data/.travis.yml +8 -0
- data/Gemfile +2 -0
- data/README.md +29 -0
- data/Rakefile +20 -0
- data/lib/sprockets-images.rb +1 -0
- data/lib/sprockets/images.rb +26 -0
- data/lib/sprockets/images/compressors.rb +24 -0
- data/lib/sprockets/images/compressors/image_optim.rb +21 -0
- data/lib/sprockets/images/compressors/jpg_compressor.rb +17 -0
- data/lib/sprockets/images/compressors/png_compressor.rb +17 -0
- data/lib/sprockets/images/processors.rb +1 -0
- data/lib/sprockets/images/processors/image_optim_processor.rb +22 -0
- data/lib/sprockets/images/version.rb +5 -0
- data/sprockets-images.gemspec +26 -0
- data/test/fixtures/unprocessed.jpg +0 -0
- data/test/fixtures/unprocessed.png +0 -0
- data/test/helper.rb +5 -0
- data/test/integration/images_test.rb +34 -0
- metadata +164 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YmYzY2ViZGM3YTZlZjk3MzE4ODRjOTljMTFiYzk4Y2M4YWQxMzYxZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
Y2U1ZGI3YTQ2Nzk1YzkwYzkyYzMyNDNhZWY5Nzg1ZTFkZTIxYjA2Zg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MmIyZmU2NWVjZjUyODBkOWFlN2ZkMzQzYzMxYjI2MDRjY2RhM2IwYzNkMzU3
|
10
|
+
OTllOWY0NDJiNTNmYjE5MGIzYmIwZWQ3MGVjN2FhOGYwNzY4M2VlZTE2MDVl
|
11
|
+
Y2Q5OTYyYTM4ODFlNTI0NmQwNWM1YTY5ZTQyNGE3MWZhZmU4NmU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NjA1Y2UyOThlMzBhYjYyMDk4YmRmNmJiMTAxNjUxMjFjM2E5NGQzYzRhNDQx
|
14
|
+
NTc2N2NjMmVlNDRlMmRmNmI2N2YwMzE2MDExM2JjYmRmOThhYzA4NjU1YzI2
|
15
|
+
Y2FmMTE2MjMwYWY1NzllMjE5MWRhNzNmNjIyYmU0ODY2M2EwZjM=
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Sprockets Images
|
2
|
+
|
3
|
+
Extends the [Sprockets](https://github.com/sstephenson/sprockets) asset pipeline with (lossless) compression of images. The compression is done with the [image_optim](https://github.com/toy/image_optim) gem.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'sprockets-images'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install sprockets-images
|
18
|
+
|
19
|
+
## Test
|
20
|
+
|
21
|
+
$ rake
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
task :default => :test
|
5
|
+
|
6
|
+
require 'rake/testtask'
|
7
|
+
Rake::TestTask.new do |t|
|
8
|
+
t.libs << "test"
|
9
|
+
t.test_files = FileList['test/**/*_test.rb']
|
10
|
+
t.verbose = true
|
11
|
+
end
|
12
|
+
|
13
|
+
# RDoc
|
14
|
+
require 'rdoc/task'
|
15
|
+
RDoc::Task.new do |rdoc|
|
16
|
+
rdoc.title = "Sprockets::Images"
|
17
|
+
rdoc.rdoc_dir = 'rdoc'
|
18
|
+
rdoc.main = 'README.md'
|
19
|
+
rdoc.rdoc_files.include('README.md', 'lib/**/*.rb')
|
20
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "sprockets/images"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "sprockets/images/version"
|
2
|
+
require "sprockets/images/processors"
|
3
|
+
require "sprockets/images/compressors"
|
4
|
+
|
5
|
+
module Sprockets
|
6
|
+
module Images
|
7
|
+
class Integration
|
8
|
+
attr_reader :processor
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@processor = Processors::ImageOptimProcessor.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup(env)
|
15
|
+
Compressors.constants.each do |compressor|
|
16
|
+
next unless compressor =~ /Compressor$/
|
17
|
+
klass = Compressors.const_get(compressor)
|
18
|
+
env.register_postprocessor klass.default_mime_type, klass.name do |context, data|
|
19
|
+
klass.new(processor).compress(context, data)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Sprockets
|
2
|
+
module Images
|
3
|
+
module Compressors
|
4
|
+
class Base
|
5
|
+
class << self
|
6
|
+
attr_accessor :default_mime_type, :default_file_extension
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :processor
|
10
|
+
def initialize(processor)
|
11
|
+
@processor = processor
|
12
|
+
end
|
13
|
+
|
14
|
+
def compress
|
15
|
+
raise NotImplementedError
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
require "sprockets/images/compressors/png_compressor"
|
24
|
+
require "sprockets/images/compressors/jpg_compressor"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Sprockets
|
2
|
+
module Images
|
3
|
+
module Compressors
|
4
|
+
module ImageOptim
|
5
|
+
|
6
|
+
def compress(context, data)
|
7
|
+
compressed = data
|
8
|
+
Tempfile.open ["sprockets-images", self.class.default_file_extension] do |file|
|
9
|
+
file.binmode
|
10
|
+
file.write data
|
11
|
+
file.close
|
12
|
+
|
13
|
+
compressed = processor.process(file.path)
|
14
|
+
end
|
15
|
+
compressed
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "sprockets/images/compressors/image_optim"
|
2
|
+
|
3
|
+
module Sprockets
|
4
|
+
module Images
|
5
|
+
module Compressors
|
6
|
+
|
7
|
+
class JPGCompressor < Base
|
8
|
+
include ImageOptim
|
9
|
+
|
10
|
+
self.default_mime_type = "image/jpeg"
|
11
|
+
self.default_file_extension = "jpg"
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "sprockets/images/compressors/image_optim"
|
2
|
+
|
3
|
+
module Sprockets
|
4
|
+
module Images
|
5
|
+
module Compressors
|
6
|
+
|
7
|
+
class PNGCompressor < Base
|
8
|
+
include ImageOptim
|
9
|
+
|
10
|
+
self.default_mime_type = "image/png"
|
11
|
+
self.default_file_extension = "png"
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "sprockets/images/processors/image_optim_processor"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "image_optim"
|
2
|
+
|
3
|
+
module Sprockets
|
4
|
+
module Images
|
5
|
+
module Processors
|
6
|
+
|
7
|
+
class ImageOptimProcessor
|
8
|
+
attr_reader :image_optim, :config
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@config = {:pngout => false}
|
12
|
+
@image_optim = ImageOptim.new(config)
|
13
|
+
end
|
14
|
+
|
15
|
+
def process(file)
|
16
|
+
open(image_optim.optimize_image(file), "rb").read
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "sprockets/images/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "sprockets-images"
|
6
|
+
gem.version = Sprockets::Images::VERSION
|
7
|
+
gem.authors = ["Jonas Thiel"]
|
8
|
+
gem.email = ["jonasthiel@googlemail.com"]
|
9
|
+
gem.homepage = "http://www.jonasthiel.de"
|
10
|
+
gem.summary = %q{Extend sprockets pipepline by image compression}
|
11
|
+
gem.description = %q{Extend sprockets pipepline by image compression}
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split("\n")
|
14
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
|
18
|
+
gem.add_dependency "sprockets", "~> 2.9"
|
19
|
+
gem.add_dependency "image_optim", "~> 0.7.3"
|
20
|
+
|
21
|
+
gem.add_development_dependency "rake"
|
22
|
+
gem.add_development_dependency "rdoc"
|
23
|
+
gem.add_development_dependency "minitest"
|
24
|
+
gem.add_development_dependency "testem"
|
25
|
+
gem.add_development_dependency "rack-test"
|
26
|
+
end
|
Binary file
|
Binary file
|
data/test/helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "sprockets"
|
3
|
+
|
4
|
+
class SprocketsImagesIntegrationTest < Testem
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
let(:app) do
|
8
|
+
Sprockets::Environment.new.tap do |env|
|
9
|
+
Sprockets::Images::Integration.new.setup env
|
10
|
+
env.append_path "test/fixtures"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
test "compresses jpg" do
|
15
|
+
test_image("unprocessed.jpg")
|
16
|
+
end
|
17
|
+
|
18
|
+
test "compresses png" do
|
19
|
+
test_image("unprocessed.png")
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def test_image(file)
|
25
|
+
plain = open("test/fixtures/#{file}")
|
26
|
+
plain_size = plain.size
|
27
|
+
processed = get "/#{file}"
|
28
|
+
processed_size = processed.headers["Content-Length"].to_i
|
29
|
+
|
30
|
+
assert processed_size > 0, "processed file should have a size"
|
31
|
+
assert processed_size < plain_size, "processed file should be smaller than original"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sprockets-images
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonas Thiel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sprockets
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: image_optim
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.7.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.7.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rdoc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: testem
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rack-test
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Extend sprockets pipepline by image compression
|
112
|
+
email:
|
113
|
+
- jonasthiel@googlemail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- .travis.yml
|
120
|
+
- Gemfile
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- lib/sprockets-images.rb
|
124
|
+
- lib/sprockets/images.rb
|
125
|
+
- lib/sprockets/images/compressors.rb
|
126
|
+
- lib/sprockets/images/compressors/image_optim.rb
|
127
|
+
- lib/sprockets/images/compressors/jpg_compressor.rb
|
128
|
+
- lib/sprockets/images/compressors/png_compressor.rb
|
129
|
+
- lib/sprockets/images/processors.rb
|
130
|
+
- lib/sprockets/images/processors/image_optim_processor.rb
|
131
|
+
- lib/sprockets/images/version.rb
|
132
|
+
- sprockets-images.gemspec
|
133
|
+
- test/fixtures/unprocessed.jpg
|
134
|
+
- test/fixtures/unprocessed.png
|
135
|
+
- test/helper.rb
|
136
|
+
- test/integration/images_test.rb
|
137
|
+
homepage: http://www.jonasthiel.de
|
138
|
+
licenses: []
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ! '>='
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ! '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.1.11
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: Extend sprockets pipepline by image compression
|
160
|
+
test_files:
|
161
|
+
- test/fixtures/unprocessed.jpg
|
162
|
+
- test/fixtures/unprocessed.png
|
163
|
+
- test/helper.rb
|
164
|
+
- test/integration/images_test.rb
|