rails-webp 0.1.1 → 0.1.2
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/.gitignore +2 -0
- data/Gemfile.lock +100 -3
- data/lib/rails-webp.rb +1 -0
- data/lib/rails/webp.rb +5 -1
- data/lib/rails/webp/converter.rb +22 -15
- data/lib/rails/webp/version.rb +1 -1
- data/rails-webp-0.1.1.gem +0 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 203dee14382dff0553e80615b22cbeef3c90da0ccc2814fc2f39ead713df21c6
|
4
|
+
data.tar.gz: db6672407cd1d0ed86648502bef383dc933430bd300bb3902310f2df0bf8db21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d6dfb860d0d70c74bcbe2e87caa545390d5915bf1afa8be0b1f98cd13caed4c9496a2493c4311d383dfe107a553d81e33a3d86ecea94fdac2ebf4787b8adb75
|
7
|
+
data.tar.gz: f007930e336d12726fdd78866603e24f17f7af6afb3c104c971e0b8f59f14d93bc3221ab0ef8011727b2cef939257b2721f2e608c2520dbef3b659e4dfa8f654
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,15 +1,99 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rails-webp (0.1)
|
4
|
+
rails-webp (0.1.2)
|
5
5
|
mini_magick
|
6
|
+
rails
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
|
-
|
11
|
+
actioncable (5.0.7.2)
|
12
|
+
actionpack (= 5.0.7.2)
|
13
|
+
nio4r (>= 1.2, < 3.0)
|
14
|
+
websocket-driver (~> 0.6.1)
|
15
|
+
actionmailer (5.0.7.2)
|
16
|
+
actionpack (= 5.0.7.2)
|
17
|
+
actionview (= 5.0.7.2)
|
18
|
+
activejob (= 5.0.7.2)
|
19
|
+
mail (~> 2.5, >= 2.5.4)
|
20
|
+
rails-dom-testing (~> 2.0)
|
21
|
+
actionpack (5.0.7.2)
|
22
|
+
actionview (= 5.0.7.2)
|
23
|
+
activesupport (= 5.0.7.2)
|
24
|
+
rack (~> 2.0)
|
25
|
+
rack-test (~> 0.6.3)
|
26
|
+
rails-dom-testing (~> 2.0)
|
27
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
28
|
+
actionview (5.0.7.2)
|
29
|
+
activesupport (= 5.0.7.2)
|
30
|
+
builder (~> 3.1)
|
31
|
+
erubis (~> 2.7.0)
|
32
|
+
rails-dom-testing (~> 2.0)
|
33
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
34
|
+
activejob (5.0.7.2)
|
35
|
+
activesupport (= 5.0.7.2)
|
36
|
+
globalid (>= 0.3.6)
|
37
|
+
activemodel (5.0.7.2)
|
38
|
+
activesupport (= 5.0.7.2)
|
39
|
+
activerecord (5.0.7.2)
|
40
|
+
activemodel (= 5.0.7.2)
|
41
|
+
activesupport (= 5.0.7.2)
|
42
|
+
arel (~> 7.0)
|
43
|
+
activesupport (5.0.7.2)
|
44
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
45
|
+
i18n (>= 0.7, < 2)
|
46
|
+
minitest (~> 5.1)
|
47
|
+
tzinfo (~> 1.1)
|
48
|
+
arel (7.1.4)
|
49
|
+
builder (3.2.3)
|
50
|
+
concurrent-ruby (1.1.5)
|
51
|
+
crass (1.0.4)
|
11
52
|
diff-lcs (1.3)
|
53
|
+
erubis (2.7.0)
|
54
|
+
globalid (0.4.2)
|
55
|
+
activesupport (>= 4.2.0)
|
56
|
+
i18n (1.1.1)
|
57
|
+
concurrent-ruby (~> 1.0)
|
58
|
+
loofah (2.2.3)
|
59
|
+
crass (~> 1.0.2)
|
60
|
+
nokogiri (>= 1.5.9)
|
61
|
+
mail (2.7.1)
|
62
|
+
mini_mime (>= 0.1.1)
|
63
|
+
method_source (0.8.2)
|
12
64
|
mini_magick (4.9.3)
|
65
|
+
mini_mime (1.0.1)
|
66
|
+
mini_portile2 (2.4.0)
|
67
|
+
minitest (5.11.3)
|
68
|
+
nio4r (2.3.1)
|
69
|
+
nokogiri (1.10.1)
|
70
|
+
mini_portile2 (~> 2.4.0)
|
71
|
+
rack (2.0.6)
|
72
|
+
rack-test (0.6.3)
|
73
|
+
rack (>= 1.0)
|
74
|
+
rails (5.0.7.2)
|
75
|
+
actioncable (= 5.0.7.2)
|
76
|
+
actionmailer (= 5.0.7.2)
|
77
|
+
actionpack (= 5.0.7.2)
|
78
|
+
actionview (= 5.0.7.2)
|
79
|
+
activejob (= 5.0.7.2)
|
80
|
+
activemodel (= 5.0.7.2)
|
81
|
+
activerecord (= 5.0.7.2)
|
82
|
+
activesupport (= 5.0.7.2)
|
83
|
+
bundler (>= 1.3.0)
|
84
|
+
railties (= 5.0.7.2)
|
85
|
+
sprockets-rails (>= 2.0.0)
|
86
|
+
rails-dom-testing (2.0.3)
|
87
|
+
activesupport (>= 4.2.0)
|
88
|
+
nokogiri (>= 1.6)
|
89
|
+
rails-html-sanitizer (1.0.4)
|
90
|
+
loofah (~> 2.2, >= 2.2.2)
|
91
|
+
railties (5.0.7.2)
|
92
|
+
actionpack (= 5.0.7.2)
|
93
|
+
activesupport (= 5.0.7.2)
|
94
|
+
method_source
|
95
|
+
rake (>= 0.8.7)
|
96
|
+
thor (>= 0.18.1, < 2.0)
|
13
97
|
rake (10.5.0)
|
14
98
|
rspec (3.8.0)
|
15
99
|
rspec-core (~> 3.8.0)
|
@@ -24,13 +108,26 @@ GEM
|
|
24
108
|
diff-lcs (>= 1.2.0, < 2.0)
|
25
109
|
rspec-support (~> 3.8.0)
|
26
110
|
rspec-support (3.8.0)
|
111
|
+
sprockets (3.7.2)
|
112
|
+
concurrent-ruby (~> 1.0)
|
113
|
+
rack (> 1, < 3)
|
114
|
+
sprockets-rails (3.2.1)
|
115
|
+
actionpack (>= 4.0)
|
116
|
+
activesupport (>= 4.0)
|
117
|
+
sprockets (>= 3.0.0)
|
118
|
+
thor (0.19.4)
|
119
|
+
thread_safe (0.3.6)
|
120
|
+
tzinfo (1.2.5)
|
121
|
+
thread_safe (~> 0.1)
|
122
|
+
websocket-driver (0.6.5)
|
123
|
+
websocket-extensions (>= 0.1.0)
|
124
|
+
websocket-extensions (0.1.3)
|
27
125
|
|
28
126
|
PLATFORMS
|
29
127
|
ruby
|
30
128
|
|
31
129
|
DEPENDENCIES
|
32
130
|
bundler (~> 2.0)
|
33
|
-
byebug
|
34
131
|
rails-webp!
|
35
132
|
rake (~> 10.0)
|
36
133
|
rspec (~> 3.0)
|
data/lib/rails-webp.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rails/webp'
|
data/lib/rails/webp.rb
CHANGED
@@ -9,12 +9,16 @@ module Rails
|
|
9
9
|
class Error < StandardError; end
|
10
10
|
|
11
11
|
class << self
|
12
|
-
attr_writer :encode_options, :force
|
12
|
+
attr_writer :encode_options, :exclude_dir_regex, :force
|
13
13
|
|
14
14
|
def encode_options
|
15
15
|
@encode_options ||= { quality: 80, lossless: true, method: 6, alpha_filtering: 2, alpha_compression: 0, alpha_quality: 100 }
|
16
16
|
end
|
17
17
|
|
18
|
+
def exclude_dir_regex
|
19
|
+
@exclude_dir_regex ||= nil
|
20
|
+
end
|
21
|
+
|
18
22
|
# Source assets that are unchanged will not be processed by default.
|
19
23
|
# Set this to true if you wish to process webp images anyway.
|
20
24
|
def force
|
data/lib/rails/webp/converter.rb
CHANGED
@@ -8,21 +8,6 @@ module Rails
|
|
8
8
|
class << self
|
9
9
|
attr_reader :context
|
10
10
|
|
11
|
-
def process(input_path, data, context)
|
12
|
-
@context = context
|
13
|
-
app = Rails.application
|
14
|
-
prefix = app.config.assets.prefix
|
15
|
-
digest = data_digest(data)
|
16
|
-
webp_file = webp_file_name(data, digest)
|
17
|
-
output_path = Pathname.new(File.join(app.root, 'public', prefix, webp_file))
|
18
|
-
if WebP.force || !webp_file_exists?(digest, output_path)
|
19
|
-
FileUtils.mkdir_p(output_path.dirname) unless Dir.exists?(output_path.dirname)
|
20
|
-
convert_to_webp(input_path, output_path)
|
21
|
-
logger.info "Writing #{output_path}"
|
22
|
-
end
|
23
|
-
data
|
24
|
-
end
|
25
|
-
|
26
11
|
def convert_to_webp(input_path, output_path)
|
27
12
|
# Ex: convert wizard.png -quality 50 -define webp:lossless=true wizard.webp
|
28
13
|
MiniMagick::Tool::Convert.new do |convert|
|
@@ -36,12 +21,34 @@ module Rails
|
|
36
21
|
end
|
37
22
|
end
|
38
23
|
|
24
|
+
def process(input_path, data, context, app = Rails.application)
|
25
|
+
return data if excluded_dir?(input_path)
|
26
|
+
@context = context
|
27
|
+
prefix = app.config.assets.prefix
|
28
|
+
digest = data_digest(data)
|
29
|
+
webp_file = webp_file_name(data, digest)
|
30
|
+
output_path = Pathname.new(File.join(app.root, 'public', prefix, webp_file))
|
31
|
+
if WebP.force || !webp_file_exists?(digest, output_path)
|
32
|
+
FileUtils.mkdir_p(output_path.dirname) unless Dir.exists?(output_path.dirname)
|
33
|
+
# TODO: check app.assets.gzip and act accordingly
|
34
|
+
convert_to_webp(input_path, output_path)
|
35
|
+
logger&.info "Writing #{output_path}"
|
36
|
+
end
|
37
|
+
data
|
38
|
+
end
|
39
|
+
|
39
40
|
private
|
40
41
|
|
41
42
|
def data_digest(data)
|
42
43
|
"-#{context.environment.digest_class.new.update(data).to_s}"
|
43
44
|
end
|
44
45
|
|
46
|
+
def excluded_dir?(path)
|
47
|
+
regex = WebP.exclude_dir_regex
|
48
|
+
return false unless regex
|
49
|
+
!!path.match(regex)
|
50
|
+
end
|
51
|
+
|
45
52
|
def webp_file_name(data, digest)
|
46
53
|
file_name = context.logical_path # Original File name w/o extension
|
47
54
|
file_ext = context.pathname.extname # Original File extension
|
data/lib/rails/webp/version.rb
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-webp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jake Peterson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -98,11 +98,13 @@ files:
|
|
98
98
|
- Rakefile
|
99
99
|
- bin/console
|
100
100
|
- bin/setup
|
101
|
+
- lib/rails-webp.rb
|
101
102
|
- lib/rails/webp.rb
|
102
103
|
- lib/rails/webp/converter.rb
|
103
104
|
- lib/rails/webp/post_processor.rb
|
104
105
|
- lib/rails/webp/railtie.rb
|
105
106
|
- lib/rails/webp/version.rb
|
107
|
+
- rails-webp-0.1.1.gem
|
106
108
|
- rails-webp-0.1.gem
|
107
109
|
- rails-webp.gemspec
|
108
110
|
homepage: https://github.com/jakenberg
|