rails-webp 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71dc74349b769d210dfac65270ca98c18370085679b7dc65571a4561cf502b3a
4
- data.tar.gz: ade953a26071ceab38f52137acb6188d2805d9641629fc7831f778666dff270f
3
+ metadata.gz: 203dee14382dff0553e80615b22cbeef3c90da0ccc2814fc2f39ead713df21c6
4
+ data.tar.gz: db6672407cd1d0ed86648502bef383dc933430bd300bb3902310f2df0bf8db21
5
5
  SHA512:
6
- metadata.gz: 6e141952f99a18c8063373a4fc0480620856d857873ce7eb6c7e19b6cdfa6c707344cee1bed6e2c40404e9515febf5f62634dbfdc05d3db9965d0b505bf013ba
7
- data.tar.gz: 960db331883e44ca712d049faabfdceaf35863018e5252fa5fe47c1d053f5ee62c254fb3efdc27b15578adc8ab9f43aebcb506ba17b9a933ae4dfe28918c0adb
6
+ metadata.gz: 6d6dfb860d0d70c74bcbe2e87caa545390d5915bf1afa8be0b1f98cd13caed4c9496a2493c4311d383dfe107a553d81e33a3d86ecea94fdac2ebf4787b8adb75
7
+ data.tar.gz: f007930e336d12726fdd78866603e24f17f7af6afb3c104c971e0b8f59f14d93bc3221ab0ef8011727b2cef939257b2721f2e608c2520dbef3b659e4dfa8f654
data/.gitignore CHANGED
@@ -9,3 +9,5 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ .DS_Store
@@ -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
- byebug (11.0.1)
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)
@@ -0,0 +1 @@
1
+ require 'rails/webp'
@@ -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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Rails
2
2
  module WebP
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
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.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-22 00:00:00.000000000 Z
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