middleman-webp 0.2.7 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +28 -1
- data/lib/middleman-webp/converter.rb +2 -1
- data/lib/middleman-webp/extension.rb +8 -0
- data/lib/middleman-webp/options.rb +3 -2
- data/lib/middleman-webp/version.rb +1 -1
- data/spec/fixtures/ok-source/lizard.jpg +0 -0
- data/spec/fixtures/ok-source/tux.png +0 -0
- data/spec/integration/extension_spec.rb +72 -3
- data/spec/unit/extension_spec.rb +1 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6c244ea287e06cf4f880eedb451099a9c6d0a3b
|
4
|
+
data.tar.gz: 27292bb40349197fd0ba463e59338ded84a4d6c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5eb6489c649a50da9bb0eba4aafc7d64a347358d6e6014d21e6977526e4011e2c254927fbe4b54de40121f8d4465b69a3492d3c70e90af1adecbe416232a25f0
|
7
|
+
data.tar.gz: 3246a4a8f3f6e82d4d965a6f0f1d1ae910d9d61f7e365ea00dc3809e662073b69e7cc555eecdb944f215d84a5aba1a2cf48afb3d3d4b7aa28181ce1241291fc0
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -30,7 +30,7 @@ install those first for your system.
|
|
30
30
|
|
31
31
|
- Fedora: ```yum install libwebp-tools```
|
32
32
|
- Ubuntu: ```apt-get install webp```
|
33
|
-
- OS X: ```brew install webp```
|
33
|
+
- OS X: ```brew install webp --with-giflib```
|
34
34
|
- Or install from the Google's WebP site:
|
35
35
|
https://developers.google.com/speed/webp/download
|
36
36
|
|
@@ -48,6 +48,8 @@ And activate :webp extension in your config.rb:
|
|
48
48
|
activate :webp
|
49
49
|
```
|
50
50
|
|
51
|
+
## Options
|
52
|
+
|
51
53
|
### Custom conversion options
|
52
54
|
|
53
55
|
Options for conversion are defined using
|
@@ -105,6 +107,30 @@ activate :webp do |webp|
|
|
105
107
|
end
|
106
108
|
```
|
107
109
|
|
110
|
+
### Working with asset_hash core extension
|
111
|
+
|
112
|
+
When you use [asset_hash extension](https://middlemanapp.com/advanced/improving_cacheability/)
|
113
|
+
you may want to change whether WebP image are converted before or after
|
114
|
+
Middleman build, dependin on how you plan to serve/download them.
|
115
|
+
|
116
|
+
Default behaviour is to generate WebP images after build, which will create
|
117
|
+
identical filenames with different extension, preserving the original
|
118
|
+
asset_cache hash. This works well if you are going to replace request content
|
119
|
+
based on Accepts header while serving image files by [configuring .htaccess or something similar](#configuring-your-site-to-provide-webp-alternatives).
|
120
|
+
|
121
|
+
However if you are going to determine used file type on client side and want to
|
122
|
+
use [asset helpers](https://middlemanapp.com/basics/helper_methods/), it would
|
123
|
+
be good idea to generate WebP versions before build allowing them to have their
|
124
|
+
own asset hashes. In this case you probably want to generate WebP versions
|
125
|
+
always even if they end up to be same size or larger than originals.
|
126
|
+
|
127
|
+
``` ruby
|
128
|
+
activate :webp do |webp|
|
129
|
+
webp.run_before_build = true
|
130
|
+
webp.allow_skip = false
|
131
|
+
end
|
132
|
+
```
|
133
|
+
|
108
134
|
## Configuring your site to provide WebP alternatives
|
109
135
|
|
110
136
|
Configure web server to serve WebP images if they are available and
|
@@ -126,3 +152,4 @@ Look for [this example how to do it in .htaccess][htaccess].
|
|
126
152
|
|
127
153
|
- [Johannes Schleifenbaum](https://github.com/jojosch)
|
128
154
|
- [Ryan Townsend](https://github.com/ryantownsend)
|
155
|
+
- [François VANTOMME](https://github.com/akarzim)
|
@@ -90,7 +90,8 @@ module Middleman
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def image_files
|
93
|
-
|
93
|
+
app_dir = @app.inst.send(@options.run_before_build ? :source_dir : :build_dir)
|
94
|
+
all = ::Middleman::Util.all_files_under(app_dir)
|
94
95
|
images = all.select { |p| p.to_s =~ SUFFIX_RE }
|
95
96
|
|
96
97
|
# Reject files matching possible ignore patterns
|
@@ -13,13 +13,21 @@ module Middleman
|
|
13
13
|
option(:verbose, false, 'Display all external command which are executed '\
|
14
14
|
'to help debugging.')
|
15
15
|
option(:allow_skip, true, 'Skip saving .webp files which are larger than their source')
|
16
|
+
option(:run_before_build, false, 'Run before build and save .webp files in source dir')
|
16
17
|
|
17
18
|
def initialize(app, options_hash = {}, &block)
|
18
19
|
super
|
19
20
|
@app = app
|
20
21
|
end
|
21
22
|
|
23
|
+
def before_build(builder)
|
24
|
+
return unless options[:run_before_build]
|
25
|
+
return unless dependencies_installed?(builder)
|
26
|
+
Middleman::WebP::Converter.new(@app, options, builder).convert
|
27
|
+
end
|
28
|
+
|
22
29
|
def after_build(builder)
|
30
|
+
return if options[:run_before_build]
|
23
31
|
return unless dependencies_installed?(builder)
|
24
32
|
Middleman::WebP::Converter.new(@app, options, builder).convert
|
25
33
|
end
|
@@ -3,7 +3,7 @@ require 'middleman-webp/pathname_matcher'
|
|
3
3
|
module Middleman
|
4
4
|
module WebP
|
5
5
|
class Options
|
6
|
-
attr_reader :ignore, :verbose, :append_extension, :allow_skip
|
6
|
+
attr_reader :ignore, :verbose, :append_extension, :allow_skip, :run_before_build
|
7
7
|
|
8
8
|
def initialize(options = {})
|
9
9
|
@ignore = options[:ignore] || []
|
@@ -21,6 +21,7 @@ module Middleman
|
|
21
21
|
|
22
22
|
@append_extension = options[:append_extension] || false
|
23
23
|
@allow_skip = !(false == options[:allow_skip])
|
24
|
+
@run_before_build = options[:run_before_build] || false
|
24
25
|
end
|
25
26
|
|
26
27
|
# Internal: Generate command line args for cwebp or gif2webp command
|
@@ -33,7 +34,7 @@ module Middleman
|
|
33
34
|
|
34
35
|
return '' if matching.empty?
|
35
36
|
|
36
|
-
matching.sort { |(ga,
|
37
|
+
matching.sort { |(ga, _oa), (gb, _ob)| gb.size <=> ga.size }[0][1]
|
37
38
|
end
|
38
39
|
|
39
40
|
private
|
Binary file
|
Binary file
|
@@ -5,9 +5,6 @@ require_relative '../../lib/middleman-webp/extension'
|
|
5
5
|
describe Middleman::WebPExtension do
|
6
6
|
before do
|
7
7
|
@builder = Middleman::Cli::Build.new
|
8
|
-
@builder.expects(:say_status).once.with do |action, msg, opts|
|
9
|
-
action == :webp and msg =~ /Total conversion savings/
|
10
|
-
end
|
11
8
|
@builder.stubs(:say_status).with do |action, msg, opts|
|
12
9
|
action == :webp and msg =~ /Please install latest version of webp/
|
13
10
|
end
|
@@ -18,14 +15,84 @@ describe Middleman::WebPExtension do
|
|
18
15
|
Dir.glob('spec/fixtures/ok-build/**/*.webp').each do |file|
|
19
16
|
File.unlink(file)
|
20
17
|
end
|
18
|
+
Dir.glob('spec/fixtures/ok-source/**/*.webp').each do |file|
|
19
|
+
File.unlink(file)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#before_build' do
|
24
|
+
it 'does not generate WebP versions using external tools' do
|
25
|
+
app_mock = stub({
|
26
|
+
initialized: '',
|
27
|
+
instance_available: true,
|
28
|
+
after_configuration: nil,
|
29
|
+
before_build: nil,
|
30
|
+
after_build: nil,
|
31
|
+
inst: stub(source_dir: 'spec/fixtures/ok-source')
|
32
|
+
})
|
33
|
+
|
34
|
+
@builder.expects(:say_status).never.with do |action, msg, opts|
|
35
|
+
action == :webp and msg =~ /Total conversion savings/
|
36
|
+
end
|
37
|
+
|
38
|
+
@builder.expects(:say_status).never.with do |action, msg, opts|
|
39
|
+
action == :run and msg =~ /cwebp/
|
40
|
+
end
|
41
|
+
|
42
|
+
@builder.expects(:say_status).never.with do |action, msg, opts|
|
43
|
+
action == :webp and msg =~ /\.webp \([0-9.]+ % smaller\)/
|
44
|
+
end
|
45
|
+
|
46
|
+
@extension = Middleman::WebPExtension.new(app_mock)
|
47
|
+
@extension.before_build(@builder)
|
48
|
+
|
49
|
+
Dir.glob('spec/fixtures/ok-source/**/*.webp').size.must_equal 0
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'generates WebP versions using external tools when option is set' do
|
53
|
+
app_mock = stub({
|
54
|
+
initialized: '',
|
55
|
+
instance_available: true,
|
56
|
+
after_configuration: nil,
|
57
|
+
before_build: nil,
|
58
|
+
after_build: nil,
|
59
|
+
inst: stub(source_dir: 'spec/fixtures/ok-source')
|
60
|
+
})
|
61
|
+
|
62
|
+
@builder.expects(:say_status).once.with do |action, msg, opts|
|
63
|
+
action == :webp and msg =~ /Total conversion savings/
|
64
|
+
end
|
65
|
+
|
66
|
+
@builder.expects(:say_status).twice.with do |action, msg, opts|
|
67
|
+
action == :run and msg =~ /cwebp/
|
68
|
+
end
|
69
|
+
|
70
|
+
@builder.expects(:say_status).twice.with do |action, msg, opts|
|
71
|
+
action == :webp and msg =~ /\.webp \([0-9.]+ % smaller\)/
|
72
|
+
end
|
73
|
+
|
74
|
+
@extension = Middleman::WebPExtension.new(app_mock) do |webp|
|
75
|
+
webp.run_before_build = true
|
76
|
+
end
|
77
|
+
@extension.before_build(@builder)
|
78
|
+
|
79
|
+
Dir.glob('spec/fixtures/ok-source/**/*.webp').size.must_equal 2
|
80
|
+
end
|
21
81
|
end
|
22
82
|
|
23
83
|
describe '#after_build' do
|
84
|
+
before do
|
85
|
+
@builder.expects(:say_status).once.with do |action, msg, opts|
|
86
|
+
action == :webp and msg =~ /Total conversion savings/
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
24
90
|
it 'generates WebP versions using external tools' do
|
25
91
|
app_mock = stub({
|
26
92
|
initialized: '',
|
27
93
|
instance_available: true,
|
28
94
|
after_configuration: nil,
|
95
|
+
before_build: nil,
|
29
96
|
after_build: nil,
|
30
97
|
inst: stub(build_dir: 'spec/fixtures/ok-build')
|
31
98
|
})
|
@@ -49,6 +116,7 @@ describe Middleman::WebPExtension do
|
|
49
116
|
initialized: '',
|
50
117
|
instance_available: true,
|
51
118
|
after_configuration: nil,
|
119
|
+
before_build: nil,
|
52
120
|
after_build: nil,
|
53
121
|
inst: stub(build_dir: 'spec/fixtures/dummy-build')
|
54
122
|
})
|
@@ -69,6 +137,7 @@ describe Middleman::WebPExtension do
|
|
69
137
|
initialized: '',
|
70
138
|
instance_available: true,
|
71
139
|
after_configuration: nil,
|
140
|
+
before_build: nil,
|
72
141
|
after_build: nil,
|
73
142
|
inst: stub(build_dir: 'spec/fixtures/dummy-build')
|
74
143
|
})
|
data/spec/unit/extension_spec.rb
CHANGED
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juhamatti Niemelä
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04
|
11
|
+
date: 2015-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman-core
|
@@ -94,6 +94,8 @@ files:
|
|
94
94
|
- spec/fixtures/dummy-build/empty.png
|
95
95
|
- spec/fixtures/ok-build/lizard.jpg
|
96
96
|
- spec/fixtures/ok-build/tux.png
|
97
|
+
- spec/fixtures/ok-source/lizard.jpg
|
98
|
+
- spec/fixtures/ok-source/tux.png
|
97
99
|
- spec/integration/extension_spec.rb
|
98
100
|
- spec/spec_helper.rb
|
99
101
|
- spec/unit/converter_spec.rb
|
@@ -131,6 +133,8 @@ test_files:
|
|
131
133
|
- spec/fixtures/dummy-build/empty.png
|
132
134
|
- spec/fixtures/ok-build/lizard.jpg
|
133
135
|
- spec/fixtures/ok-build/tux.png
|
136
|
+
- spec/fixtures/ok-source/lizard.jpg
|
137
|
+
- spec/fixtures/ok-source/tux.png
|
134
138
|
- spec/integration/extension_spec.rb
|
135
139
|
- spec/spec_helper.rb
|
136
140
|
- spec/unit/converter_spec.rb
|