middleman-images 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.travis.yml +29 -0
- data/CHANGELOG.md +32 -0
- data/Gemfile +26 -0
- data/Gemfile.lock +194 -0
- data/LICENSE +20 -0
- data/README.md +142 -0
- data/Rakefile +18 -0
- data/features/building.feature +79 -0
- data/features/ignore_original.feature +78 -0
- data/features/image_path.feature +67 -0
- data/features/optimization.feature +57 -0
- data/features/relative_path.feature +40 -0
- data/features/resize.feature +29 -0
- data/features/support/env.rb +4 -0
- data/features/support/middleman_images_steps.rb +31 -0
- data/fixtures/image/source/images/fox.jpg +0 -0
- data/gemfiles/Gemfile.middleman-4.1 +27 -0
- data/gemfiles/Gemfile.middleman-4.1.lock +196 -0
- data/gemfiles/Gemfile.middleman-4.2 +27 -0
- data/gemfiles/Gemfile.middleman-4.2.lock +196 -0
- data/gemfiles/Gemfile.middleman-4.3 +27 -0
- data/gemfiles/Gemfile.middleman-4.3.lock +194 -0
- data/gemfiles/Gemfile.middleman-5.0-rc +27 -0
- data/gemfiles/Gemfile.middleman-5.0-rc.lock +199 -0
- data/lib/middleman-images.rb +8 -0
- data/lib/middleman-images/extension.rb +89 -0
- data/lib/middleman-images/image.rb +68 -0
- data/lib/middleman-images/manipulator.rb +49 -0
- data/lib/middleman-images/version.rb +3 -0
- data/middleman-images.gemspec +23 -0
- metadata +98 -0
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
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
|
@@ -0,0 +1,79 @@
|
|
1
|
+
Feature: Building images
|
2
|
+
|
3
|
+
Scenario: Building all images
|
4
|
+
Given a fixture app "image"
|
5
|
+
And our extension is enabled
|
6
|
+
And a template named "index.html.erb" with:
|
7
|
+
"""
|
8
|
+
<%= image_tag 'images/fox.jpg', optimize: true %>
|
9
|
+
<%= image_tag 'images/fox.jpg', resize: '400x225', optimize: true %>
|
10
|
+
<%= image_tag 'images/fox.jpg', resize: '400x225', optimize: false %>
|
11
|
+
"""
|
12
|
+
And a successfully built app at "image"
|
13
|
+
When I cd to "build"
|
14
|
+
Then the following files should exist:
|
15
|
+
| index.html |
|
16
|
+
| images/fox.jpg |
|
17
|
+
| images/fox-opt.jpg |
|
18
|
+
| images/fox-400x225.jpg |
|
19
|
+
| images/fox-400x225-opt.jpg |
|
20
|
+
|
21
|
+
Scenario: Not building resources twice in a build
|
22
|
+
Given a fixture app "image"
|
23
|
+
And our extension is enabled
|
24
|
+
And a template named "first.html.erb" with:
|
25
|
+
"""
|
26
|
+
<%= image_tag 'images/fox.jpg', optimize: true %>
|
27
|
+
"""
|
28
|
+
And a template named "second.html.erb" with:
|
29
|
+
"""
|
30
|
+
<%= image_tag 'images/fox.jpg', optimize: true %>
|
31
|
+
"""
|
32
|
+
And the Server is running
|
33
|
+
And I go to "/first.html"
|
34
|
+
And a modification time for a file named "cache/images/fox-opt.jpg"
|
35
|
+
When I go to "/second.html"
|
36
|
+
Then the file "cache/images/fox-opt.jpg" should exist
|
37
|
+
Then the file "cache/images/fox-opt.jpg" should not have been updated
|
38
|
+
|
39
|
+
Scenario: Building image with asset_hash extension
|
40
|
+
Given a fixture app "image"
|
41
|
+
And our extension is enabled
|
42
|
+
And I append to "config.rb" with:
|
43
|
+
"""
|
44
|
+
activate :asset_hash
|
45
|
+
"""
|
46
|
+
And a template named "index.html.erb" with:
|
47
|
+
"""
|
48
|
+
<%= image_path 'images/fox.jpg', optimize: true %>
|
49
|
+
"""
|
50
|
+
And a successfully built app at "image"
|
51
|
+
When I cd to "build/images"
|
52
|
+
Then a file named "fox-opt.jpg" should not exist
|
53
|
+
Then a file named "fox-opt-4eaecd94.jpg" should exist
|
54
|
+
|
55
|
+
Scenario: Not rebuilding unchanged resource
|
56
|
+
Given a fixture app "image"
|
57
|
+
And our extension is enabled
|
58
|
+
And a template named "index.html.erb" with:
|
59
|
+
"""
|
60
|
+
<%= image_path 'images/fox.jpg', optimize: true %>
|
61
|
+
"""
|
62
|
+
And a successfully built app at "image"
|
63
|
+
And a modification time for a file named "cache/images/fox-opt.jpg"
|
64
|
+
When a successfully built app at "image"
|
65
|
+
Then the file "cache/images/fox-opt.jpg" should exist
|
66
|
+
Then the file "cache/images/fox-opt.jpg" should not have been updated
|
67
|
+
|
68
|
+
Scenario: Building all images in a custom cache directory
|
69
|
+
Given a fixture app "image"
|
70
|
+
And our extension is enabled with:
|
71
|
+
"""
|
72
|
+
config.cache_dir = 'custom/cache'
|
73
|
+
"""
|
74
|
+
And a template named "index.html.erb" with:
|
75
|
+
"""
|
76
|
+
<%= image_tag 'images/fox.jpg', optimize: true %>
|
77
|
+
"""
|
78
|
+
When a successfully built app at "image"
|
79
|
+
Then the file "custom/cache/images/fox-opt.jpg" should exist
|
@@ -0,0 +1,78 @@
|
|
1
|
+
Feature: Ignore original
|
2
|
+
|
3
|
+
Scenario: Build original when processing
|
4
|
+
Given a fixture app "image"
|
5
|
+
And our extension is enabled with:
|
6
|
+
"""
|
7
|
+
config.ignore_original = false
|
8
|
+
"""
|
9
|
+
And a template named "index.html.erb" with:
|
10
|
+
"""
|
11
|
+
<%= image_path '/images/fox.jpg', optimize: true %>
|
12
|
+
"""
|
13
|
+
And the Server is running
|
14
|
+
And I go to "/index.html"
|
15
|
+
When I go to "/images/fox.jpg"
|
16
|
+
Then the status code should be "200"
|
17
|
+
|
18
|
+
Scenario: Ignore original when processing
|
19
|
+
Given a fixture app "image"
|
20
|
+
And our extension is enabled with:
|
21
|
+
"""
|
22
|
+
config.ignore_original = true
|
23
|
+
"""
|
24
|
+
And a template named "index.html.erb" with:
|
25
|
+
"""
|
26
|
+
<%= image_path 'fox.jpg', optimize: true %>
|
27
|
+
"""
|
28
|
+
And the Server is running
|
29
|
+
And I go to "/index.html"
|
30
|
+
When I go to "/images/fox.jpg"
|
31
|
+
Then the status code should be "404"
|
32
|
+
|
33
|
+
Scenario: Build original when not processing
|
34
|
+
Given a fixture app "image"
|
35
|
+
And our extension is enabled with:
|
36
|
+
"""
|
37
|
+
config.ignore_original = true
|
38
|
+
"""
|
39
|
+
And a template named "index.html.erb" with:
|
40
|
+
"""
|
41
|
+
<%= image_path 'fox.jpg', optimize: false %>
|
42
|
+
"""
|
43
|
+
And the Server is running
|
44
|
+
And I go to "/index.html"
|
45
|
+
When I go to "/images/fox.jpg"
|
46
|
+
Then the status code should be "200"
|
47
|
+
|
48
|
+
Scenario: Build original when using processed before original image
|
49
|
+
Given a fixture app "image"
|
50
|
+
And our extension is enabled with:
|
51
|
+
"""
|
52
|
+
config.ignore_original = true
|
53
|
+
"""
|
54
|
+
And a template named "index.html.erb" with:
|
55
|
+
"""
|
56
|
+
<%= image_path 'fox.jpg', optimize: true %>
|
57
|
+
<%= image_path 'fox.jpg', optimize: false %>
|
58
|
+
"""
|
59
|
+
And the Server is running
|
60
|
+
And I go to "/index.html"
|
61
|
+
When I go to "/images/fox.jpg"
|
62
|
+
Then the status code should be "200"
|
63
|
+
|
64
|
+
Scenario: Build original when using processed after original image
|
65
|
+
Given a fixture app "image"
|
66
|
+
And our extension is enabled with:
|
67
|
+
"""
|
68
|
+
config.ignore_original = true
|
69
|
+
"""
|
70
|
+
And a template named "index.html.erb" with:
|
71
|
+
"""
|
72
|
+
<%= image_path 'fox.jpg', optimize: false %>
|
73
|
+
<%= image_path 'fox.jpg', optimize: true %>
|
74
|
+
"""
|
75
|
+
And the Server is running
|
76
|
+
And I go to "/index.html"
|
77
|
+
When I go to "/images/fox.jpg"
|
78
|
+
Then the status code should be "200"
|
@@ -0,0 +1,67 @@
|
|
1
|
+
Feature: image_path helper
|
2
|
+
|
3
|
+
Scenario: image_path with options
|
4
|
+
Given a fixture app "image"
|
5
|
+
And our extension is enabled
|
6
|
+
And a template named "index.html.erb" with:
|
7
|
+
"""
|
8
|
+
<%= image_path '/images/fox.jpg', resize: "400x225", optimize: true %>
|
9
|
+
"""
|
10
|
+
And the Server is running
|
11
|
+
When I go to "/index.html"
|
12
|
+
Then I should see '/images/fox-400x225-opt.jpg'
|
13
|
+
When I go to "/images/fox-400x225-opt.jpg"
|
14
|
+
Then the status code should be "200"
|
15
|
+
|
16
|
+
Scenario: image_path without options
|
17
|
+
Given a fixture app "image"
|
18
|
+
And our extension is enabled
|
19
|
+
And a template named "index.html.erb" with:
|
20
|
+
"""
|
21
|
+
<%= image_path '/images/fox.jpg', optimize: true %>
|
22
|
+
"""
|
23
|
+
And the Server is running
|
24
|
+
When I go to "/index.html"
|
25
|
+
Then I should see '/images/fox-opt.jpg'
|
26
|
+
When I go to "/images/fox-opt.jpg"
|
27
|
+
Then the status code should be "200"
|
28
|
+
|
29
|
+
Scenario: image_path with unavailable image file
|
30
|
+
Given a fixture app "image"
|
31
|
+
And our extension is enabled
|
32
|
+
And a template named "index.html.erb" with:
|
33
|
+
"""
|
34
|
+
<%= image_path 'nofile.jpg', optimize: true %>
|
35
|
+
"""
|
36
|
+
And the Server is running
|
37
|
+
When I go to "/index.html"
|
38
|
+
Then I should see '/images/nofile.jpg'
|
39
|
+
When I go to "/images/nofile.jpg"
|
40
|
+
Then the status code should be "404"
|
41
|
+
|
42
|
+
Scenario: image_path with asset_hash extension
|
43
|
+
Given a fixture app "image"
|
44
|
+
And our extension is enabled
|
45
|
+
And "asset_hash" feature is "enabled"
|
46
|
+
And a template named "index.html.erb" with:
|
47
|
+
"""
|
48
|
+
<%= image_path 'images/fox.jpg', optimize: true %>
|
49
|
+
"""
|
50
|
+
And the Server is running
|
51
|
+
When I go to "/index.html"
|
52
|
+
Then I should see '/images/fox-opt-4eaecd94.jpg'
|
53
|
+
When I go to "/images/fox-opt-4eaecd94.jpg"
|
54
|
+
Then the status code should be "200"
|
55
|
+
|
56
|
+
Scenario: image_path in CSS file
|
57
|
+
Given a fixture app "image"
|
58
|
+
And our extension is enabled
|
59
|
+
And a file named "source/stylesheets/app.css.erb" with:
|
60
|
+
"""
|
61
|
+
body { background: url("<%= image_path 'images/fox.jpg', optimize: true %>") }
|
62
|
+
"""
|
63
|
+
And the Server is running
|
64
|
+
When I go to "/stylesheets/app.css"
|
65
|
+
Then I should see 'body { background: url("/images/fox-opt.jpg") }'
|
66
|
+
When I go to "/images/fox-opt.jpg"
|
67
|
+
Then the status code should be "200"
|
@@ -0,0 +1,57 @@
|
|
1
|
+
Feature: Image optimization
|
2
|
+
|
3
|
+
Scenario: Regular behavior without optimization
|
4
|
+
Given a fixture app "image"
|
5
|
+
And our extension is enabled
|
6
|
+
And a template named "index.html.erb" with:
|
7
|
+
"""
|
8
|
+
<%= image_tag '/images/fox.jpg', alt: "Lazy Fox" %>
|
9
|
+
"""
|
10
|
+
And the Server is running
|
11
|
+
When I go to "/index.html"
|
12
|
+
Then I should see '<img src="/images/fox.jpg" alt="Lazy Fox" />'
|
13
|
+
When I go to "/images/fox.jpg"
|
14
|
+
Then the status code should be "200"
|
15
|
+
And the content length should be equal to the file size of "source/images/fox.jpg"
|
16
|
+
|
17
|
+
Scenario: Optimize an image by default
|
18
|
+
Given a fixture app "image"
|
19
|
+
And our extension is enabled with:
|
20
|
+
"""
|
21
|
+
config.optimize = true
|
22
|
+
"""
|
23
|
+
And a template named "index.html.erb" with:
|
24
|
+
"""
|
25
|
+
<%= image_tag '/images/fox.jpg', alt: 'Lazy Fox' %>
|
26
|
+
"""
|
27
|
+
And the Server is running
|
28
|
+
When I go to "/index.html"
|
29
|
+
Then I should see '<img src="/images/fox-opt.jpg" alt="Lazy Fox" />'
|
30
|
+
When I go to "/images/fox-opt.jpg"
|
31
|
+
Then the status code should be "200"
|
32
|
+
And the content length should be smaller than the file size of "source/images/fox.jpg"
|
33
|
+
|
34
|
+
Scenario: Override optimize by default
|
35
|
+
Given a fixture app "image"
|
36
|
+
And our extension is enabled with:
|
37
|
+
"""
|
38
|
+
config.optimize = true
|
39
|
+
"""
|
40
|
+
And a template named "index.html.erb" with:
|
41
|
+
"""
|
42
|
+
<%= image_tag '/images/fox.jpg', alt: 'Lazy Fox', optimize: false %>
|
43
|
+
"""
|
44
|
+
And the Server is running
|
45
|
+
When I go to "/index.html"
|
46
|
+
Then I should see '<img src="/images/fox.jpg" alt="Lazy Fox" />'
|
47
|
+
|
48
|
+
Scenario: Override disabled optimization
|
49
|
+
Given a fixture app "image"
|
50
|
+
And our extension is enabled
|
51
|
+
And a template named "index.html.erb" with:
|
52
|
+
"""
|
53
|
+
<%= image_tag '/images/fox.jpg', alt: 'Lazy Fox', optimize: true %>
|
54
|
+
"""
|
55
|
+
And the Server is running
|
56
|
+
When I go to "/index.html"
|
57
|
+
Then I should see '<img src="/images/fox-opt.jpg" alt="Lazy Fox" />'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
Feature: Relative paths
|
2
|
+
|
3
|
+
Scenario: Absolute image path
|
4
|
+
Given a fixture app "image"
|
5
|
+
And our extension is enabled
|
6
|
+
And a template named "index.html.erb" with:
|
7
|
+
"""
|
8
|
+
<%= image_path '/images/fox.jpg', optimize: true %>
|
9
|
+
"""
|
10
|
+
And the Server is running
|
11
|
+
When I go to "/index.html"
|
12
|
+
Then I should see 'images/fox-opt.jpg'
|
13
|
+
When I go to "/images/fox-opt.jpg"
|
14
|
+
Then the status code should be "200"
|
15
|
+
|
16
|
+
Scenario: Relative image path
|
17
|
+
Given a fixture app "image"
|
18
|
+
And our extension is enabled
|
19
|
+
And a template named "index.html.erb" with:
|
20
|
+
"""
|
21
|
+
<%= image_path 'fox.jpg', optimize: true %>
|
22
|
+
"""
|
23
|
+
And the Server is running
|
24
|
+
When I go to "/index.html"
|
25
|
+
Then I should see 'images/fox-opt.jpg'
|
26
|
+
When I go to "/images/fox-opt.jpg"
|
27
|
+
Then the status code should be "200"
|
28
|
+
|
29
|
+
Scenario: Relative asset path
|
30
|
+
Given a fixture app "image"
|
31
|
+
And our extension is enabled
|
32
|
+
And a template named "index.html.erb" with:
|
33
|
+
"""
|
34
|
+
<%= image_path 'images/fox.jpg', optimize: true %>
|
35
|
+
"""
|
36
|
+
And the Server is running
|
37
|
+
When I go to "/index.html"
|
38
|
+
Then I should see 'images/fox-opt.jpg'
|
39
|
+
When I go to "/images/fox-opt.jpg"
|
40
|
+
Then the status code should be "200"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Feature: Image resizing
|
2
|
+
|
3
|
+
Scenario: Resize image
|
4
|
+
Given a fixture app "image"
|
5
|
+
And our extension is enabled
|
6
|
+
And a template named "index.html.erb" with:
|
7
|
+
"""
|
8
|
+
<%= image_tag '/images/fox.jpg', alt: "Lazy Fox", resize: "400x225", optimize: false %>
|
9
|
+
"""
|
10
|
+
And the Server is running
|
11
|
+
When I go to "/index.html"
|
12
|
+
Then I should see '<img src="/images/fox-400x225.jpg" alt="Lazy Fox" />'
|
13
|
+
When I go to "/images/fox-400x225.jpg"
|
14
|
+
Then the status code should be "200"
|
15
|
+
And the dimensions should be 400x225
|
16
|
+
|
17
|
+
Scenario: Resize image with optimization
|
18
|
+
Given a fixture app "image"
|
19
|
+
And our extension is enabled
|
20
|
+
And a template named "index.html.erb" with:
|
21
|
+
"""
|
22
|
+
<%= image_tag '/images/fox.jpg', alt: "Lazy Fox", resize: "400x225", optimize: true %>
|
23
|
+
"""
|
24
|
+
And the Server is running
|
25
|
+
When I go to "/index.html"
|
26
|
+
Then I should see '<img src="/images/fox-400x225-opt.jpg" alt="Lazy Fox" />'
|
27
|
+
When I go to "/images/fox-400x225-opt.jpg"
|
28
|
+
Then the status code should be "200"
|
29
|
+
And the dimensions should be 400x225
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'mini_magick'
|
2
|
+
|
3
|
+
Given /^our extension is enabled?$/ do
|
4
|
+
step 'our extension is enabled with:', ''
|
5
|
+
end
|
6
|
+
|
7
|
+
Given /^our extension is enabled with:$/ do |config|
|
8
|
+
config = """
|
9
|
+
activate :images do |config|
|
10
|
+
config.image_optim = {
|
11
|
+
pngout: false,
|
12
|
+
svgo: false,
|
13
|
+
}
|
14
|
+
#{config}
|
15
|
+
end
|
16
|
+
"""
|
17
|
+
step 'a file named "config.rb" with:', config
|
18
|
+
end
|
19
|
+
|
20
|
+
Then /^the dimensions should be (\d+)x(\d+)$/ do |x, y|
|
21
|
+
image = MiniMagick::Image.read page.body
|
22
|
+
expect(image.dimensions).to eql [x.to_i, y.to_i]
|
23
|
+
end
|
24
|
+
|
25
|
+
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))
|
27
|
+
end
|
28
|
+
|
29
|
+
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))
|
31
|
+
end
|
Binary file
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# If you do not have OpenSSL installed, update
|
2
|
+
# the following line to use "http://" instead
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in middleman-images.gemspec
|
6
|
+
gemspec path: '..'
|
7
|
+
|
8
|
+
|
9
|
+
group :development do
|
10
|
+
gem 'middleman', '~> 4.1.0'
|
11
|
+
gem 'rake'
|
12
|
+
gem 'rdoc'
|
13
|
+
gem 'yard'
|
14
|
+
end
|
15
|
+
|
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
|