middleman-images 0.1.0 → 0.2.0

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: 964a7c5425a22aaef41c52646d09bb031e96d651635667f9cc559c02138f9311
4
- data.tar.gz: ec12a1b00e31d5d597dd081f9f7adfe862e034cab41945113ee11cfdf4ec6b97
3
+ metadata.gz: f00d10aeb0db6ab714537b15b0d07a71e034a08b45e7fc5e8dcdfa9713abdc3d
4
+ data.tar.gz: aa863f277ff04b872d6641275a3ca5444c888037f2d56c47ee1f3a99ee1f5098
5
5
  SHA512:
6
- metadata.gz: c082d6cc1dfbe762e4c6e9c908e135a8b03d2e120bad55a73e8e67b52a4ab76e2f8c8ddcaf56f0b8b1e9f632570918f1a5f628b2c0b9842a0b71247d8668d2c5
7
- data.tar.gz: afc35215b01e2b7543f00c58fd4952b0c71fa3438791e1d8e774ec43468693ee2212daf159fb69ab47e4c184e2ec2c372a37c1643241aa7e52975a43619b4614
6
+ metadata.gz: e89daa6f803d8687fc89477e12d5986d10187c6adccf891a819f5be58cd49a7af2000c1f606fe0ea7e76dadebf7284bffa1f0de435e3216b6a59401f4a65847a
7
+ data.tar.gz: 990ee4608b982912eaa3973beaaf898c9f90eb2c36556a66960c7ae9f8ce38e730e745ef1c1bf3f727b0ef1934af09434e172c76da74661a56149df1b9239471
data/.rufo ADDED
@@ -0,0 +1 @@
1
+ includes [gemfiles/Gemfile.*[!l][!o][!c][!k]]
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
-
3
2
  cache: bundler
4
- before_script:
5
- - gem install bundler:1.17.3
3
+ before_script: gem install bundler:1.17.3
4
+ script: bundle exec cucumber
5
+
6
6
  rvm:
7
7
  - 2.7
8
8
  - 2.6
@@ -23,7 +23,7 @@ jobs:
23
23
  gemfile: gemfiles/Gemfile.middleman-4.2
24
24
  - rvm: 2.7
25
25
  gemfile: gemfiles/Gemfile.middleman-4.1
26
- allow_failures:
27
- - gemfile: gemfiles/Gemfile.middleman-5.0-rc
28
-
29
- script: bundle exec rake test
26
+ include:
27
+ - rvm: 2.7
28
+ gemfile: Gemfile
29
+ script: bundle exec rufo -c .
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.2.0] - 2020-08-05
10
+ ### Added
11
+ - Support for Middleman 5 RC
12
+ ### Changed
13
+ - We changed the way images get registered while running the Middleman server.
14
+ This should bring way better performance and make this Gem usable in server mode.
15
+
9
16
  ## [0.1.0] - 2020-02-05
10
17
  ### Added
11
18
  - Do not resize SVG or GIF files.
@@ -28,5 +35,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
28
35
  ### Removed
29
36
  - Removed support for Ruby < 2.5
30
37
 
31
- [Unreleased]: https://github.com/zweitag/middleman-images/compare/v0.1.0...HEAD
38
+ [Unreleased]: https://github.com/zweitag/middleman-images/compare/v0.2.0...HEAD
39
+ [0.2.0]: https://github.com/zweitag/middleman-images/compare/v0.1.0...v0.2.0
32
40
  [0.1.0]: https://github.com/zweitag/middleman-images/releases/tag/v0.1.0
data/Gemfile CHANGED
@@ -1,26 +1,18 @@
1
1
  # If you do not have OpenSSL installed, update
2
2
  # the following line to use "http://" instead
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in middleman-images.gemspec
6
6
  gemspec
7
7
 
8
- group :development do
9
- gem 'middleman', '~> 4.3'
10
- gem 'rake'
11
- gem 'rdoc'
12
- gem 'yard'
13
- end
8
+ gem "middleman", "~> 4.3"
14
9
 
15
- group :test do
16
- gem 'cucumber'
17
- gem 'capybara'
18
- gem 'aruba'
19
- gem 'rspec'
10
+ gem "aruba"
11
+ gem "capybara"
12
+ gem "cucumber"
13
+ gem "rufo"
20
14
 
21
- gem 'image_optim'
22
- gem 'mini_magick'
23
-
24
- # Version is locked to make sure asset_hash tests are not broken by updated optimizations.
25
- gem 'image_optim_pack', '=0.6.0'
26
- end
15
+ gem "image_optim"
16
+ # Version is locked to make sure asset_hash tests are not broken by updated optimizations.
17
+ gem "image_optim_pack", "=0.6.0"
18
+ gem "mini_magick"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- middleman-images (0.1.0)
4
+ middleman-images (0.2.0)
5
5
  middleman-core (>= 4.1.14)
6
6
 
7
7
  GEM
@@ -125,7 +125,7 @@ GEM
125
125
  minitest (5.14.0)
126
126
  multi_json (1.14.1)
127
127
  multi_test (0.1.2)
128
- nokogiri (1.10.7)
128
+ nokogiri (1.10.8)
129
129
  mini_portile2 (~> 2.4.0)
130
130
  padrino-helpers (0.13.3.4)
131
131
  i18n (~> 0.6, >= 0.6.7)
@@ -136,28 +136,18 @@ GEM
136
136
  parallel (1.19.1)
137
137
  progress (3.5.2)
138
138
  public_suffix (4.0.3)
139
- rack (2.1.2)
139
+ rack (2.2.3)
140
140
  rack-test (1.1.0)
141
141
  rack (>= 1.0, < 3)
142
- rake (13.0.1)
143
142
  rb-fsevent (0.10.3)
144
143
  rb-inotify (0.10.1)
145
144
  ffi (~> 1.0)
146
- rdoc (6.2.1)
147
145
  regexp_parser (1.6.0)
148
- rspec (3.9.0)
149
- rspec-core (~> 3.9.0)
150
- rspec-expectations (~> 3.9.0)
151
- rspec-mocks (~> 3.9.0)
152
- rspec-core (3.9.1)
153
- rspec-support (~> 3.9.1)
154
146
  rspec-expectations (3.9.0)
155
147
  diff-lcs (>= 1.2.0, < 2.0)
156
148
  rspec-support (~> 3.9.0)
157
- rspec-mocks (3.9.1)
158
- diff-lcs (>= 1.2.0, < 2.0)
159
- rspec-support (~> 3.9.0)
160
149
  rspec-support (3.9.2)
150
+ rufo (0.12.0)
161
151
  sassc (2.2.1)
162
152
  ffi (~> 1.9)
163
153
  servolux (0.13.0)
@@ -171,7 +161,6 @@ GEM
171
161
  execjs (>= 0.3.0, < 3)
172
162
  xpath (3.2.0)
173
163
  nokogiri (~> 1.8)
174
- yard (0.9.24)
175
164
 
176
165
  PLATFORMS
177
166
  ruby
@@ -185,10 +174,7 @@ DEPENDENCIES
185
174
  middleman (~> 4.3)
186
175
  middleman-images!
187
176
  mini_magick
188
- rake
189
- rdoc
190
- rspec
191
- yard
177
+ rufo
192
178
 
193
179
  BUNDLED WITH
194
180
  2.1.4
data/README.md CHANGED
@@ -43,37 +43,34 @@ For more information check [`image_optim_pack`](https://github.com/toy/image_opt
43
43
  To activate the extension just put this into your `config.rb`:
44
44
 
45
45
  ```ruby
46
- configure :build do
47
- activate :images
48
- end
46
+ activate :images
49
47
  ```
50
48
 
51
- Although it is possible to activate the extension in development mode, we do
52
- not recommend this. Since this will radically drain the performance.
49
+ With Middleman images activated, starting the Middleman server will take some time.
50
+ During that time images that need procssing will get registered.
51
+ The actual processing of the images takes place while navigating the page.
53
52
 
54
53
  Configure the extension by passing a block to `:activate`:
55
54
 
56
55
  ```ruby
57
- configure :build do
58
- activate :images do |images|
59
- # Do not include original images in the build (default: false)
60
- images.ignore_original = true
61
-
62
- # Specify another cache directory depending on your root directory (default: 'cache')
63
- images.cache_dir = 'funky_cache/subdir_of_funky_cache'
64
-
65
- # Optimize images (default: false)
66
- images.optimize = true
67
-
68
- # Provide additional options for image_optim
69
- # See https://github.com/toy/image_optim for all available options
70
- images.image_optim = {
71
- nice: 20,
72
- optipng: {
73
- level: 5,
74
- },
75
- }
76
- end
56
+ activate :images do |images|
57
+ # Do not include original images in the build (default: false)
58
+ images.ignore_original = true
59
+
60
+ # Specify another cache directory depending on your root directory (default: 'cache')
61
+ images.cache_dir = 'funky_cache/subdir_of_funky_cache'
62
+
63
+ # Optimize images (default: false)
64
+ images.optimize = true
65
+
66
+ # Provide additional options for image_optim
67
+ # See https://github.com/toy/image_optim for all available options
68
+ images.image_optim = {
69
+ nice: 20,
70
+ optipng: {
71
+ level: 5,
72
+ },
73
+ }
77
74
  end
78
75
  ```
79
76
 
@@ -31,8 +31,10 @@ Feature: Building images
31
31
  """
32
32
  And the Server is running
33
33
  And I go to "/first.html"
34
+ And I go to "/images/fox-opt.jpg"
34
35
  And a modification time for a file named "cache/images/fox-opt.jpg"
35
- When I go to "/second.html"
36
+ And I go to "/second.html"
37
+ When I go to "/images/fox-opt.jpg"
36
38
  Then the file "cache/images/fox-opt.jpg" should exist
37
39
  Then the file "cache/images/fox-opt.jpg" should not have been updated
38
40
 
@@ -0,0 +1,33 @@
1
+ Feature: images_dir configuration given
2
+
3
+ Scenario: Building correctly
4
+ Given a fixture app "image"
5
+ And a middleman configuration with:
6
+ """
7
+ set :images_dir, 'assets/images'
8
+ """
9
+ And our extension is enabled
10
+ And a template named "index.html.erb" with:
11
+ """
12
+ <%= image_tag 'fox.jpg', optimize: true, resize: 400 %>
13
+ """
14
+ When a successfully built app at "image"
15
+ When I cd to "build/assets/images"
16
+ Then a file named "fox-400-opt.jpg" should exist
17
+
18
+ Scenario: Running correctly
19
+ Given a fixture app "image"
20
+ And a middleman configuration with:
21
+ """
22
+ set :images_dir, 'assets/images'
23
+ """
24
+ And our extension is enabled
25
+ And a template named "index.html.erb" with:
26
+ """
27
+ <%= image_tag 'fox.jpg', optimize: true, resize: 400 %>
28
+ """
29
+ And the Server is running
30
+ When I go to "/index.html"
31
+ Then I should see '<img src="/assets/images/fox-400-opt.jpg" alt="Fox" />'
32
+ When I go to "/assets/images/fox-400-opt.jpg"
33
+ Then the status code should be "200"
@@ -0,0 +1,39 @@
1
+
2
+ Feature: Proxy resources
3
+
4
+ Scenario: Resizing images for a proxy resource on build
5
+ Given a fixture app "image"
6
+ And a middleman configuration with:
7
+ """
8
+ activate :i18n, langs: [:en, :de], mount_at_root: false
9
+ """
10
+ And our extension is enabled
11
+ And a template named "localizable/index.html.erb" with:
12
+ """
13
+ <%= image_tag 'fox.jpg', resize: (I18n.locale == :en ? 400 : 500) %>
14
+ """
15
+ When a successfully built app at "image"
16
+ When I cd to "build/images"
17
+ Then a file named "fox-400.jpg" should exist
18
+ And a file named "fox-500.jpg" should exist
19
+
20
+ Scenario: Resizing images for a proxy resource on server
21
+ Given a fixture app "image"
22
+ And a middleman configuration with:
23
+ """
24
+ activate :i18n, langs: [:en, :de], mount_at_root: false
25
+ """
26
+ And our extension is enabled
27
+ And a template named "localizable/index.html.erb" with:
28
+ """
29
+ <%= image_tag 'fox.jpg', resize: (I18n.locale == :en ? 400 : 500) %>
30
+ """
31
+ And the Server is running
32
+ When I go to "/en/index.html"
33
+ Then I should see '<img src="/images/fox-400.jpg" alt="Fox" />'
34
+ When I go to "/images/fox-400.jpg"
35
+ Then the status code should be "200"
36
+ When I go to "/de/index.html"
37
+ Then I should see '<img src="/images/fox-500.jpg" alt="Fox" />'
38
+ When I go to "/images/fox-500.jpg"
39
+ Then the status code should be "200"
@@ -1,4 +1,4 @@
1
1
  PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
2
- require 'middleman-core'
3
- require 'middleman-core/step_definitions'
4
- require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-images')
2
+ require "middleman-core"
3
+ require "middleman-core/step_definitions"
4
+ require File.join(PROJECT_ROOT_PATH, "lib", "middleman-images")
@@ -1,11 +1,17 @@
1
- require 'mini_magick'
1
+ require "mini_magick"
2
+
3
+ Given /^a middleman configuration with:$/ do |config|
4
+ @middleman_config = config
5
+ end
2
6
 
3
7
  Given /^our extension is enabled?$/ do
4
- step 'our extension is enabled with:', ''
8
+ step "our extension is enabled with:", ""
5
9
  end
6
10
 
7
11
  Given /^our extension is enabled with:$/ do |config|
8
- config = """
12
+ config = "" "
13
+ #{@middleman_config}
14
+
9
15
  activate :images do |config|
10
16
  config.image_optim = {
11
17
  pngout: false,
@@ -13,7 +19,7 @@ Given /^our extension is enabled with:$/ do |config|
13
19
  }
14
20
  #{config}
15
21
  end
16
- """
22
+ " ""
17
23
  step 'a file named "config.rb" with:', config
18
24
  end
19
25
 
@@ -23,9 +29,9 @@ Then /^the dimensions should be (\d+)x(\d+)$/ do |x, y|
23
29
  end
24
30
 
25
31
  Then /^the content length should be equal to the file size of "([^\"]*)"$/ do |file|
26
- expect(page.response_headers['Content-Length'].to_i).to eq File.size(expand_path(file))
32
+ expect(page.response_headers["Content-Length"].to_i).to eq File.size(expand_path(file))
27
33
  end
28
34
 
29
35
  Then /^the content length should be smaller than the file size of "([^\"]*)"$/ do |file|
30
- expect(page.response_headers['Content-Length'].to_i).to be < File.size(expand_path(file))
36
+ expect(page.response_headers["Content-Length"].to_i).to be < File.size(expand_path(file))
31
37
  end
@@ -1,27 +1,17 @@
1
1
  # If you do not have OpenSSL installed, update
2
2
  # the following line to use "http://" instead
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in middleman-images.gemspec
6
- gemspec path: '..'
6
+ gemspec path: ".."
7
7
 
8
+ gem "middleman", "~> 4.1.0"
8
9
 
9
- group :development do
10
- gem 'middleman', '~> 4.1.0'
11
- gem 'rake'
12
- gem 'rdoc'
13
- gem 'yard'
14
- end
10
+ gem "aruba"
11
+ gem "capybara"
12
+ gem "cucumber"
15
13
 
16
- group :test do
17
- gem 'cucumber'
18
- gem 'capybara'
19
- gem 'aruba'
20
- gem 'rspec'
21
-
22
- gem 'image_optim'
23
- gem 'mini_magick'
24
-
25
- # Version is locked to make sure asset_hash tests are not broken by updated optimizations.
26
- gem 'image_optim_pack', '=0.6.0'
27
- end
14
+ gem "image_optim"
15
+ # Version is locked to make sure asset_hash tests are not broken by updated optimizations.
16
+ gem "image_optim_pack", "=0.6.0"
17
+ gem "mini_magick"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- middleman-images (0.1.0)
4
+ middleman-images (0.2.0)
5
5
  middleman-core (>= 4.1.14)
6
6
 
7
7
  GEM
@@ -142,24 +142,13 @@ GEM
142
142
  rack (2.1.2)
143
143
  rack-test (1.1.0)
144
144
  rack (>= 1.0, < 3)
145
- rake (13.0.1)
146
145
  rb-fsevent (0.10.3)
147
146
  rb-inotify (0.10.1)
148
147
  ffi (~> 1.0)
149
- rdoc (6.2.1)
150
148
  regexp_parser (1.6.0)
151
- rspec (3.9.0)
152
- rspec-core (~> 3.9.0)
153
- rspec-expectations (~> 3.9.0)
154
- rspec-mocks (~> 3.9.0)
155
- rspec-core (3.9.1)
156
- rspec-support (~> 3.9.1)
157
149
  rspec-expectations (3.9.0)
158
150
  diff-lcs (>= 1.2.0, < 2.0)
159
151
  rspec-support (~> 3.9.0)
160
- rspec-mocks (3.9.1)
161
- diff-lcs (>= 1.2.0, < 2.0)
162
- rspec-support (~> 3.9.0)
163
152
  rspec-support (3.9.2)
164
153
  sass (3.4.25)
165
154
  servolux (0.13.0)
@@ -173,7 +162,6 @@ GEM
173
162
  execjs (>= 0.3.0, < 3)
174
163
  xpath (3.2.0)
175
164
  nokogiri (~> 1.8)
176
- yard (0.9.24)
177
165
 
178
166
  PLATFORMS
179
167
  ruby
@@ -187,10 +175,6 @@ DEPENDENCIES
187
175
  middleman (~> 4.1.0)
188
176
  middleman-images!
189
177
  mini_magick
190
- rake
191
- rdoc
192
- rspec
193
- yard
194
178
 
195
179
  BUNDLED WITH
196
180
  1.17.3
@@ -1,27 +1,17 @@
1
1
  # If you do not have OpenSSL installed, update
2
2
  # the following line to use "http://" instead
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in middleman-images.gemspec
6
- gemspec path: '..'
6
+ gemspec path: ".."
7
7
 
8
+ gem "middleman", "~> 4.2.0"
8
9
 
9
- group :development do
10
- gem 'middleman', '~> 4.2.0'
11
- gem 'rake'
12
- gem 'rdoc'
13
- gem 'yard'
14
- end
10
+ gem "aruba"
11
+ gem "capybara"
12
+ gem "cucumber"
15
13
 
16
- group :test do
17
- gem 'cucumber'
18
- gem 'capybara'
19
- gem 'aruba'
20
- gem 'rspec'
21
-
22
- gem 'image_optim'
23
- gem 'mini_magick'
24
-
25
- # Version is locked to make sure asset_hash tests are not broken by updated optimizations.
26
- gem 'image_optim_pack', '=0.6.0'
27
- end
14
+ gem "image_optim"
15
+ # Version is locked to make sure asset_hash tests are not broken by updated optimizations.
16
+ gem "image_optim_pack", "=0.6.0"
17
+ gem "mini_magick"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- middleman-images (0.1.0)
4
+ middleman-images (0.2.0)
5
5
  middleman-core (>= 4.1.14)
6
6
 
7
7
  GEM
@@ -142,24 +142,13 @@ GEM
142
142
  rack (2.1.2)
143
143
  rack-test (1.1.0)
144
144
  rack (>= 1.0, < 3)
145
- rake (13.0.1)
146
145
  rb-fsevent (0.10.3)
147
146
  rb-inotify (0.10.1)
148
147
  ffi (~> 1.0)
149
- rdoc (6.2.1)
150
148
  regexp_parser (1.6.0)
151
- rspec (3.9.0)
152
- rspec-core (~> 3.9.0)
153
- rspec-expectations (~> 3.9.0)
154
- rspec-mocks (~> 3.9.0)
155
- rspec-core (3.9.1)
156
- rspec-support (~> 3.9.1)
157
149
  rspec-expectations (3.9.0)
158
150
  diff-lcs (>= 1.2.0, < 2.0)
159
151
  rspec-support (~> 3.9.0)
160
- rspec-mocks (3.9.1)
161
- diff-lcs (>= 1.2.0, < 2.0)
162
- rspec-support (~> 3.9.0)
163
152
  rspec-support (3.9.2)
164
153
  sass (3.4.25)
165
154
  servolux (0.13.0)
@@ -173,7 +162,6 @@ GEM
173
162
  execjs (>= 0.3.0, < 3)
174
163
  xpath (3.2.0)
175
164
  nokogiri (~> 1.8)
176
- yard (0.9.24)
177
165
 
178
166
  PLATFORMS
179
167
  ruby
@@ -187,10 +175,6 @@ DEPENDENCIES
187
175
  middleman (~> 4.2.0)
188
176
  middleman-images!
189
177
  mini_magick
190
- rake
191
- rdoc
192
- rspec
193
- yard
194
178
 
195
179
  BUNDLED WITH
196
180
  1.17.3
@@ -1,27 +1,17 @@
1
1
  # If you do not have OpenSSL installed, update
2
2
  # the following line to use "http://" instead
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in middleman-images.gemspec
6
- gemspec path: '..'
6
+ gemspec path: ".."
7
7
 
8
+ gem "middleman", "~> 4.3.0"
8
9
 
9
- group :development do
10
- gem 'middleman', '~> 4.3.0'
11
- gem 'rake'
12
- gem 'rdoc'
13
- gem 'yard'
14
- end
10
+ gem "aruba"
11
+ gem "capybara"
12
+ gem "cucumber"
15
13
 
16
- group :test do
17
- gem 'cucumber'
18
- gem 'capybara'
19
- gem 'aruba'
20
- gem 'rspec'
21
-
22
- gem 'image_optim'
23
- gem 'mini_magick'
24
-
25
- # Version is locked to make sure asset_hash tests are not broken by updated optimizations.
26
- gem 'image_optim_pack', '=0.6.0'
27
- end
14
+ gem "image_optim"
15
+ # Version is locked to make sure asset_hash tests are not broken by updated optimizations.
16
+ gem "image_optim_pack", "=0.6.0"
17
+ gem "mini_magick"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- middleman-images (0.1.0)
4
+ middleman-images (0.2.0)
5
5
  middleman-core (>= 4.1.14)
6
6
 
7
7
  GEM
@@ -139,24 +139,13 @@ GEM
139
139
  rack (2.1.2)
140
140
  rack-test (1.1.0)
141
141
  rack (>= 1.0, < 3)
142
- rake (13.0.1)
143
142
  rb-fsevent (0.10.3)
144
143
  rb-inotify (0.10.1)
145
144
  ffi (~> 1.0)
146
- rdoc (6.2.1)
147
145
  regexp_parser (1.6.0)
148
- rspec (3.9.0)
149
- rspec-core (~> 3.9.0)
150
- rspec-expectations (~> 3.9.0)
151
- rspec-mocks (~> 3.9.0)
152
- rspec-core (3.9.1)
153
- rspec-support (~> 3.9.1)
154
146
  rspec-expectations (3.9.0)
155
147
  diff-lcs (>= 1.2.0, < 2.0)
156
148
  rspec-support (~> 3.9.0)
157
- rspec-mocks (3.9.1)
158
- diff-lcs (>= 1.2.0, < 2.0)
159
- rspec-support (~> 3.9.0)
160
149
  rspec-support (3.9.2)
161
150
  sassc (2.2.1)
162
151
  ffi (~> 1.9)
@@ -171,7 +160,6 @@ GEM
171
160
  execjs (>= 0.3.0, < 3)
172
161
  xpath (3.2.0)
173
162
  nokogiri (~> 1.8)
174
- yard (0.9.24)
175
163
 
176
164
  PLATFORMS
177
165
  ruby
@@ -185,10 +173,6 @@ DEPENDENCIES
185
173
  middleman (~> 4.3.0)
186
174
  middleman-images!
187
175
  mini_magick
188
- rake
189
- rdoc
190
- rspec
191
- yard
192
176
 
193
177
  BUNDLED WITH
194
178
  2.1.4
@@ -1,27 +1,17 @@
1
1
  # If you do not have OpenSSL installed, update
2
2
  # the following line to use "http://" instead
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in middleman-images.gemspec
6
- gemspec path: '..'
6
+ gemspec path: ".."
7
7
 
8
+ gem "middleman", "~> 5.0.0.rc"
8
9
 
9
- group :development do
10
- gem 'middleman', '~> 5.0.0.rc'
11
- gem 'rake'
12
- gem 'rdoc'
13
- gem 'yard'
14
- end
10
+ gem "aruba"
11
+ gem "capybara"
12
+ gem "cucumber"
15
13
 
16
- group :test do
17
- gem 'cucumber'
18
- gem 'capybara'
19
- gem 'aruba'
20
- gem 'rspec'
21
-
22
- gem 'image_optim'
23
- gem 'mini_magick'
24
-
25
- # Version is locked to make sure asset_hash tests are not broken by updated optimizations.
26
- gem 'image_optim_pack', '=0.6.0'
27
- end
14
+ gem "image_optim"
15
+ # Version is locked to make sure asset_hash tests are not broken by updated optimizations.
16
+ gem "image_optim_pack", "=0.6.0"
17
+ gem "mini_magick"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- middleman-images (0.1.0)
4
+ middleman-images (0.2.0)
5
5
  middleman-core (>= 4.1.14)
6
6
 
7
7
  GEM
@@ -21,7 +21,7 @@ GEM
21
21
  ffi (~> 1.9)
22
22
  rspec-expectations (>= 2.99)
23
23
  thor (>= 0.19, < 2.0)
24
- backports (3.15.0)
24
+ backports (3.16.1)
25
25
  builder (3.2.4)
26
26
  capybara (3.31.0)
27
27
  addressable
@@ -140,27 +140,16 @@ GEM
140
140
  rack (2.1.2)
141
141
  rack-test (1.1.0)
142
142
  rack (>= 1.0, < 3)
143
- rake (13.0.1)
144
143
  rb-fsevent (0.10.3)
145
144
  rb-inotify (0.10.1)
146
145
  ffi (~> 1.0)
147
- rdoc (6.2.1)
148
146
  regexp_parser (1.6.0)
149
147
  rgl (0.5.6)
150
148
  lazy_priority_queue (~> 0.1.0)
151
149
  stream (~> 0.5.2)
152
- rspec (3.9.0)
153
- rspec-core (~> 3.9.0)
154
- rspec-expectations (~> 3.9.0)
155
- rspec-mocks (~> 3.9.0)
156
- rspec-core (3.9.1)
157
- rspec-support (~> 3.9.1)
158
150
  rspec-expectations (3.9.0)
159
151
  diff-lcs (>= 1.2.0, < 2.0)
160
152
  rspec-support (~> 3.9.0)
161
- rspec-mocks (3.9.1)
162
- diff-lcs (>= 1.2.0, < 2.0)
163
- rspec-support (~> 3.9.0)
164
153
  rspec-support (3.9.2)
165
154
  sassc (2.2.1)
166
155
  ffi (~> 1.9)
@@ -176,7 +165,6 @@ GEM
176
165
  execjs (>= 0.3.0, < 3)
177
166
  xpath (3.2.0)
178
167
  nokogiri (~> 1.8)
179
- yard (0.9.24)
180
168
 
181
169
  PLATFORMS
182
170
  ruby
@@ -190,10 +178,6 @@ DEPENDENCIES
190
178
  middleman (~> 5.0.0.rc)
191
179
  middleman-images!
192
180
  mini_magick
193
- rake
194
- rdoc
195
- rspec
196
- yard
197
181
 
198
182
  BUNDLED WITH
199
183
  2.1.4
@@ -1,56 +1,48 @@
1
- require 'middleman-core'
2
- require 'pathname'
3
- require 'padrino-helpers'
1
+ require "middleman-core"
2
+ require "pathname"
3
+ require "padrino-helpers"
4
4
 
5
5
  module Middleman
6
6
  module Images
7
7
  class Extension < ::Middleman::Extension
8
- option :optimize, false, 'Whether to optimize images by default'
9
- option :image_optim, {}, 'Default options for image_optim'
10
- option :ignore_original, false, 'Whether to ignore original images in build'
11
- option :cache_dir, 'cache', 'Specification of cache folder'
8
+ option :optimize, false, "Whether to optimize images by default"
9
+ option :image_optim, {}, "Default options for image_optim"
10
+ option :ignore_original, false, "Whether to ignore original images in build"
11
+ option :cache_dir, "cache", "Specification of cache folder"
12
12
 
13
13
  helpers do
14
- def image_tag(url, options = {})
14
+ def image_tag(path, options = {})
15
15
  process_options = options.slice(:resize, :optimize)
16
- options = { src: image_path(url, process_options) }.update(options.except(:resize, :optimize))
17
- super
16
+ options = { src: image_path(path, process_options) }.update(options.except(:resize, :optimize))
17
+ super(path, options)
18
18
  end
19
19
 
20
- def image_path(url, process_options = {})
21
- url = extensions[:images].image(url, process_options)
22
- super url
20
+ def image_path(path, process_options = {})
21
+ path = extensions[:images].image_path(path, process_options)
22
+ super(path)
23
23
  end
24
24
  end
25
25
 
26
- def template_context
27
- @template_context ||= app.template_context_class.new(app, {}, {})
26
+ def manipulate_resource_list(resources)
27
+ @manipulator.manipulate_resource_list(resources)
28
28
  end
29
29
 
30
- def process(source, process_options)
31
- destination_path(source, process_options).tap do |dest_url|
32
- unless app.sitemap.find_resource_by_path(dest_url)
33
- image = Image.new(app, source.source_file, dest_url, process_options.merge(cache_dir: options[:cache_dir]))
34
- manipulator.add image
35
- app.sitemap.register_resource_list_manipulator(:images, manipulator, 40) unless app.build?
36
- end
37
- end
38
- end
39
-
40
- def image(url, process_options)
41
- source = app.sitemap.find_resource_by_path(absolute_image_path(url))
42
- return url if source.nil?
30
+ def image_path(path, process_options)
31
+ source = app.sitemap.find_resource_by_path(absolute_path(path))
32
+ return path if source.nil?
43
33
 
44
34
  process_options[:image_optim] = options[:image_optim]
45
35
  process_options[:optimize] = options[:optimize] unless process_options.key?(:optimize)
46
36
 
47
37
  if process_options[:resize] || process_options[:optimize]
48
- url = process(source, process_options)
38
+ processed_path = Pathname.new(add_processed_resource(source, process_options))
39
+ images_dir = Pathname.new(app.config[:images_dir])
40
+ path = processed_path.relative_path_from(Pathname.new(app.config[:images_dir])).to_s
49
41
  else
50
- manipulator.preserve_original source
51
- app.sitemap.register_resource_list_manipulator(:images, manipulator, 40) unless app.build?
42
+ @manipulator.preserve_original source
52
43
  end
53
- url
44
+
45
+ path
54
46
  end
55
47
 
56
48
  def initialize(app, options_hash = {}, &block)
@@ -58,31 +50,25 @@ module Middleman
58
50
  @manipulator = Manipulator.new(@app, options[:ignore_original])
59
51
  end
60
52
 
61
- def before_build(builder)
62
- # trigger our image_tag helper
63
- rack = builder.instance_variable_get(:@rack)
64
-
65
- builder.app.logger.info "== Images: Looking for images to process"
66
- builder.app.sitemap.resources.each do |resource|
67
- rack.get(CGI.escape(resource.request_path)) unless resource.binary?
68
- end
69
- builder.app.sitemap.register_resource_list_manipulator(:images, manipulator, 40)
70
- end
71
-
72
53
  private
73
54
 
74
- attr_reader :manipulator
55
+ def absolute_path(path)
56
+ absolute_path = path.start_with?("/") || path.start_with?(app.config[:images_dir])
57
+ absolute_path ? path : app.config[:images_dir] + "/" + path
58
+ end
75
59
 
76
- def destination_path(source, options)
77
- destination = source.normalized_path.sub(/#{source.ext}$/, '')
78
- destination += '-' + template_context.escape_html(options[:resize]) if options[:resize]
79
- destination += '-opt' if options[:optimize]
80
- destination + source.ext
60
+ def add_processed_resource(source, process_options)
61
+ build_processed_path(source, process_options).tap do |processed_path|
62
+ processed_resource = Image.new(app.sitemap, processed_path, source.source_file, process_options.merge(cache_dir: options[:cache_dir]))
63
+ @manipulator.add(processed_resource)
64
+ end
81
65
  end
82
66
 
83
- def absolute_image_path(url)
84
- absolute_path = url.start_with?('/') || url.start_with?(app.config[:images_dir])
85
- absolute_path ? url : app.config[:images_dir] + '/' + url
67
+ def build_processed_path(source, process_options)
68
+ destination = source.normalized_path.sub(/#{source.ext}$/, "")
69
+ destination += "-" + CGI.escape(process_options[:resize].to_s) if process_options[:resize]
70
+ destination += "-opt" if process_options[:optimize]
71
+ destination + source.ext
86
72
  end
87
73
  end
88
74
  end
@@ -1,40 +1,56 @@
1
1
  module Middleman
2
2
  module Images
3
- class Image
4
- attr_reader :destination, :source
5
-
3
+ class Image < Middleman::Sitemap::Resource
6
4
  IGNORE_RESIZING = {
7
- ".svg" => "WARNING: We did not resize %{file}. Resizing SVG files will lead to ImageMagick creating an SVG with an embedded binary image thus making the file way bigger.",
8
- ".gif" => "WARNING: We did not resize %{file}. Resizing GIF files will remove the animation. If your GIF file is not animated, use JPG or PNG instead.",
5
+ ".svg" => "WARNING: We did not resize %{file}. Resizing SVG files will lead to ImageMagick creating an SVG with an embedded binary image thus making the file way bigger.",
6
+ ".gif" => "WARNING: We did not resize %{file}. Resizing GIF files will remove the animation. If your GIF file is not animated, use JPG or PNG instead.",
9
7
  }.freeze
10
8
 
11
- def initialize(app, source, destination, options = {})
12
- @app = app
13
- @source = source
14
- @destination = destination
15
- @options = options
16
- @cache = File.join(app.root, options[:cache_dir], destination).to_s
17
- FileUtils.mkdir_p File.dirname(cache)
9
+ attr_reader :app, :original_source_file
10
+
11
+ def initialize(store, path, source, options = {})
12
+ @original_source_file = source
13
+
14
+ processed_source_file = File.join(store.app.root, options.delete(:cache_dir), path)
15
+ FileUtils.mkdir_p File.dirname(processed_source_file)
16
+
17
+ @processing_options = options
18
+
19
+ super(store, path, processed_source_file)
18
20
  end
19
21
 
20
22
  def process
21
- return if File.exist?(cache) && File.mtime(source) < File.mtime(cache)
23
+ return if File.exist?(processed_source_file) && File.mtime(original_source_file) < File.mtime(processed_source_file)
24
+
25
+ app.logger.info "== Images: Processing #{@path}"
22
26
 
23
- app.logger.info "== Images: Processing #{destination}"
24
- FileUtils.copy(source, cache)
25
- resize(cache, options[:resize]) unless options[:resize].nil?
26
- optimize(cache, options[:image_optim]) if options[:optimize]
27
+ FileUtils.copy(original_source_file, processed_source_file)
28
+ resize(processed_source_file, @processing_options[:resize]) unless @processing_options[:resize].nil?
29
+ optimize(processed_source_file, @processing_options[:image_optim]) if @processing_options[:optimize]
27
30
  end
28
31
 
29
- def resource
30
- @resource ||= ::Middleman::Sitemap::Resource.new(app.sitemap, destination, cache)
32
+ # We want to process images as late as possible. Before Middleman works with our source file, it will check
33
+ # whether it is binary? or static_file?. That's when we need to ensure the processed source files exist.
34
+ def binary?
35
+ process
36
+ super
37
+ end
38
+
39
+ def static_file?
40
+ process
41
+ super
42
+ end
43
+
44
+ # The processed source file is the new source file for middleman.
45
+ def processed_source_file
46
+ source_file
31
47
  end
32
48
 
33
49
  private
34
50
 
35
51
  def resize(image_path, options)
36
52
  begin
37
- require 'mini_magick'
53
+ require "mini_magick"
38
54
  rescue LoadError
39
55
  raise 'The gem "mini_magick" is required for image resizing. Please install "mini_magick" or remove the resize option.'
40
56
  end
@@ -47,22 +63,20 @@ module Middleman
47
63
 
48
64
  image = MiniMagick::Image.new(image_path) do |i|
49
65
  i.resize(options)
50
- i.define('jpeg:preserve-settings')
66
+ i.define("jpeg:preserve-settings")
51
67
  end
52
68
  image.write image_path
53
69
  end
54
70
 
55
71
  def optimize(image_path, options)
56
72
  begin
57
- require 'image_optim'
73
+ require "image_optim"
58
74
  rescue LoadError
59
75
  raise "The gem 'image_option' is required for image optimization. Please install the gem 'image_optim' or set the option optimize: false."
60
76
  end
61
77
 
62
78
  ImageOptim.new(options).optimize_image!(image_path)
63
79
  end
64
-
65
- attr_accessor :app, :cache, :options
66
80
  end
67
81
  end
68
82
  end
@@ -6,12 +6,13 @@ module Middleman
6
6
  @images = []
7
7
  @required_originals = []
8
8
  @ignore_original = ignore_original
9
+ @inspected_at = {}
10
+ @destination_paths = []
9
11
  end
10
12
 
11
13
  def add(image)
12
- unless images.collect(&:destination).include? image.destination
13
- images << image
14
- end
14
+ images << image unless @destination_paths.include?(image.destination_path)
15
+ @destination_paths << image.destination_path
15
16
  end
16
17
 
17
18
  def preserve_original(resource)
@@ -19,28 +20,54 @@ module Middleman
19
20
  end
20
21
 
21
22
  def manipulate_resource_list(resources)
23
+ app.logger.info "== Images: Registering images to process. This may take a while…"
24
+
25
+ resources.each do |resource|
26
+ next unless inspect?(resource)
27
+
28
+ app.logger.debug "== Images: Inspecting #{resource.destination_path} for images to process."
29
+
30
+ begin
31
+ # We inspect templates by triggering the render method on them. This way our
32
+ # image_tag and image_path helpers will get called and register the images.
33
+ resource.render({}, {})
34
+ rescue => e
35
+ app.logger.debug e
36
+ app.logger.debug "== Images: There was an error inspecting #{resource.destination_path}. Images for this resource will not be processed."
37
+ end
38
+ end
39
+
40
+ app.logger.info "== Images: All images have been registered."
41
+
22
42
  ignore_orginal_resources(resources) if ignore_original
23
- resources + processed_images
43
+ resources + images
24
44
  end
25
45
 
26
46
  private
27
47
 
28
48
  attr_accessor :app, :images, :ignore_original, :required_originals
29
49
 
30
- def processed_images
31
- images.each(&:process)
32
- images.collect(&:resource)
50
+ def inspect?(resource)
51
+ return false unless resource.template?
52
+
53
+ inspected_at = @inspected_at[resource.destination_path]
54
+ return true if inspected_at.nil?
55
+
56
+ source_modification_time = File.mtime(resource.source_file)
57
+ inspected_at < source_modification_time.tap do |inspect|
58
+ @inspected_at[resource.destination_path] = source_modification_time if inspect
59
+ end
33
60
  end
34
61
 
35
62
  def ignore_orginal_resources(resources)
36
- originals = images.map(&:source)
63
+ originals = images.map(&:original_source_file)
37
64
  unused_originals = originals - required_originals
38
65
 
39
66
  resources.each do |resource|
40
67
  if unused_originals.include? resource.source_file
41
68
  resource.ignore!
42
69
  elsif required_originals.include? resource.source_file
43
- resource.ignored = false
70
+ resource.instance_variable_set(:@ignored, false)
44
71
  end
45
72
  end
46
73
  end
@@ -1,3 +1,3 @@
1
1
  module MiddlemanImages
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -3,21 +3,25 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
  require "middleman-images/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "middleman-images"
7
- s.version = MiddlemanImages::VERSION.dup
8
- s.platform = Gem::Platform::RUBY
9
- s.licenses = ["MIT"]
10
- s.authors = ["Ruben Grimm", "Julian Schneider"]
11
- s.email = ["ruben.grimm@zweitag.de", "julian.schneider@zweitag.de"]
12
- s.homepage = "https://www.github.com/zweitag/middleman-images"
13
- s.summary = "Resize and optimize images for Middleman"
14
- s.description = "Resize and optimize images for Middleman"
6
+ s.name = "middleman-images"
7
+ s.version = MiddlemanImages::VERSION.dup
8
+ s.platform = Gem::Platform::RUBY
9
+ s.licenses = ["MIT"]
10
+ s.authors = ["Ruben Grimm", "Julian Schneider"]
11
+ s.email = ["ruben.grimm@zweitag.de", "julian.schneider@zweitag.de"]
12
+ s.homepage = "https://www.github.com/zweitag/middleman-images"
13
+ s.summary = "Resize and optimize images for Middleman"
14
+ s.description = "" "
15
+ Resize and optimize your images on the fly with Middleman. Just run middleman build
16
+ and all your images will get the minimizing treatment. Middleman Images currently
17
+ depends on mini_magick for resizing and image_optim for optimizing your images.
18
+ " ""
15
19
 
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
23
  s.require_paths = ["lib"]
20
- s.required_ruby_version = '>= 2.5.0'
24
+ s.required_ruby_version = ">= 2.5.0"
21
25
 
22
- s.add_runtime_dependency("middleman-core", [">= 4.1.14"])
26
+ s.add_runtime_dependency("middleman-core", [">= 4.1.14", "< 5.1"])
23
27
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-images
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruben Grimm
8
8
  - Julian Schneider
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-02-05 00:00:00.000000000 Z
12
+ date: 2020-09-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: middleman-core
@@ -18,6 +18,9 @@ dependencies:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: 4.1.14
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '5.1'
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -25,7 +28,13 @@ dependencies:
25
28
  - - ">="
26
29
  - !ruby/object:Gem::Version
27
30
  version: 4.1.14
28
- description: Resize and optimize images for Middleman
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.1'
34
+ description: "\n Resize and optimize your images on the fly with Middleman. Just
35
+ run middleman build\n and all your images will get the minimizing treatment.
36
+ Middleman Images currently\n depends on mini_magick for resizing and image_optim
37
+ for optimizing your images.\n "
29
38
  email:
30
39
  - ruben.grimm@zweitag.de
31
40
  - julian.schneider@zweitag.de
@@ -34,21 +43,24 @@ extensions: []
34
43
  extra_rdoc_files: []
35
44
  files:
36
45
  - ".gitignore"
46
+ - ".rufo"
37
47
  - ".travis.yml"
38
48
  - CHANGELOG.md
39
49
  - Gemfile
40
50
  - Gemfile.lock
41
51
  - LICENSE
42
52
  - README.md
43
- - Rakefile
44
53
  - features/building.feature
45
54
  - features/ignore_original.feature
46
55
  - features/image_path.feature
56
+ - features/images_dir.feature
47
57
  - features/optimization.feature
58
+ - features/proxy_resources.feature
48
59
  - features/relative_path.feature
49
60
  - features/resize.feature
50
61
  - features/support/env.rb
51
62
  - features/support/middleman_images_steps.rb
63
+ - fixtures/image/source/assets/images/fox.jpg
52
64
  - fixtures/image/source/images/fox.jpg
53
65
  - gemfiles/Gemfile.middleman-4.1
54
66
  - gemfiles/Gemfile.middleman-4.1.lock
@@ -68,7 +80,7 @@ homepage: https://www.github.com/zweitag/middleman-images
68
80
  licenses:
69
81
  - MIT
70
82
  metadata: {}
71
- post_install_message:
83
+ post_install_message:
72
84
  rdoc_options: []
73
85
  require_paths:
74
86
  - lib
@@ -83,15 +95,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
95
  - !ruby/object:Gem::Version
84
96
  version: '0'
85
97
  requirements: []
86
- rubygems_version: 3.0.3
87
- signing_key:
98
+ rubygems_version: 3.1.2
99
+ signing_key:
88
100
  specification_version: 4
89
101
  summary: Resize and optimize images for Middleman
90
102
  test_files:
91
103
  - features/building.feature
92
104
  - features/ignore_original.feature
93
105
  - features/image_path.feature
106
+ - features/images_dir.feature
94
107
  - features/optimization.feature
108
+ - features/proxy_resources.feature
95
109
  - features/relative_path.feature
96
110
  - features/resize.feature
97
111
  - features/support/env.rb
data/Rakefile DELETED
@@ -1,18 +0,0 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
3
-
4
- require 'cucumber/rake/task'
5
-
6
- Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
7
- t.cucumber_opts = '--color --tags ~@wip --strict'
8
- end
9
-
10
- Cucumber::Rake::Task.new(:cucumber_wip, 'Run work-in-progress features that should pass') do |t|
11
- t.cucumber_opts = "--color --tags @wip --strict"
12
- end
13
-
14
- require 'rake/clean'
15
-
16
- task test: ['cucumber']
17
-
18
- task default: :test