middleman-webp 0.2.0 → 0.2.1
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 +9 -6
- data/lib/middleman-webp/version.rb +1 -1
- data/spec/unit/converter_spec.rb +2 -6
- 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: f8d1995720a8e7bc350a39670a5f4c4d6df21728
|
4
|
+
data.tar.gz: e4a889e73b614e54de3e5abf796077a60a0fc06d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0293029f3349059f58a6b1fbfeb1f2b74832dcef81c768b1be3c83b74dc3f938537371dfddacd23e3a9a4a1faf2873ff4ebb2ff89f0a0915ad78aae29221f464
|
7
|
+
data.tar.gz: 7ede1788f640466e05e08cfaf9ae044a0cc29b71da1e31daa652226b53af5188ccc7eed71ae9cadabf3ebe65cc4c26cb794381016ad45ab99884c5161bdad90c
|
@@ -12,14 +12,17 @@ module Middleman
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def convert
|
15
|
-
@
|
15
|
+
@original_size = 0
|
16
|
+
@converted_size = 0
|
16
17
|
convert_images(image_files) do |src, dst|
|
17
18
|
next reject_file(dst) if dst.size >= src.size
|
18
19
|
|
19
|
-
@
|
20
|
-
@
|
20
|
+
@original_size += src.size
|
21
|
+
@converted_size += dst.size
|
22
|
+
@builder.say_status :webp, "#{dst.path} (#{change_percentage(src.size,dst.size)} smaller)"
|
21
23
|
end
|
22
|
-
|
24
|
+
savings = @original_size - @converted_size
|
25
|
+
@builder.say_status(:webp, "Total conversion savings: #{number_to_human_size(savings)} (#{change_percentage(@original_size, @converted_size)})", :blue)
|
23
26
|
end
|
24
27
|
|
25
28
|
def convert_images(paths, &after_conversion)
|
@@ -50,8 +53,8 @@ module Middleman
|
|
50
53
|
#
|
51
54
|
# src - File instance of the source
|
52
55
|
# dst - File instance of the destination
|
53
|
-
def change_percentage(
|
54
|
-
"%g %%" % ("%.2f" % [100 - 100.0 *
|
56
|
+
def change_percentage(src_size, dst_size)
|
57
|
+
"%g %%" % ("%.2f" % [100 - 100.0 * dst_size / src_size])
|
55
58
|
end
|
56
59
|
|
57
60
|
def destination_path(src_path)
|
data/spec/unit/converter_spec.rb
CHANGED
@@ -9,15 +9,11 @@ describe Middleman::WebP::Converter do
|
|
9
9
|
|
10
10
|
describe "#change_percentage" do
|
11
11
|
it "returns how many percents smaller destination file is" do
|
12
|
-
|
13
|
-
dst = stub(:size => 8746)
|
14
|
-
@converter.change_percentage(src, dst).must_equal "12.54 %"
|
12
|
+
@converter.change_percentage(10000, 8746).must_equal "12.54 %"
|
15
13
|
end
|
16
14
|
|
17
15
|
it "omits zeroes in the end of decimal part" do
|
18
|
-
|
19
|
-
dst = stub(:size => 76)
|
20
|
-
@converter.change_percentage(src, dst).must_equal "24 %"
|
16
|
+
@converter.change_percentage(100, 76).must_equal "24 %"
|
21
17
|
end
|
22
18
|
end
|
23
19
|
|
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.1
|
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-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman-core
|