jekyll-responsive_image 0.13.0 → 0.14.0
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/.travis.yml +7 -5
- data/README.md +17 -10
- data/features/fixtures/assets/subdir/test.png +0 -0
- data/features/image-generation.feature +35 -0
- data/features/responsive-image-tag.feature +1 -1
- data/features/step_definitions/jekyll_steps.rb +6 -0
- data/jekyll-responsive_image.gemspec +1 -1
- data/lib/jekyll/responsive_image/common.rb +3 -1
- data/lib/jekyll/responsive_image/defaults.rb +1 -0
- data/lib/jekyll/responsive_image/image_processor.rb +1 -1
- data/lib/jekyll/responsive_image/resize_handler.rb +2 -2
- data/lib/jekyll/responsive_image/utils.rb +19 -8
- data/lib/jekyll/responsive_image/version.rb +1 -1
- metadata +14 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26a3868d77490e6edcf5c932cffb129cf05cdab6
|
4
|
+
data.tar.gz: d3b7bcc0c173b2938cf7486dd45967a5a0978f9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 195fda571ae489df9febc69e482b4b7ae4b3d1cc65289d4c97f70c5e2bcfe43c850cc921d94f21e1c2fd4c53d22970820ddba3586ab346e6c0268a14853e2500
|
7
|
+
data.tar.gz: 6f4ef84402e49e4e0f2b2278aef28d97ccebfb9f7b7e484ea9f522e67c3b49e84385dde8e6c5ce31a804fbd63f1c4afd166aa2517b54f3335bbd81b4f2c5e3d5
|
data/.travis.yml
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
sudo: false
|
1
2
|
language: ruby
|
2
3
|
bundler_args: --without debug
|
4
|
+
before_script: bundle exec jekyll --version
|
3
5
|
script: bundle exec rake features_with_coveralls
|
4
6
|
rvm:
|
5
|
-
- 2.2
|
6
|
-
- 2.1
|
7
|
-
- 2.0
|
8
|
-
- 1.9
|
9
|
-
- rbx
|
7
|
+
- 2.2
|
8
|
+
- 2.1
|
9
|
+
- 2.0
|
10
|
+
- 1.9
|
11
|
+
- rbx
|
data/README.md
CHANGED
@@ -45,11 +45,17 @@ responsive_image:
|
|
45
45
|
- width: 1400
|
46
46
|
quality: 90
|
47
47
|
|
48
|
+
# [Optional, Default: assets]
|
49
|
+
# The base directory where assets are stored. This is used to determine the
|
50
|
+
# `dirname` value in `output_path_format` below.
|
51
|
+
base_path: assets
|
52
|
+
|
48
53
|
# [Optional, Default: assets/resized/%{filename}-%{width}x%{height}.%{extension}]
|
49
54
|
# The template used when generating filenames for resized images. Must be a
|
50
55
|
# relative path.
|
51
56
|
#
|
52
57
|
# Parameters available are:
|
58
|
+
# %{dirname} Directory of the file relative to `base_path` (assets/sub/dir/some-file.jpg => sub/dir)
|
53
59
|
# %{basename} Basename of the file (assets/some-file.jpg => some-file.jpg)
|
54
60
|
# %{filename} Basename without the extension (assets/some-file.jpg => some-file)
|
55
61
|
# %{extension} Extension of the file (assets/some-file.jpg => jpg)
|
@@ -83,7 +89,7 @@ Any extra attributes will be passed straight to the template as variables.
|
|
83
89
|
|
84
90
|
You can use Liquid variables as attributes with the `responsive_image_block` tag. This tag works in exactly the same way as the `responsive_image` tag, but is implemented as a block tag to allow for more complex logic.
|
85
91
|
|
86
|
-
> **Important!** The attributes in the `responsive_image_block` tag are parsed as YAML, so whitespace and indentation are
|
92
|
+
> **Important!** The attributes in the `responsive_image_block` tag are parsed as YAML, so whitespace and indentation are significant!
|
87
93
|
|
88
94
|
```twig
|
89
95
|
{% assign path = 'assets/test.png' %}
|
@@ -127,7 +133,7 @@ You will need to create a template in order to use the `responsive_image` tag. B
|
|
127
133
|
|
128
134
|
#### Responsive images using [Imager.js](https://github.com/BBC-News/Imager.js/)
|
129
135
|
|
130
|
-
> This template assumes an `output_path_format` of `assets/resized/%{width}/%{basename}`
|
136
|
+
> **Note:** This template assumes an `output_path_format` of `assets/resized/%{width}/%{basename}`
|
131
137
|
|
132
138
|
```twig
|
133
139
|
{% assign smallest = resized | sort: 'width' | first %}
|
@@ -162,11 +168,12 @@ The following variables are available in the template:
|
|
162
168
|
|
163
169
|
Image objects (like `original` and each object in `resized`) contain the following properties:
|
164
170
|
|
165
|
-
| Variable | Type | Description
|
166
|
-
|
167
|
-
| `path` | String | The path to the image.
|
168
|
-
| `width` | Integer | The width of the image.
|
169
|
-
| `height` | Integer | The height of the image.
|
170
|
-
| `basename` | String | Basename of the file (`assets/some-file.jpg` => `some-file.jpg`).
|
171
|
-
| `
|
172
|
-
| `
|
171
|
+
| Variable | Type | Description |
|
172
|
+
|-------------|---------|----------------------------------------------------------------------------------------------|
|
173
|
+
| `path` | String | The path to the image. |
|
174
|
+
| `width` | Integer | The width of the image. |
|
175
|
+
| `height` | Integer | The height of the image. |
|
176
|
+
| `basename` | String | Basename of the file (`assets/some-file.jpg` => `some-file.jpg`). |
|
177
|
+
| `dirname` | String | Directory of the file relative to `base_path` (`assets/sub/dir/some-file.jpg` => `sub/dir`). |
|
178
|
+
| `filename` | String | Basename without the extension (`assets/some-file.jpg` => `some-file`). |
|
179
|
+
| `extension` | String | Extension of the file (`assets/some-file.jpg` => `jpg`). |
|
Binary file
|
@@ -0,0 +1,35 @@
|
|
1
|
+
Feature: Responsive image generation
|
2
|
+
As a Jekyll user
|
3
|
+
I want to generate responsive images
|
4
|
+
In order to use them on my pages
|
5
|
+
|
6
|
+
Scenario: Resizing images
|
7
|
+
Given I have a responsive_image configuration with:
|
8
|
+
"""
|
9
|
+
template: _includes/responsive-image.html
|
10
|
+
sizes:
|
11
|
+
- width: 100
|
12
|
+
"""
|
13
|
+
|
14
|
+
And I have a file "index.html" with "{% responsive_image path: assets/test.png alt: Foobar %}"
|
15
|
+
When I run Jekyll
|
16
|
+
Then the image "assets/resized/test-100x50.png" should have the dimensions "100x50"
|
17
|
+
|
18
|
+
Scenario: Handling subdirectories
|
19
|
+
Given I have a responsive_image configuration with:
|
20
|
+
"""
|
21
|
+
template: _includes/responsive-image.html
|
22
|
+
output_path_format: assets/resized/%{dirname}/%{filename}-%{width}.%{extension}
|
23
|
+
sizes:
|
24
|
+
- width: 100
|
25
|
+
"""
|
26
|
+
|
27
|
+
And I have a file "index.html" with:
|
28
|
+
"""
|
29
|
+
{% responsive_image path: assets/test.png %}
|
30
|
+
{% responsive_image path: assets/subdir/test.png %}
|
31
|
+
"""
|
32
|
+
|
33
|
+
When I run Jekyll
|
34
|
+
Then the file "assets/resized/test-100.png" should exist
|
35
|
+
And the file "assets/resized/subdir/test-100.png" should exist
|
@@ -69,7 +69,7 @@ Feature: Jekyll responsive_image tag
|
|
69
69
|
Given I have a responsive_image configuration with:
|
70
70
|
"""
|
71
71
|
template: _includes/responsive-image.html
|
72
|
-
output_path_format: assets/%{basename}-resized/%{width}/%{filename}-%{height}.%{extension}
|
72
|
+
output_path_format: assets/%{dirname}/%{basename}-resized/%{width}/%{filename}-%{height}.%{extension}
|
73
73
|
sizes:
|
74
74
|
- width: 100
|
75
75
|
"""
|
@@ -36,6 +36,12 @@ Then /^the file "(.+)" should exist$/ do |path|
|
|
36
36
|
assert File.exists?(path)
|
37
37
|
end
|
38
38
|
|
39
|
+
Then /^the image "(.+)" should have the dimensions "(\d+)x(\d+)"$/ do |path, width, height|
|
40
|
+
img = Magick::Image::read(path).first
|
41
|
+
assert_equal "#{width}x#{height}", "#{img.columns}x#{img.rows}"
|
42
|
+
img.destroy!
|
43
|
+
end
|
44
|
+
|
39
45
|
def write_file(path, contents)
|
40
46
|
File.open(path, 'w') do |f|
|
41
47
|
f.write(contents)
|
@@ -7,7 +7,9 @@ module Jekyll
|
|
7
7
|
config = ResponsiveImage.defaults.dup.merge(site.config['responsive_image']).merge(:site_dest => site.dest)
|
8
8
|
|
9
9
|
# Not very nice, but this is needed to create a clean path to add to keep_files
|
10
|
-
output_dir = format_output_path(config['output_path_format'], '*', '*', '*')
|
10
|
+
output_dir = format_output_path(config['output_path_format'], config['base_path'], '*', '*', '*')
|
11
|
+
output_dir = "#{File.dirname(output_dir)}/*"
|
12
|
+
|
11
13
|
site.config['keep_files'] << output_dir unless site.config['keep_files'].include?(output_dir)
|
12
14
|
|
13
15
|
config
|
@@ -10,7 +10,7 @@ module Jekyll
|
|
10
10
|
img = Magick::Image::read(image_path).first
|
11
11
|
|
12
12
|
{
|
13
|
-
original: image_hash(image_path, img.columns, img.rows),
|
13
|
+
original: image_hash(config['base_path'], image_path, img.columns, img.rows),
|
14
14
|
resized: resize_handler.resize_image(img, config),
|
15
15
|
}
|
16
16
|
end
|
@@ -13,8 +13,8 @@ module Jekyll
|
|
13
13
|
|
14
14
|
next unless needs_resizing?(img, width)
|
15
15
|
|
16
|
-
filepath = format_output_path(config['output_path_format'], img.filename, width, height)
|
17
|
-
resized.push(image_hash(filepath, width, height))
|
16
|
+
filepath = format_output_path(config['output_path_format'], config['base_path'], img.filename, width, height)
|
17
|
+
resized.push(image_hash(config['base_path'], filepath, width, height))
|
18
18
|
|
19
19
|
# Don't resize images more than once
|
20
20
|
next if File.exists?(filepath)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
1
3
|
module Jekyll
|
2
4
|
class ResponsiveImage
|
3
5
|
module Utils
|
@@ -9,22 +11,31 @@ module Jekyll
|
|
9
11
|
result
|
10
12
|
end
|
11
13
|
|
12
|
-
def format_output_path(format,
|
13
|
-
params = symbolize_keys(image_hash(
|
14
|
-
|
14
|
+
def format_output_path(format, base_path, image_path, width, height)
|
15
|
+
params = symbolize_keys(image_hash(base_path, image_path, width, height))
|
16
|
+
|
17
|
+
Pathname.new(format % params).cleanpath.to_s
|
15
18
|
end
|
16
19
|
|
17
20
|
# Build a hash containing image information
|
18
|
-
def image_hash(
|
21
|
+
def image_hash(base_path, image_path, width, height)
|
19
22
|
{
|
20
|
-
'path' =>
|
21
|
-
'
|
22
|
-
'
|
23
|
-
'
|
23
|
+
'path' => image_path,
|
24
|
+
'dirname' => relative_dirname(base_path, image_path),
|
25
|
+
'basename' => File.basename(image_path),
|
26
|
+
'filename' => File.basename(image_path, '.*'),
|
27
|
+
'extension' => File.extname(image_path).delete('.'),
|
24
28
|
'width' => width,
|
25
29
|
'height' => height,
|
26
30
|
}
|
27
31
|
end
|
32
|
+
|
33
|
+
def relative_dirname(base_path, image_path)
|
34
|
+
path = Pathname.new(image_path).expand_path
|
35
|
+
base = Pathname.new(base_path).expand_path
|
36
|
+
|
37
|
+
path.relative_path_from(base).dirname.to_s.delete('.')
|
38
|
+
end
|
28
39
|
end
|
29
40
|
end
|
30
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-responsive_image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Wynn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -36,14 +36,20 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '0'
|
39
|
+
version: '2.0'
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '3.0'
|
40
43
|
type: :runtime
|
41
44
|
prerelease: false
|
42
45
|
version_requirements: !ruby/object:Gem::Requirement
|
43
46
|
requirements:
|
44
47
|
- - ">="
|
45
48
|
- !ruby/object:Gem::Version
|
46
|
-
version: '0'
|
49
|
+
version: '2.0'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '3.0'
|
47
53
|
description: "\n Jekyll Responsive Images is a Jekyll plugin and utility for automatically
|
48
54
|
resizing images.\n Its intended use is for sites which want to display responsive
|
49
55
|
images using something like srcset or Imager.js.\n "
|
@@ -63,7 +69,9 @@ files:
|
|
63
69
|
- features/fixtures/_includes/base-url.html
|
64
70
|
- features/fixtures/_includes/custom-template.html
|
65
71
|
- features/fixtures/_includes/responsive-image.html
|
72
|
+
- features/fixtures/assets/subdir/test.png
|
66
73
|
- features/fixtures/assets/test.png
|
74
|
+
- features/image-generation.feature
|
67
75
|
- features/responsive-image-block.feature
|
68
76
|
- features/responsive-image-tag.feature
|
69
77
|
- features/step_definitions/jekyll_steps.rb
|
@@ -107,7 +115,9 @@ test_files:
|
|
107
115
|
- features/fixtures/_includes/base-url.html
|
108
116
|
- features/fixtures/_includes/custom-template.html
|
109
117
|
- features/fixtures/_includes/responsive-image.html
|
118
|
+
- features/fixtures/assets/subdir/test.png
|
110
119
|
- features/fixtures/assets/test.png
|
120
|
+
- features/image-generation.feature
|
111
121
|
- features/responsive-image-block.feature
|
112
122
|
- features/responsive-image-tag.feature
|
113
123
|
- features/step_definitions/jekyll_steps.rb
|