jekyll-responsive_image 0.11.0 → 0.11.1
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/README.md +25 -12
- data/features/responsive-image-block.feature +10 -0
- data/features/{responsive-image.feature → responsive-image-tag.feature} +0 -0
- data/features/step_definitions/jekyll_steps.rb +6 -0
- data/lib/jekyll/responsive_image/block.rb +3 -4
- data/lib/jekyll/responsive_image/image_processor.rb +23 -0
- data/lib/jekyll/responsive_image/resize_handler.rb +4 -2
- data/lib/jekyll/responsive_image/tag.rb +3 -4
- data/lib/jekyll/responsive_image/utils.rb +3 -3
- data/lib/jekyll/responsive_image/version.rb +1 -1
- data/lib/jekyll/responsive_image.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe2970475b8023f942caa43714d99f99adfbb4a3
|
4
|
+
data.tar.gz: ea81c9cc1381b8d8018e87a97243d94e383f094f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08bbd6b9121656bb1c6203ed89e7169fd6b308ce94418875db420ccbcc12cf70d952ea3c77988a4359741774be566c17ab4139ca80f3c512a440fca56fff7b9e
|
7
|
+
data.tar.gz: 64a81aecc60593954afece28db05ce753202d14dc6b3400e7440836d84c018e36de5fdec025eaf96fb062d5c5860c68824616a6a4e93c9d21932bcd616e09f5a
|
data/README.md
CHANGED
@@ -62,19 +62,19 @@ responsive_image:
|
|
62
62
|
|
63
63
|
Replace your images with the `responsive_image` tag, specifying the path to the image in the `path` attribute.
|
64
64
|
|
65
|
-
```
|
65
|
+
```twig
|
66
66
|
{% responsive_image path: assets/my-file.jpg %}
|
67
67
|
```
|
68
68
|
|
69
69
|
You can override the template on a per-image basis by specifying the `template` attribute.
|
70
70
|
|
71
|
-
```
|
71
|
+
```twig
|
72
72
|
{% responsive_image path: assets/my-file.jpg template: _includes/another-template.html %}
|
73
73
|
```
|
74
74
|
|
75
75
|
Any extra attributes will be passed straight to the template as variables.
|
76
76
|
|
77
|
-
```
|
77
|
+
```twig
|
78
78
|
{% responsive_image path: assets/image.jpg alt: "Lorem ipsum..." title: "Lorem ipsum..." %}
|
79
79
|
```
|
80
80
|
|
@@ -84,7 +84,7 @@ You can use Liquid variables as attributes with the `responsive_image_block` tag
|
|
84
84
|
|
85
85
|
> **Important!** The attributes in the `responsive_image_block` tag are parsed as YAML, so whitespace and indentation are important!
|
86
86
|
|
87
|
-
```
|
87
|
+
```twig
|
88
88
|
{% assign path = 'assets/test.png' %}
|
89
89
|
{% assign alt = 'Lorem ipsum...' %}
|
90
90
|
|
@@ -101,21 +101,34 @@ You can use Liquid variables as attributes with the `responsive_image_block` tag
|
|
101
101
|
|
102
102
|
You will need to create a template in order to use the `responsive_image` tag. Below are some sample templates to get you started.
|
103
103
|
|
104
|
-
####
|
104
|
+
#### Responsive images with `srcset`
|
105
|
+
|
106
|
+
```twig
|
107
|
+
{% capture srcset %}
|
108
|
+
{% for i in resized %}
|
109
|
+
/{{ i.path }} {{ i.width }}w,
|
110
|
+
{% endfor %}
|
111
|
+
{% endcapture %}
|
112
|
+
|
113
|
+
<img src="/{{ path }}" srcset="{{ srcset | strip_newlines }} /{{ original.path }} {{ original.width }}w">
|
114
|
+
```
|
115
|
+
|
116
|
+
#### Responsive images with `<picture>`
|
105
117
|
|
106
|
-
```
|
107
|
-
<
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
118
|
+
```twig
|
119
|
+
<picture>
|
120
|
+
{% for i in resized %}
|
121
|
+
<source media="(min-width: {{ i.width }}px)" srcset="/{{ i.path }}">
|
122
|
+
{% endfor %}
|
123
|
+
<img src="/{{ path }}">
|
124
|
+
</picture>
|
112
125
|
```
|
113
126
|
|
114
127
|
#### Responsive images using [Imager.js](https://github.com/BBC-News/Imager.js/)
|
115
128
|
|
116
129
|
> This template assumes an `output_path_format` of `assets/resized/%{width}/%{basename}`
|
117
130
|
|
118
|
-
```
|
131
|
+
```twig
|
119
132
|
{% assign smallest = resized | sort: 'width' | first %}
|
120
133
|
|
121
134
|
<div class="responsive-image">
|
@@ -38,3 +38,13 @@ Feature: Jekyll responsive_image_block tag
|
|
38
38
|
"""
|
39
39
|
When I run Jekyll
|
40
40
|
Then I should see "<img alt=\"Lorem ipsum\" src=\"/assets/test.png\"" in "_site/index.html"
|
41
|
+
|
42
|
+
Scenario: Handling a nil path
|
43
|
+
Given I have a responsive_image configuration with "template" set to "_includes/responsive-image.html"
|
44
|
+
And I have a file "index.html" with:
|
45
|
+
"""
|
46
|
+
{% responsive_image_block %}
|
47
|
+
path: {{ path }}
|
48
|
+
{% endresponsive_image_block %}
|
49
|
+
"""
|
50
|
+
Then Jekyll should throw a "SyntaxError"
|
File without changes
|
@@ -1,7 +1,13 @@
|
|
1
|
+
include Test::Unit::Assertions
|
2
|
+
|
1
3
|
When /^I run Jekyll$/ do
|
2
4
|
run_jekyll
|
3
5
|
end
|
4
6
|
|
7
|
+
Then /^Jekyll should throw a "(.+)"$/ do |error_class|
|
8
|
+
assert_raise(Object.const_get(error_class)) { run_jekyll }
|
9
|
+
end
|
10
|
+
|
5
11
|
Given /^I have a responsive_image configuration with:$/ do |config|
|
6
12
|
write_file('_config.yml', "responsive_image:\n#{config}")
|
7
13
|
end
|
@@ -8,10 +8,9 @@ module Jekyll
|
|
8
8
|
attributes = YAML.load(super)
|
9
9
|
image_template = attributes['template'] || config['template']
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
attributes['
|
14
|
-
attributes['resized'] = resize_handler.resize_image(img, config)
|
11
|
+
image = ImageProcessor.process(attributes['path'], config)
|
12
|
+
attributes['original'] = image[:original]
|
13
|
+
attributes['resized'] = image[:resized]
|
15
14
|
|
16
15
|
partial = File.read(image_template)
|
17
16
|
template = Liquid::Template.parse(partial)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Jekyll
|
2
|
+
class ResponsiveImage
|
3
|
+
class ImageProcessor
|
4
|
+
include ResponsiveImage::Utils
|
5
|
+
|
6
|
+
def process(image_path, config)
|
7
|
+
raise SyntaxError.new('Invalid image path specified') unless File.exists?(image_path.to_s)
|
8
|
+
|
9
|
+
resize_handler = ResizeHandler.new
|
10
|
+
img = Magick::Image::read(image_path).first
|
11
|
+
|
12
|
+
{
|
13
|
+
original: image_hash(image_path, img.columns, img.rows),
|
14
|
+
resized: resize_handler.resize_image(img, config),
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.process(image_path, config)
|
19
|
+
self.new.process(image_path, config)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Jekyll
|
2
2
|
class ResponsiveImage
|
3
3
|
class ResizeHandler
|
4
|
+
include ResponsiveImage::Utils
|
5
|
+
|
4
6
|
def resize_image(img, config)
|
5
7
|
resized = []
|
6
8
|
|
@@ -12,7 +14,7 @@ module Jekyll
|
|
12
14
|
next unless needs_resizing?(img, width)
|
13
15
|
|
14
16
|
filepath = format_output_path(config['output_path_format'], img.filename, width, height)
|
15
|
-
resized.push(
|
17
|
+
resized.push(image_hash(filepath, width, height))
|
16
18
|
|
17
19
|
# Don't resize images more than once
|
18
20
|
next if File.exists?(filepath)
|
@@ -33,7 +35,7 @@ module Jekyll
|
|
33
35
|
end
|
34
36
|
|
35
37
|
def format_output_path(format, path, width, height)
|
36
|
-
params =
|
38
|
+
params = symbolize_keys(image_hash(path, width, height))
|
37
39
|
format % params
|
38
40
|
end
|
39
41
|
|
@@ -16,10 +16,9 @@ module Jekyll
|
|
16
16
|
config = ResponsiveImage.defaults.dup
|
17
17
|
config.merge!(context.registers[:site].config['responsive_image'])
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
@attributes['
|
22
|
-
@attributes['resized'] = resize_handler.resize_image(img, config)
|
19
|
+
image = ImageProcessor.process(@attributes['path'], config)
|
20
|
+
@attributes['original'] = image[:original]
|
21
|
+
@attributes['resized'] = image[:resized]
|
23
22
|
|
24
23
|
image_template = @attributes['template'] || config['template']
|
25
24
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Jekyll
|
2
2
|
class ResponsiveImage
|
3
|
-
|
4
|
-
def
|
3
|
+
module Utils
|
4
|
+
def symbolize_keys(hash)
|
5
5
|
result = {}
|
6
6
|
hash.each_key do |key|
|
7
7
|
result[key.to_sym] = hash[key]
|
@@ -10,7 +10,7 @@ module Jekyll
|
|
10
10
|
end
|
11
11
|
|
12
12
|
# Build a hash containing image information
|
13
|
-
def
|
13
|
+
def image_hash(path, width, height)
|
14
14
|
{
|
15
15
|
'path' => path,
|
16
16
|
'basename' => File.basename(path),
|
@@ -7,6 +7,7 @@ require 'rmagick'
|
|
7
7
|
require 'jekyll/responsive_image/version'
|
8
8
|
require 'jekyll/responsive_image/defaults'
|
9
9
|
require 'jekyll/responsive_image/utils'
|
10
|
+
require 'jekyll/responsive_image/image_processor'
|
10
11
|
require 'jekyll/responsive_image/resize_handler'
|
11
12
|
require 'jekyll/responsive_image/tag'
|
12
13
|
require 'jekyll/responsive_image/block'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-responsive_image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Wynn
|
@@ -58,7 +58,7 @@ files:
|
|
58
58
|
- features/fixtures/_includes/responsive-image.html
|
59
59
|
- features/fixtures/assets/test.png
|
60
60
|
- features/responsive-image-block.feature
|
61
|
-
- features/responsive-image.feature
|
61
|
+
- features/responsive-image-tag.feature
|
62
62
|
- features/step_definitions/jekyll_steps.rb
|
63
63
|
- features/support/env.rb
|
64
64
|
- features/support/hooks.rb
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- lib/jekyll/responsive_image.rb
|
68
68
|
- lib/jekyll/responsive_image/block.rb
|
69
69
|
- lib/jekyll/responsive_image/defaults.rb
|
70
|
+
- lib/jekyll/responsive_image/image_processor.rb
|
70
71
|
- lib/jekyll/responsive_image/resize_handler.rb
|
71
72
|
- lib/jekyll/responsive_image/tag.rb
|
72
73
|
- lib/jekyll/responsive_image/utils.rb
|