middleman-imageoptim 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.cane +4 -0
- data/.gitignore +1 -0
- data/.travis.yml +11 -0
- data/README.md +10 -2
- data/Rakefile +2 -1
- data/lib/middleman-imageoptim/extension.rb +2 -0
- data/lib/middleman-imageoptim/optimizer.rb +37 -18
- data/lib/middleman-imageoptim/options.rb +3 -0
- data/lib/middleman-imageoptim/version.rb +1 -1
- data/middleman-imageoptim.gemspec +1 -1
- data/script/quality +7 -0
- data/script/spec +11 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/use_coveralls.rb +2 -0
- metadata +13 -8
data/.cane
ADDED
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -4,6 +4,11 @@
|
|
4
4
|
|
5
5
|
Serving big images is fo numb-skulls! Compress and optimise your imagery during `middleman build` by running [image_optim](https://github.com/toy/image_optim) over it. Yay-hooray!
|
6
6
|
|
7
|
+
[![Build Status](https://travis-ci.org/plasticine/middleman-imageoptim.png?branch=master)](https://travis-ci.org/plasticine/middleman-imageoptim)
|
8
|
+
[![Coverage Status](https://coveralls.io/repos/plasticine/middleman-imageoptim/badge.png)](https://coveralls.io/r/plasticine/middleman-imageoptim)
|
9
|
+
[![Gem Version](https://badge.fury.io/rb/middleman-imageoptim.png)](http://badge.fury.io/rb/middleman-imageoptim)
|
10
|
+
[![Dependency Status](https://gemnasium.com/plasticine/middleman-imageoptim.png)](https://gemnasium.com/plasticine/middleman-imageoptim)
|
11
|
+
|
7
12
|
![](http://cl.ly/image/0h0b330F2p3C/Terminal%20%E2%80%94%20zsh%20%E2%80%94%20109%C3%9712.png)
|
8
13
|
|
9
14
|
## Installation
|
@@ -11,7 +16,7 @@ Serving big images is fo numb-skulls! Compress and optimise your imagery during
|
|
11
16
|
Go set up the [image_optim](https://github.com/toy/image_optim) external utilities, then;
|
12
17
|
|
13
18
|
```ruby
|
14
|
-
gem "middleman-imageoptim", "~> 0.1.
|
19
|
+
gem "middleman-imageoptim", "~> 0.1.1"
|
15
20
|
```
|
16
21
|
|
17
22
|
## Usage
|
@@ -51,7 +56,10 @@ end
|
|
51
56
|
|
52
57
|
## Changelog
|
53
58
|
|
59
|
+
##### `0.1.1`
|
60
|
+
- remove legacy requirement for padrino
|
61
|
+
|
54
62
|
##### `0.1.0`
|
55
63
|
- complete refactor and clean-up
|
56
64
|
- introduced an options class. options now work (lol, yay!), thanks @andrew-aladev for your help there
|
57
|
-
- change of extension activation name from `:image_optim to `:imageoptim` for consistency with internal naming
|
65
|
+
- change of extension activation name from `:image_optim` to `:imageoptim` for consistency with internal naming
|
data/Rakefile
CHANGED
@@ -12,8 +12,9 @@ namespace :spec do
|
|
12
12
|
desc "Run cane to check quality metrics"
|
13
13
|
Cane::RakeTask.new(:quality) do |cane|
|
14
14
|
cane.abc_max = 10
|
15
|
-
cane.add_threshold 'coverage/covered_percent', :>=,
|
15
|
+
cane.add_threshold 'coverage/covered_percent', :>=, 74
|
16
16
|
cane.no_style = true
|
17
|
+
cane.abc_exclude = %w(Middleman::Imageoptim::Optimizer#optimizer)
|
17
18
|
end
|
18
19
|
|
19
20
|
task :default => :quality
|
@@ -2,11 +2,10 @@ module Middleman
|
|
2
2
|
module Imageoptim
|
3
3
|
require "image_optim"
|
4
4
|
require "fileutils"
|
5
|
-
require "padrino-helpers"
|
6
5
|
|
6
|
+
# Optimizer class that accepts an options object and processes files and
|
7
|
+
# passes them off to image_optim to be processed
|
7
8
|
class Optimizer
|
8
|
-
include ::Padrino::Helpers::NumberHelpers
|
9
|
-
|
10
9
|
def initialize(app, builder, options)
|
11
10
|
@app = app
|
12
11
|
@builder = builder
|
@@ -19,7 +18,7 @@ module Middleman
|
|
19
18
|
optimizer.optimize_images(images_to_optimize) {|src_file, dst_file|
|
20
19
|
if dst_file
|
21
20
|
@total_savings += (src_file.size - dst_file.size)
|
22
|
-
|
21
|
+
say_file_size_stats(src_file, dst_file)
|
23
22
|
FileUtils.mv dst_file, src_file
|
24
23
|
elsif @options.verbose
|
25
24
|
say_status "[skipped] #{src_file}"
|
@@ -28,16 +27,6 @@ module Middleman
|
|
28
27
|
say_status "Total image savings: #{format_size(@total_savings)}"
|
29
28
|
end
|
30
29
|
|
31
|
-
def say_status(status)
|
32
|
-
if @builder
|
33
|
-
@builder.say_status :image_optim, status
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def file_paths
|
38
|
-
::Middleman::Util.all_files_under(@app.inst.build_dir)
|
39
|
-
end
|
40
|
-
|
41
30
|
def filter_file_paths(paths)
|
42
31
|
paths.select {|path|
|
43
32
|
is_image_extension(path.extname) && image_is_optimizable(path)
|
@@ -52,10 +41,6 @@ module Middleman
|
|
52
41
|
optimizer.optimizable?(path)
|
53
42
|
end
|
54
43
|
|
55
|
-
def format_size(bytes)
|
56
|
-
number_to_human_size(bytes)
|
57
|
-
end
|
58
|
-
|
59
44
|
def size_change_word(size_src, size_dst)
|
60
45
|
size_difference = (size_src - size_dst)
|
61
46
|
if size_difference > 0
|
@@ -71,6 +56,25 @@ module Middleman
|
|
71
56
|
'%.2f%%' % [100 - 100.0 * size_dst / size_src]
|
72
57
|
end
|
73
58
|
|
59
|
+
private
|
60
|
+
|
61
|
+
def file_paths
|
62
|
+
::Middleman::Util.all_files_under(@app.inst.build_dir)
|
63
|
+
end
|
64
|
+
|
65
|
+
def say_file_size_stats(src_file, dst_file)
|
66
|
+
file_percent_change = percentage_change(src_file.size, dst_file.size)
|
67
|
+
file_size_change = format_size((src_file.size - dst_file.size))
|
68
|
+
file_size_change_type = size_change_word(src_file.size, dst_file.size)
|
69
|
+
say_status "#{src_file} (#{file_percent_change} / #{file_size_change} #{file_size_change_type})"
|
70
|
+
end
|
71
|
+
|
72
|
+
def say_status(status)
|
73
|
+
if @builder
|
74
|
+
@builder.say_status :image_optim, status
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
74
78
|
def optimizer
|
75
79
|
@optimizer ||= ImageOptim.new(
|
76
80
|
:nice => @options.nice,
|
@@ -84,6 +88,21 @@ module Middleman
|
|
84
88
|
:gifsicle => @options.gifsicle_options
|
85
89
|
)
|
86
90
|
end
|
91
|
+
|
92
|
+
def format_size(bytes)
|
93
|
+
units = %W(B KiB MiB GiB TiB)
|
94
|
+
|
95
|
+
if bytes.to_i < 1024
|
96
|
+
exponent = 0
|
97
|
+
else
|
98
|
+
max_exp = UNITS.size - 1
|
99
|
+
exponent = (Math.log(bytes) / Math.log(1024)).to_i
|
100
|
+
exponent = max_exp if exponent > max_exp
|
101
|
+
bytes /= 1024 ** exponent
|
102
|
+
end
|
103
|
+
|
104
|
+
"#{bytes}#{UNITS[exponent]}"
|
105
|
+
end
|
87
106
|
end
|
88
107
|
end
|
89
108
|
end
|
@@ -19,10 +19,10 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.add_dependency "middleman-core", [">= 3.0"]
|
20
20
|
gem.add_dependency "image_optim", "~> 0.9.1"
|
21
21
|
|
22
|
-
gem.add_development_dependency "padrino-helpers"
|
23
22
|
gem.add_development_dependency "rspec"
|
24
23
|
gem.add_development_dependency "rake"
|
25
24
|
gem.add_development_dependency "cucumber"
|
26
25
|
gem.add_development_dependency "simplecov"
|
26
|
+
gem.add_development_dependency "coveralls"
|
27
27
|
gem.add_development_dependency "cane"
|
28
28
|
end
|
data/script/quality
ADDED
data/script/spec
ADDED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-imageoptim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 0.9.1
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: rspec
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
@@ -60,7 +60,7 @@ dependencies:
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: rake
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
79
|
+
name: cucumber
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
@@ -92,7 +92,7 @@ dependencies:
|
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
|
-
name:
|
95
|
+
name: simplecov
|
96
96
|
requirement: !ruby/object:Gem::Requirement
|
97
97
|
none: false
|
98
98
|
requirements:
|
@@ -108,7 +108,7 @@ dependencies:
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
|
-
name:
|
111
|
+
name: coveralls
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
113
113
|
none: false
|
114
114
|
requirements:
|
@@ -146,8 +146,10 @@ executables: []
|
|
146
146
|
extensions: []
|
147
147
|
extra_rdoc_files: []
|
148
148
|
files:
|
149
|
+
- .cane
|
149
150
|
- .gitignore
|
150
151
|
- .rspec
|
152
|
+
- .travis.yml
|
151
153
|
- Gemfile
|
152
154
|
- LICENSE
|
153
155
|
- README.md
|
@@ -159,9 +161,12 @@ files:
|
|
159
161
|
- lib/middleman-imageoptim/version.rb
|
160
162
|
- lib/middleman_extension.rb
|
161
163
|
- middleman-imageoptim.gemspec
|
164
|
+
- script/quality
|
165
|
+
- script/spec
|
162
166
|
- spec/spec_helper.rb
|
163
167
|
- spec/unit/optimizer_spec.rb
|
164
168
|
- spec/unit/options_spec.rb
|
169
|
+
- spec/use_coveralls.rb
|
165
170
|
- spec/use_simplecov.rb
|
166
171
|
homepage: https://github.com/plasticine/middleman-imageoptim
|
167
172
|
licenses: []
|
@@ -177,7 +182,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
177
182
|
version: '0'
|
178
183
|
segments:
|
179
184
|
- 0
|
180
|
-
hash:
|
185
|
+
hash: 3808513596251224587
|
181
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
187
|
none: false
|
183
188
|
requirements:
|
@@ -186,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
191
|
version: '0'
|
187
192
|
segments:
|
188
193
|
- 0
|
189
|
-
hash:
|
194
|
+
hash: 3808513596251224587
|
190
195
|
requirements: []
|
191
196
|
rubyforge_project:
|
192
197
|
rubygems_version: 1.8.23
|