middleman-webp 0.2.2 → 0.2.3
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.
- checksums.yaml +4 -4
- data/lib/middleman-webp/converter.rb +14 -5
- data/lib/middleman-webp/version.rb +1 -1
- data/spec/unit/converter_spec.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0b0affadf5badd85debeee5e4c945f5e18dadb9
|
4
|
+
data.tar.gz: 161c2a8925c82eeda8f84699bade12bb8532b0b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 674cd611524a0617647a575c9e5646f04754774ed4f2df54cab27333e87588b511f2747b8087a158f036f3bcac675c1ab4edff8cd3b4387df3176bbf9eba61b5
|
7
|
+
data.tar.gz: 6ec3ddc1d381977d35de9dd352c7ef4c5709f26925ecd925b1150e11d91e5aa861954c8b8fe93a9ddefd75ad03f8dbe5ec7bd4307ba98f64a92e56b8f701beb0
|
@@ -27,9 +27,13 @@ module Middleman
|
|
27
27
|
|
28
28
|
def convert_images(paths, &after_conversion)
|
29
29
|
paths.each do |p|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
begin
|
31
|
+
dst = destination_path(p)
|
32
|
+
exec_convert_tool(p, dst)
|
33
|
+
yield File.new(p), File.new(dst)
|
34
|
+
rescue
|
35
|
+
@builder.say_status :webp, "Converting #{p} failed", :red
|
36
|
+
end
|
33
37
|
end
|
34
38
|
end
|
35
39
|
|
@@ -54,7 +58,9 @@ module Middleman
|
|
54
58
|
# src - File instance of the source
|
55
59
|
# dst - File instance of the destination
|
56
60
|
def change_percentage(src_size, dst_size)
|
57
|
-
|
61
|
+
return '0 %' if src_size == 0
|
62
|
+
|
63
|
+
format('%g %%', format('%.2f', 100 - 100.0 * dst_size / src_size))
|
58
64
|
end
|
59
65
|
|
60
66
|
def destination_path(src_path)
|
@@ -68,9 +74,12 @@ module Middleman
|
|
68
74
|
end
|
69
75
|
|
70
76
|
def number_to_human_size(n)
|
77
|
+
return '0 B' if n == 0
|
78
|
+
|
71
79
|
units = %w{B KiB MiB GiB TiB PiB}
|
72
80
|
exponent = (Math.log(n) / Math.log(1024)).to_i
|
73
|
-
"%g #{units[exponent]}"
|
81
|
+
format("%g #{units[exponent]}",
|
82
|
+
format('%.2f', n.to_f / 1024**exponent))
|
74
83
|
end
|
75
84
|
end
|
76
85
|
end
|
data/spec/unit/converter_spec.rb
CHANGED
@@ -15,6 +15,10 @@ describe Middleman::WebP::Converter do
|
|
15
15
|
it "omits zeroes in the end of decimal part" do
|
16
16
|
@converter.change_percentage(100, 76).must_equal "24 %"
|
17
17
|
end
|
18
|
+
|
19
|
+
it "returns 0% when original and new size are both 0" do
|
20
|
+
@converter.change_percentage(0, 0).must_equal "0 %"
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
24
|
describe "#number_to_human_size" do
|
@@ -23,6 +27,10 @@ describe Middleman::WebP::Converter do
|
|
23
27
|
@converter.number_to_human_size(1234).must_equal "1.21 KiB"
|
24
28
|
@converter.number_to_human_size(2_634_234).must_equal "2.51 MiB"
|
25
29
|
end
|
30
|
+
|
31
|
+
it 'handles zero size properly' do
|
32
|
+
@converter.number_to_human_size(0).must_equal '0 B'
|
33
|
+
end
|
26
34
|
end
|
27
35
|
|
28
36
|
describe "#tool_for" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-webp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juhamatti Niemelä
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman-core
|