jekyll_img 0.2.9 → 0.2.11
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/.rubocop.yml +7 -1
- data/CHANGELOG.md +11 -1
- data/README.md +1 -1
- data/lib/img_builder.rb +3 -2
- data/lib/img_props.rb +12 -5
- data/lib/jekyll_img/version.rb +1 -1
- data/lib/jekyll_img.rb +0 -1
- data/lib/source.rb +1 -1
- data/spec/img_builder_spec.rb +25 -15
- data/spec/img_props_spec.rb +63 -10
- data/spec/jekyll_img_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/status_persistence.txt +7 -5
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6665da5a9ea0fb8a14413e6bbcb177802b4419ead9470bdc3bbacdee5fafce73
|
|
4
|
+
data.tar.gz: 055d42f74d2c6361672132652779eb2a3a05e01d1e6d706932f03248ff9dca84
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f4196b6105ee1f9c449440d9d134ef63db4196d839257bc1e333214c414785cacb9bef906074adbf532b470aa85e7df48a0231d8c556b3b54137b9a9b1233a20
|
|
7
|
+
data.tar.gz: d6585eb0051f441eaa9d00aec48e05e4a23e34045843feeb2e2d6a2255c6439229ce99c8c532deade048726af4b60d441d4c88521f30ab7b731cfcf4f013d4c2
|
data/.rubocop.yml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
plugins:
|
|
2
2
|
# - rubocop-jekyll
|
|
3
3
|
- rubocop-md
|
|
4
4
|
- rubocop-performance
|
|
@@ -64,6 +64,9 @@ Metrics/PerceivedComplexity:
|
|
|
64
64
|
Naming/FileName:
|
|
65
65
|
Exclude:
|
|
66
66
|
- Rakefile
|
|
67
|
+
- Gemfile
|
|
68
|
+
- README.md
|
|
69
|
+
- CHANGELOG.md
|
|
67
70
|
|
|
68
71
|
Naming/MemoizedInstanceVariableName:
|
|
69
72
|
Enabled: false
|
|
@@ -86,6 +89,9 @@ Style/Documentation:
|
|
|
86
89
|
Style/FrozenStringLiteralComment:
|
|
87
90
|
Enabled: false
|
|
88
91
|
|
|
92
|
+
Style/OneClassPerFile:
|
|
93
|
+
Enabled: false
|
|
94
|
+
|
|
89
95
|
Style/StringConcatenation:
|
|
90
96
|
Exclude:
|
|
91
97
|
- spec/**/*
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 0.2.11 /2026-09-11
|
|
4
|
+
|
|
5
|
+
Not fixed yet:
|
|
6
|
+
|
|
7
|
+
* Fixed bug related to max-width percentage specification
|
|
8
|
+
|
|
9
|
+
## 0.2.10 /2026-07-04
|
|
10
|
+
|
|
11
|
+
* Pry is no longer a production dependency
|
|
12
|
+
|
|
3
13
|
## 0.2.9 / 2025-05-19
|
|
4
14
|
|
|
5
15
|
* `max-width` option added.
|
|
@@ -36,7 +46,7 @@
|
|
|
36
46
|
* Corrected `README.md#Configuration` and fixed demo `_config.yml`
|
|
37
47
|
so they correctly specify error handling for this plugin:
|
|
38
48
|
|
|
39
|
-
```
|
|
49
|
+
```yaml
|
|
40
50
|
img:
|
|
41
51
|
die_on_img_error: false
|
|
42
52
|
pry_on_img_error: false
|
data/README.md
CHANGED
data/lib/img_builder.rb
CHANGED
|
@@ -84,8 +84,9 @@ class ImgBuilder
|
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
def generate_wrapper
|
|
87
|
-
classes =
|
|
88
|
-
"#{@props.attr_max_width_class} #{@props.wrapper_class}"
|
|
87
|
+
classes = "imgWrapper #{@props.img_display} #{@props.align} #{@props.attr_size_class} " \
|
|
88
|
+
"#{@props.attr_max_width_class} #{@props.wrapper_class}"
|
|
89
|
+
classes = classes.squish
|
|
89
90
|
styles = "#{@props.attr_width_style} #{@props.attr_max_width_style} #{@props.wrapper_style}".squish
|
|
90
91
|
<<~END_HTML.remove_blank_lines
|
|
91
92
|
<div class='#{classes}' style='#{styles}'>
|
data/lib/img_props.rb
CHANGED
|
@@ -9,8 +9,8 @@ class ImgProperties
|
|
|
9
9
|
:id, :img_display, :lazy, :local_src, :max_width, :nofollow, :priority, :src, :size, :style,
|
|
10
10
|
:target, :title, :url, :wrapper_class, :wrapper_style
|
|
11
11
|
|
|
12
|
-
SIZES = %w[eighthsize fullsize halfsize initial quartersize].freeze
|
|
13
|
-
UNITS = %w[Q ch cm em dvh dvw ex in lh lvh lvw mm pc px pt rem rlh svh svw vb vh vi vmax vmin vw %].freeze
|
|
12
|
+
SIZES = %w[eighthsize fullsize halfsize initial quartersize].freeze unless const_defined?(:SIZES)
|
|
13
|
+
UNITS = %w[Q ch cm em dvh dvw ex in lh lvh lvw mm pc px pt rem rlh svh svw vb vh vi vmax vmin vw %].freeze unless const_defined?(:UNITS)
|
|
14
14
|
|
|
15
15
|
def attr_alt
|
|
16
16
|
"alt='#{@alt}'" if @alt
|
|
@@ -29,16 +29,19 @@ class ImgProperties
|
|
|
29
29
|
" rel='nofollow'" if @nofollow
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
# FIXME: this method does not work when max-width is specified as a % or a unit such as 15em
|
|
33
|
+
# @return class name: max_fullsize, max_halfsize, max_quartersize
|
|
32
34
|
def attr_max_width_class
|
|
33
35
|
return nil if @max_width == false || @max_width.nil? || max_width_unit_specified?
|
|
34
36
|
|
|
35
|
-
unless SIZES.include?(@max_width)
|
|
37
|
+
unless SIZES.include?(@max_width) || @max_width.end_with?('%')
|
|
36
38
|
msg = "'#{@max_width}' is not a recognized size; must be one of #{SIZES.join(', ')}, or an explicit unit."
|
|
37
39
|
raise Jekyll::ImgError, msg
|
|
38
40
|
end
|
|
39
|
-
"max_#{@max_width}"
|
|
41
|
+
"max_#{@max_width}" # FIXME: this only works with fullsize, halfsize, quartersize and not % or units
|
|
40
42
|
end
|
|
41
43
|
|
|
44
|
+
# FIXME: this method does not work when width is specified as a unit such as 15em
|
|
42
45
|
def attr_size_class
|
|
43
46
|
return nil if @size == false || @size.nil? || size_unit_specified?
|
|
44
47
|
|
|
@@ -50,7 +53,11 @@ class ImgProperties
|
|
|
50
53
|
end
|
|
51
54
|
|
|
52
55
|
def attr_style_img
|
|
53
|
-
|
|
56
|
+
if size_unit_specified?
|
|
57
|
+
"width: #{@size};"
|
|
58
|
+
else
|
|
59
|
+
"style='width: 100%; #{@style}'".squish
|
|
60
|
+
end
|
|
54
61
|
end
|
|
55
62
|
|
|
56
63
|
def attr_target
|
data/lib/jekyll_img/version.rb
CHANGED
data/lib/jekyll_img.rb
CHANGED
data/lib/source.rb
CHANGED
|
@@ -41,7 +41,7 @@ class Source
|
|
|
41
41
|
return result unless result.end_with? '.webp' # we know @path will be a webp after this
|
|
42
42
|
|
|
43
43
|
files = sorted_files
|
|
44
|
-
return files[0] if files.
|
|
44
|
+
return files[0] if files.one?
|
|
45
45
|
|
|
46
46
|
files.each do |filename|
|
|
47
47
|
ext = File.extname filename
|
data/spec/img_builder_spec.rb
CHANGED
|
@@ -3,33 +3,43 @@ require_relative '../lib/img_builder'
|
|
|
3
3
|
require_relative '../lib/img_props'
|
|
4
4
|
require_relative '../lib/source'
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
class ImgTest
|
|
7
|
+
attr_accessor :page, :cite, :url
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
@page = { 'path' => 'mypage.html' }
|
|
11
|
+
@cite = 'this is a cite'
|
|
12
|
+
@url = 'http://localhost:4001/mypage.html'
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
7
16
|
class ImgPropertiesTest
|
|
8
17
|
RSpec.describe ImgBuilder do
|
|
9
18
|
Dir.chdir("demo")
|
|
10
19
|
props = ImgProperties.new
|
|
11
20
|
props.src = '/assets/images/jekyll.webp'
|
|
12
|
-
|
|
21
|
+
img = ImgTest.new
|
|
22
|
+
builder = described_class.new(img, props)
|
|
13
23
|
|
|
14
24
|
it 'generates sources' do
|
|
15
25
|
actual = builder.source.generate
|
|
16
|
-
|
|
26
|
+
expected = [
|
|
17
27
|
'<source srcset="/assets/images/jekyll.webp" type="image/webp">',
|
|
18
28
|
'<source srcset="/assets/images/jekyll.png" type="image/png">'
|
|
19
29
|
]
|
|
20
|
-
expect(actual).to match_array(
|
|
30
|
+
expect(actual).to match_array(expected)
|
|
21
31
|
end
|
|
22
32
|
|
|
23
33
|
it 'generates a figcaption' do
|
|
24
|
-
|
|
34
|
+
expected = <<~END_STRING
|
|
25
35
|
<figcaption class='imgFigCaption '>
|
|
26
36
|
</figcaption>
|
|
27
37
|
END_STRING
|
|
28
|
-
expect(builder.generate_figcaption).to match_ignoring_whitespace(
|
|
38
|
+
expect(builder.generate_figcaption).to match_ignoring_whitespace(expected)
|
|
29
39
|
end
|
|
30
40
|
|
|
31
41
|
it 'generates a picture' do
|
|
32
|
-
|
|
42
|
+
expected = <<~END_DESIRED
|
|
33
43
|
<picture class='imgPicture'>
|
|
34
44
|
<source srcset="/assets/images/jekyll.webp" type="image/webp">
|
|
35
45
|
<source srcset="/assets/images/jekyll.png" type="image/png">
|
|
@@ -40,12 +50,12 @@ class ImgPropertiesTest
|
|
|
40
50
|
</picture>
|
|
41
51
|
END_DESIRED
|
|
42
52
|
actual = builder.generate_picture
|
|
43
|
-
expect(actual).to match_ignoring_whitespace(
|
|
53
|
+
expect(actual).to match_ignoring_whitespace(expected)
|
|
44
54
|
end
|
|
45
55
|
|
|
46
56
|
it 'generates a default img' do
|
|
47
|
-
|
|
48
|
-
<div class='imgWrapper imgFlex' style='
|
|
57
|
+
expected = <<~END_IMG
|
|
58
|
+
<div class='imgWrapper imgFlex' style=''>
|
|
49
59
|
<picture class='imgPicture'>
|
|
50
60
|
<source srcset="/assets/images/jekyll.webp" type="image/webp">
|
|
51
61
|
<source srcset="/assets/images/jekyll.png" type="image/png">
|
|
@@ -58,13 +68,13 @@ class ImgPropertiesTest
|
|
|
58
68
|
END_IMG
|
|
59
69
|
|
|
60
70
|
actual = builder.generate_wrapper
|
|
61
|
-
expect(actual).to match_ignoring_whitespace(
|
|
71
|
+
expect(actual).to match_ignoring_whitespace(expected)
|
|
62
72
|
end
|
|
63
73
|
|
|
64
74
|
it 'generates an img wrapper with size and caption' do
|
|
65
75
|
props.caption = 'This is a caption'
|
|
66
76
|
props.size = '123px'
|
|
67
|
-
builder = described_class.new(props)
|
|
77
|
+
builder = described_class.new(img, props)
|
|
68
78
|
|
|
69
79
|
caption = <<~END_CAPTION
|
|
70
80
|
<figcaption class='imgFigCaption '>
|
|
@@ -72,8 +82,8 @@ class ImgPropertiesTest
|
|
|
72
82
|
</figcaption>
|
|
73
83
|
END_CAPTION
|
|
74
84
|
|
|
75
|
-
|
|
76
|
-
<div class='imgWrapper imgBlock' style='width: 123px;
|
|
85
|
+
expected = <<~END_IMG
|
|
86
|
+
<div class='imgWrapper imgBlock' style='width: 123px;'>
|
|
77
87
|
<figure>
|
|
78
88
|
<picture class='imgPicture'>
|
|
79
89
|
<source srcset="/assets/images/jekyll.webp" type="image/webp">
|
|
@@ -91,7 +101,7 @@ class ImgPropertiesTest
|
|
|
91
101
|
END_IMG
|
|
92
102
|
|
|
93
103
|
actual = builder.generate_wrapper
|
|
94
|
-
expect(actual).to match_ignoring_whitespace(
|
|
104
|
+
expect(actual).to match_ignoring_whitespace(expected)
|
|
95
105
|
end
|
|
96
106
|
end
|
|
97
107
|
end
|
data/spec/img_props_spec.rb
CHANGED
|
@@ -71,30 +71,83 @@ class ImgPropertiesTest
|
|
|
71
71
|
props.size = 'initial'
|
|
72
72
|
expect(props.attr_size_class).to eq('initial')
|
|
73
73
|
|
|
74
|
+
props.target = 'moon'
|
|
75
|
+
expect(props.attr_target).to eq(" target='moon'")
|
|
76
|
+
|
|
77
|
+
props.title = 'The End'
|
|
78
|
+
expect(props.attr_title).to eq("title='The End'")
|
|
79
|
+
|
|
74
80
|
props.size = '100px'
|
|
81
|
+
props.caption = 'A caption'
|
|
75
82
|
expect(props.attr_size_class).to be_nil
|
|
76
|
-
expect(props.attr_style_img).to eq("style='width: 100%; '")
|
|
77
83
|
expect(props.attr_width_style).to eq('width: 100px;')
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it 'generates widths' do
|
|
87
|
+
props = described_class.new
|
|
88
|
+
|
|
89
|
+
props.size = '100px'
|
|
90
|
+
expect(props.attr_size_class).to be_nil
|
|
91
|
+
expect(props.attr_style_img).to eq('width: 100px;')
|
|
92
|
+
expect(props.attr_width_style).to eq('width: 100px;')
|
|
93
|
+
|
|
94
|
+
props.size = '100em'
|
|
95
|
+
expect(props.attr_size_class).to be_nil
|
|
96
|
+
expect(props.attr_style_img).to eq('width: 100em;')
|
|
97
|
+
expect(props.attr_width_style).to eq('width: 100em;')
|
|
78
98
|
|
|
79
99
|
props.size = '10%'
|
|
80
100
|
expect(props.attr_size_class).to be_nil
|
|
81
101
|
expect(props.attr_width_style).to eq('width: 10%;')
|
|
82
|
-
expect(props.attr_style_img).to eq(
|
|
102
|
+
expect(props.attr_style_img).to eq('width: 10%;')
|
|
83
103
|
|
|
84
104
|
props.size = 'fullsize'
|
|
85
105
|
expect(props.attr_size_class).to eq('fullsize')
|
|
86
106
|
expect(props.attr_width_style).to be_nil
|
|
87
107
|
|
|
88
|
-
props.
|
|
89
|
-
expect(props.
|
|
108
|
+
props.size = 'halfsize'
|
|
109
|
+
expect(props.attr_size_class).to eq('halfsize')
|
|
110
|
+
expect(props.attr_width_style).to be_nil
|
|
90
111
|
|
|
91
|
-
props.
|
|
92
|
-
expect(props.
|
|
112
|
+
props.size = 'quartersize'
|
|
113
|
+
expect(props.attr_size_class).to eq('quartersize')
|
|
114
|
+
expect(props.attr_width_style).to be_nil
|
|
93
115
|
|
|
94
|
-
props.size = '
|
|
95
|
-
props.
|
|
96
|
-
expect(props.
|
|
97
|
-
|
|
116
|
+
props.size = 'eighthsize'
|
|
117
|
+
expect(props.attr_size_class).to eq('eighthsize')
|
|
118
|
+
expect(props.attr_width_style).to be_nil
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it 'generates max_widths' do
|
|
122
|
+
props = described_class.new
|
|
123
|
+
|
|
124
|
+
props.max_width = '100px'
|
|
125
|
+
expect(props.attr_max_width_class).to be_nil
|
|
126
|
+
expect(props.attr_max_width_style).to eq('max-width: 100px;')
|
|
127
|
+
|
|
128
|
+
props.max_width = '100em'
|
|
129
|
+
expect(props.attr_max_width_class).to be_nil
|
|
130
|
+
expect(props.attr_max_width_style).to eq('max-width: 100em;')
|
|
131
|
+
|
|
132
|
+
props.max_width = '10%'
|
|
133
|
+
expect(props.attr_max_width_class).to be_nil
|
|
134
|
+
expect(props.attr_max_width_style).to eq('max-width: 10%;')
|
|
135
|
+
|
|
136
|
+
props.max_width = 'fullsize'
|
|
137
|
+
expect(props.attr_max_width_class).to eq('max_fullsize')
|
|
138
|
+
expect(props.attr_max_width_style).to be_nil
|
|
139
|
+
|
|
140
|
+
props.max_width = 'halfsize'
|
|
141
|
+
expect(props.attr_max_width_class).to eq('max_halfsize')
|
|
142
|
+
expect(props.attr_max_width_style).to be_nil
|
|
143
|
+
|
|
144
|
+
props.max_width = 'quartersize'
|
|
145
|
+
expect(props.attr_max_width_class).to eq('max_quartersize')
|
|
146
|
+
expect(props.attr_max_width_style).to be_nil
|
|
147
|
+
|
|
148
|
+
props.max_width = 'eighthsize'
|
|
149
|
+
expect(props.attr_max_width_class).to eq('max_eighthsize')
|
|
150
|
+
expect(props.attr_max_width_style).to be_nil
|
|
98
151
|
end
|
|
99
152
|
end
|
|
100
153
|
end
|
data/spec/jekyll_img_spec.rb
CHANGED
|
@@ -5,7 +5,7 @@ require 'jekyll_plugin_support'
|
|
|
5
5
|
require 'rspec/match_ignoring_whitespace'
|
|
6
6
|
require_relative '../lib/jekyll_img'
|
|
7
7
|
|
|
8
|
-
Registers = Struct.new(:page, :site) unless defined?
|
|
8
|
+
Registers = Struct.new(:page, :site) unless defined? Registers
|
|
9
9
|
|
|
10
10
|
# Mock for Collections
|
|
11
11
|
class Collections
|
|
@@ -56,7 +56,7 @@ class MyTest
|
|
|
56
56
|
)
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
it 'has no cite or url', skip: 'unfinished' do
|
|
60
60
|
helper.reinitialize('src="./blah.webp"')
|
|
61
61
|
img = described_class.send(
|
|
62
62
|
:new,
|
data/spec/spec_helper.rb
CHANGED
|
@@ -3,7 +3,7 @@ require_relative '../lib/jekyll_img'
|
|
|
3
3
|
|
|
4
4
|
RSpec.configure do |config|
|
|
5
5
|
config.filter_run_when_matching focus: true
|
|
6
|
-
config.order = 'random'
|
|
6
|
+
# config.order = 'random'
|
|
7
7
|
|
|
8
8
|
# See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
|
|
9
9
|
config.example_status_persistence_file_path = 'spec/status_persistence.txt'
|
data/spec/status_persistence.txt
CHANGED
|
@@ -3,11 +3,13 @@ example_id | status | run_time |
|
|
|
3
3
|
./spec/img_builder_spec.rb[1:1] | failed | 14.37 seconds |
|
|
4
4
|
./spec/img_builder_spec.rb[1:2] | failed | 0.01498 seconds |
|
|
5
5
|
./spec/img_builder_spec.rb[1:3] | failed | 0.00093 seconds |
|
|
6
|
-
./spec/img_props_spec.rb[1:1] | passed | 0.
|
|
7
|
-
./spec/img_props_spec.rb[1:2] | passed | 0.
|
|
8
|
-
./spec/img_props_spec.rb[1:3] | passed | 0.
|
|
9
|
-
./spec/img_props_spec.rb[1:4] | passed |
|
|
10
|
-
./spec/img_props_spec.rb[1:5] | passed | 0.
|
|
6
|
+
./spec/img_props_spec.rb[1:1] | passed | 0.00174 seconds |
|
|
7
|
+
./spec/img_props_spec.rb[1:2] | passed | 0.00005 seconds |
|
|
8
|
+
./spec/img_props_spec.rb[1:3] | passed | 0.00189 seconds |
|
|
9
|
+
./spec/img_props_spec.rb[1:4] | passed | 0.00126 seconds |
|
|
10
|
+
./spec/img_props_spec.rb[1:5] | passed | 0.00006 seconds |
|
|
11
|
+
./spec/img_props_spec.rb[1:6] | passed | 0.00005 seconds |
|
|
12
|
+
./spec/img_props_spec.rb[1:7] | passed | 0.00005 seconds |
|
|
11
13
|
./spec/jekyll_img_spec.rb[1:1] | failed | 40.84 seconds |
|
|
12
14
|
./spec/source_spec.rb[1:1] | passed | 0.00089 seconds |
|
|
13
15
|
./spec/source_spec.rb[1:2] | passed | 0.0045 seconds |
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jekyll_img
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.11
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mike Slinn
|
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
101
101
|
- !ruby/object:Gem::Version
|
|
102
102
|
version: '0'
|
|
103
103
|
requirements: []
|
|
104
|
-
rubygems_version:
|
|
104
|
+
rubygems_version: 4.0.21
|
|
105
105
|
specification_version: 4
|
|
106
106
|
summary: Provides a Jekyll tag that generates images.
|
|
107
107
|
test_files:
|