jekyll_img 0.2.8 → 0.2.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc81e3ae00a242cf25f3444f45da2f621c692d6c7ee4760a17b59e8acc672c4d
4
- data.tar.gz: 8b10b63f09b8b586343fd7a4ccc42c205ad1618cb9b422712d2300838799ead3
3
+ metadata.gz: 2fceb334580b84bf7a4238093ab6fb718d1b5fc84a087b1f554764be2ddae477
4
+ data.tar.gz: b0a489a01ee502e0bb4c6006610a8d82faf3561086fa4f57ce752158e0b9770a
5
5
  SHA512:
6
- metadata.gz: 97b5302cf184c4fa544498354f1a8bae327f1567c438d88a232eef174422425d9e416bd6b0568439c1df2544cfb9b534e3cf0603931e00b9b2ff6a708c00abd5
7
- data.tar.gz: a3ebcc031fb6e63dc92073cf358a38c7092719df8fbf028a5e3376d5b3447e3a539647d0825f47a47c27b45121345c91fecd1af99fc00b1ee816906b71d9c638
6
+ metadata.gz: 14a147fe5e8ee74caffa3c4919d31fc28389ed9c4d5571357fc4797f1efaba10960eb2cefe9a3ebc68a85e76a339acdc9916d1191df11a2f9d1381412fff085a
7
+ data.tar.gz: 9e7b3b29ea91638fd8f54e5320c9fc14ceef0456057cbd40d7b1d5e9c6803cfa65a01c7c76567e147be5cefcf270ce9721c328e65944b8c873ae63591956a180
data/.rubocop.yml CHANGED
@@ -53,13 +53,13 @@ Metrics/BlockLength:
53
53
  - spec/img_props_spec.rb
54
54
 
55
55
  Metrics/CyclomaticComplexity:
56
- Max: 10
56
+ Max: 15
57
57
 
58
58
  Metrics/MethodLength:
59
59
  Max: 40
60
60
 
61
61
  Metrics/PerceivedComplexity:
62
- Max: 10
62
+ Max: 15
63
63
 
64
64
  Naming/FileName:
65
65
  Exclude:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.2.9 / 2025-05-19
4
+
5
+ * `max-width` option added.
6
+ * `width` option added as an alias for `size`.
7
+ This requires new CSS classes to be defined:
8
+ `max_eighthsize`, `max_fullsize`, `max_halfsize`, and `max_quartersize`.
9
+ * More CSS classes defined and more tests added to the Demo app to support `max-width`.
10
+ * `width='calc(something)'` added.
11
+
12
+
3
13
  ## 0.2.8 / 2025-05-16
4
14
 
5
15
  * An image can now be lazily loaded by providing the `lazy` keyword.
data/README.md CHANGED
@@ -249,12 +249,17 @@ $ demo/_bin/debug -r
249
249
  - `caption="A caption"` No default value
250
250
  - `classes="class1 class2 classN"` Extra <img> classes; default is `rounded shadow`
251
251
  - `id="someId"` No default value
252
- - `nofollow` Generates `rel='nofollow'`; only applicable when `url` is specified
253
- - `size='eighthsize|fullsize|halfsize|initial|quartersize|XXXYY|XXX%'`
252
+ - `max-width='eighthsize|fullsize|halfsize|initial|quartersize|XXXYY|XXX%'`
254
253
  Defines width of image.
255
254
  - `initial` is the default behavior.
256
255
  - `eighthsize`, `fullsize`, `halfsize`, and `quartersize` are relative to the enclosing tag's width.
257
256
  - CSS units can also be used, for those cases `XXX` is a float and `YY` is `unit` (see below)
257
+ - `nofollow` Generates `rel='nofollow'`; only applicable when `url` is specified
258
+ - `width='eighthsize|fullsize|halfsize|initial|quartersize|XXXYY|XXX%'`
259
+ Defines width of image (alias for `size`).
260
+ - `initial` is the default behavior.
261
+ - `eighthsize`, `fullsize`, `halfsize`, and `quartersize` are relative to the enclosing tag's width.
262
+ - CSS units can also be used, for those cases `XXX` is a float and `YY` is `unit` (see below)
258
263
  - `style='css goes here'` CSS style for <img>; no default
259
264
  - `target='none|whatever'` Only applicable when `url` is specified; default value is `_blank`
260
265
  - `title="A title"` Default value is `caption` text, if provided
@@ -314,8 +319,9 @@ Within the wrapper `<div />`, the embedded `<img />` is displayed with `width=10
314
319
  If a caption is required, the generated `<figure />` only makes the space taken by the generated HTML longer;
315
320
  the image&rsquo;s width and height are not affected.
316
321
 
317
- The wrapper will not exceed the width of the tag that encloses it if the `size` parameter has values
322
+ The wrapper will not exceed the width of the tag that encloses it if the `width` parameter has values
318
323
  `eighthsize`, `fullsize`, `halfsize`, `initial` or `quartersize`.
324
+ You can also use the `max-width` option.
319
325
 
320
326
  The wrapper's width can be defined independently of its enclosing tag by using
321
327
  [CSS units](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units#numbers_lengths_and_percentages)
data/lib/img_builder.rb CHANGED
@@ -44,10 +44,10 @@ class ImgBuilder
44
44
 
45
45
  # See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture
46
46
  def generate_picture
47
- if @props.lazy && @props.size
47
+ if @props.lazy && (@props.size || @props.max_width)
48
48
  @img.logger.warn do
49
49
  <<~END_MSG.squish
50
- Warning: lazy loading was specified, but the size attribute was specified for the href tag
50
+ Warning: lazy loading was specified, but the size or max_width attribute was specified for the href tag
51
51
  on line #{@img.line_number} (after front matter) of #{@img.page['path']}.
52
52
  Specify dimensions via style or class attributes instead.
53
53
  END_MSG
@@ -84,9 +84,11 @@ class ImgBuilder
84
84
  end
85
85
 
86
86
  def generate_wrapper
87
- classes = "imgWrapper #{@props.img_display} #{@props.align} #{@props.attr_size_class} #{@props.wrapper_class}".squish
87
+ classes = ("imgWrapper #{@props.img_display} #{@props.align} #{@props.attr_size_class} " +
88
+ "#{@props.attr_max_width_class} #{@props.wrapper_class}").squish
89
+ styles = "#{@props.attr_width_style} #{@props.attr_max_width_style} #{@props.wrapper_style}".squish
88
90
  <<~END_HTML.remove_blank_lines
89
- <div class='#{classes}' style='#{@props.attr_width_style} #{@props.wrapper_style}'>
91
+ <div class='#{classes}' style='#{styles}'>
90
92
  #{"<figure>\n" if @props.caption}
91
93
  #{@props.url ? generate_url_wrapper : generate_picture}
92
94
  #{generate_figcaption if @props.caption}
data/lib/img_props.rb CHANGED
@@ -6,8 +6,8 @@ require 'uri'
6
6
  # All methods except compute_dependant_properties can be called in any order
7
7
  class ImgProperties
8
8
  attr_accessor :align, :alt, :attr_wrapper_align_class, :attribute, :attribution, :caption, :classes, :die_on_img_error,
9
- :id, :img_display, :lazy, :local_src, :nofollow, :priority, :src, :size, :style, :target, :title,
10
- :url, :wrapper_class, :wrapper_style
9
+ :id, :img_display, :lazy, :local_src, :max_width, :nofollow, :priority, :src, :size, :style,
10
+ :target, :title, :url, :wrapper_class, :wrapper_style
11
11
 
12
12
  SIZES = %w[eighthsize fullsize halfsize initial quartersize].freeze
13
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
@@ -29,6 +29,16 @@ class ImgProperties
29
29
  " rel='nofollow'" if @nofollow
30
30
  end
31
31
 
32
+ def attr_max_width_class
33
+ return nil if @max_width == false || @max_width.nil? || max_width_unit_specified?
34
+
35
+ unless SIZES.include?(@max_width)
36
+ msg = "'#{@max_width}' is not a recognized size; must be one of #{SIZES.join(', ')}, or an explicit unit."
37
+ raise Jekyll::ImgError, msg
38
+ end
39
+ "max_#{@max_width}"
40
+ end
41
+
32
42
  def attr_size_class
33
43
  return nil if @size == false || @size.nil? || size_unit_specified?
34
44
 
@@ -54,6 +64,10 @@ class ImgProperties
54
64
  "title='#{@title}'" if @title && !@title.empty?
55
65
  end
56
66
 
67
+ def attr_max_width_style
68
+ "max-width: #{@max_width};" if max_width_unit_specified?
69
+ end
70
+
57
71
  def attr_width_style
58
72
  "width: #{@size};" if size_unit_specified?
59
73
  end
@@ -98,10 +112,18 @@ class ImgProperties
98
112
  # raise Jekyll::ImgError, "#{@src} does not exist" unless File.exist?(src)
99
113
  end
100
114
 
115
+ def max_width_unit_specified?
116
+ max_width_not_specified = @max_width == false || @max_width.to_s.strip.empty?
117
+ return false if max_width_not_specified
118
+
119
+ @max_width&.end_with?(*UNITS) || @max_width&.start_with?('calc')
120
+ end
121
+
101
122
  def size_unit_specified?
102
- return false if @size == false || @size.to_s.strip.empty?
123
+ size_not_specified = @size == false || @size.to_s.strip.empty?
124
+ return false if size_not_specified
103
125
 
104
- @size.end_with?(*UNITS)
126
+ @size&.end_with?(*UNITS) || @size&.start_with?('calc')
105
127
  end
106
128
 
107
129
  def url?(src)
@@ -1,3 +1,3 @@
1
1
  module JekyllImgVersion
2
- VERSION = '0.2.8'.freeze
2
+ VERSION = '0.2.9'.freeze
3
3
  end
data/lib/jekyll_img.rb CHANGED
@@ -36,9 +36,12 @@ module Jekyll
36
36
  props.die_on_img_error = @die_on_img_error
37
37
  props.id = @helper.parameter_specified? 'id'
38
38
  props.lazy = ' loading="lazy"' if @helper.parameter_specified?('lazy')
39
+ props.max_width = @helper.parameter_specified?('max-width')
39
40
  props.nofollow = @helper.parameter_specified? 'nofollow'
40
41
  props.priority = ' fetchpriority="high"' if @helper.parameter_specified?('priority')
41
- props.size = @helper.parameter_specified?('size') || @helper.parameter_specified?('_size')
42
+ props.size = @helper.parameter_specified?('size') ||
43
+ @helper.parameter_specified?('_size') ||
44
+ @helper.parameter_specified?('width')
42
45
  props.src = @helper.parameter_specified? 'src'
43
46
  props.style = @helper.parameter_specified? 'style'
44
47
  props.target = @helper.parameter_specified? 'target'
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.8
4
+ version: 0.2.9
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: 3.6.9
104
+ rubygems_version: 3.7.1
105
105
  specification_version: 4
106
106
  summary: Provides a Jekyll tag that generates images.
107
107
  test_files: