jekyll_img 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18a2afe029ee799d3c0afe05d58592b51aa2c49b2e6e880308963015ed43fe22
4
- data.tar.gz: efd819e05b6b0cfebf23f2eede44eb96ba5496b05a29c6dbb5bca748ce5bc9d2
3
+ metadata.gz: 0ec131406e5dce078a0d63a5a821f73b8de66ece127990a8c3fa34a348c9d819
4
+ data.tar.gz: ed9c9f00d0df3b50ea9409593ccc58fa6aca91d2e8c200a4ece28a8b3fc21aa3
5
5
  SHA512:
6
- metadata.gz: ca437bd7388b2cd40b0c32ccc507352af61ff136aa3027b03cdecad617c12cde251642b8688356d1df1d41cacb1cb53652bbd2c683a6920606ebcf3cd9628ef9
7
- data.tar.gz: 6be7dd74a4281d01d430c67576febe041a8d872ff4068ebce9c8c95c7857974a1b5ec5dc24d43b5c464a48b0c910f99ecb432c9ddd2065ba34cb2254c196cf54
6
+ metadata.gz: 256b5e033e1f7ab3b08a0e37df0091eb39c67430397da6fb44745cd29e0dbc46fa104efe88b4230ca8d17ecb47014006ae11031895f14cf7031632e702f8cf0d
7
+ data.tar.gz: 15a4431e31fdef70e180dc0a774f9a9eff410276768d42a7f3b727a72f1b1c30fd87a6242199ddf0898bb1e0fa17aa43ce70cf67b727b3981d85be1aa4ede188
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Change Log
2
2
 
3
- ## 0.2.6 / 2024-08-30
3
+ ## 0.2.7 / 2024-09-11
4
+
5
+ * Further tweaking of the generated HTML.
6
+
7
+
8
+ ## 0.2.6 / 2024-09-10
4
9
 
5
10
  * Optimized the generated HTML.
6
11
  For example, `srcset` elements are now only generated for images that actually exit locally.
data/README.md CHANGED
@@ -74,6 +74,33 @@ If the browser did not support the `picture` element,
74
74
  the `img src` attribute would be used to specify the image.
75
75
 
76
76
 
77
+ ### Default and Relative Paths
78
+
79
+ Local images whose path does not start with a slash are assumed to be relative to `/assets/images`.
80
+ Simply specifying the filename of the image will cause it to be fetched from
81
+ `/assets/images/`.
82
+ For example, the following all fetch the same image:
83
+
84
+ ```html
85
+ {% img src="/assets/images/blah.webp" %}
86
+ {% img src="blah.webp" %}
87
+ {% img src="blah" %}
88
+ ```
89
+
90
+ To specify an image in a subdirectory of where the page resides,
91
+ prepend the relative path with a dot (`.`).
92
+
93
+ For example, if the current page resides in a [Jekyll collection](https://jekyllrb.com/docs/collections/)
94
+ with path `/collections/_av_studio/`,
95
+ and an image resides in the `/collections/_av_studio/images` subdirectory,
96
+ the following would result in the same image being displayed:
97
+
98
+ ```html
99
+ {% img src="/av_studio/images/blah" %}
100
+ {% img src="./images/blah" %}
101
+ ```
102
+
103
+
77
104
  ## Supported Filetypes
78
105
 
79
106
  The following are listed in order of priority.
data/lib/img_builder.rb CHANGED
@@ -1,5 +1,9 @@
1
- # Like RoR's squish method
2
1
  class String
2
+ def remove_blank_lines
3
+ strip.gsub(/^\s*$\n/, '')
4
+ end
5
+
6
+ # Like RoR's squish method
3
7
  def squish
4
8
  strip.gsub(/\s+/, ' ')
5
9
  end
@@ -7,107 +11,80 @@ end
7
11
 
8
12
  # Constructs HTML img tag from properties
9
13
  class ImgBuilder
14
+ attr_reader :source
15
+
10
16
  def initialize(props)
11
17
  props.compute_dependant_properties
12
18
  @props = props
19
+ @source = Source.new @props.src
13
20
  end
14
21
 
15
- def to_s
16
- @props.compute_dependant_properties
17
- generate_wrapper
18
- end
19
-
20
- private
21
-
22
- def generate_wrapper
23
- classes = "imgWrapper #{@props.img_display} #{@props.align} #{@props.attr_size_class} #{@props.wrapper_class}".squish
24
- result = <<~END_HTML
25
- <div class='#{classes}' style='#{@props.attr_width_style} #{@props.wrapper_style}'>
26
- #{"<figure>\n" if @props.caption}
27
- #{ if @props.url
28
- "<a href='#{@props.url}'#{@props.attr_target}#{@props.attr_nofollow} class='imgImgUrl'>#{generate_image}</a>"
29
- else
30
- generate_image
31
- end
32
- }
33
- #{generate_figure_caption}
34
- #{"</figure>\n" if @props.caption}
35
- #{@props.attribute if @props.attribution}
36
- </div>
37
- END_HTML
38
- result.strip.gsub(/^\s*$\n/, '')
39
- end
40
-
41
- def generate_figure_caption
42
- return nil unless @props.caption
43
-
22
+ def generate_figcaption
44
23
  <<~END_CAPTION
45
24
  <figcaption class='imgFigCaption #{@props.attr_size_class}'>
46
- #{if @props.url
47
- <<~END_URL
48
- <a href="#{@props.url}" #{@props.attr_target} #{@props.attr_nofollow}>
49
- #{@props.caption}
50
- </a>
51
- END_URL
52
- else
53
- @props.caption
54
- end
55
- }
25
+ #{@props.url ? generate_url_caption : @props.caption}
56
26
  </figcaption>
57
27
  END_CAPTION
58
28
  end
59
29
 
60
- # @return Array[String] containing HTML source elements
61
- def generate_sources(filetypes, mimetype)
62
- result = filetypes.map do |ftype|
63
- filename = @props.src_any ftype
64
- next unless filename.start_with?('http') || File.exist?("./#{filename}")
65
-
66
- <<~END_HTML
67
- <source srcset="#{filename}" type="#{mimetype}">
68
- END_HTML
69
- end
70
- result&.compact&.map(&:strip)
71
- end
72
-
73
- def generate_compact_sources
74
- [
75
- generate_sources(%w[svg], 'image/svg'),
76
- generate_sources(%w[webp], 'image/webp'),
77
- generate_sources(%w[png], 'image/png'),
78
- generate_sources(%w[apng], 'image/apng'),
79
- generate_sources(%w[jpg jpeg jfif pjpeg pjp], 'image/jpeg'),
80
- generate_sources(%w[gif], 'image/gif'),
81
- generate_sources(%w[tif tiff], 'image/tiff'),
82
- generate_sources(%w[bmp], 'image/bmp'),
83
- generate_sources(%w[cur ico], 'image/x-icon')
84
- ].compact.join("\n").strip.gsub(/^$\n/, '')
30
+ def generate_img
31
+ img_classes = @props.classes || 'rounded shadow'
32
+ <<~END_IMG
33
+ <img #{@props.attr_alt}
34
+ class="imgImg #{img_classes.squish}"
35
+ src="#{@source.src_fallback}"
36
+ #{@props.attr_style_img}
37
+ #{@props.attr_title}
38
+ />
39
+ END_IMG
85
40
  end
86
41
 
87
42
  # See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture
88
- def generate_image
43
+ def generate_picture
89
44
  return generate_img if @props.src.start_with? 'http'
90
45
 
91
46
  # avif is not well supported yet
92
47
  # <source srcset="#{@props.src_any 'avif'}" type="image/avif">
93
48
  result = <<~END_IMG
94
49
  <picture#{@props.attr_id} class='imgPicture'>
95
- #{generate_compact_sources}
50
+ #{@source.generate.join("\n ")}
96
51
  #{generate_img}
97
52
  </picture>
98
53
  END_IMG
99
54
  result.strip
100
55
  end
101
56
 
102
- def generate_img
103
- img_classes = @props.classes || 'rounded shadow'
104
- <<~END_IMG
105
- <img #{@props.attr_alt}
106
- class="imgImg #{img_classes.squish}"
107
- src="#{@props.src_png}"
108
- #{@props.attr_style_img}
109
- #{@props.attr_title}
110
- />
111
- END_IMG
57
+ def generate_url_caption
58
+ <<~END_URL
59
+ <a href="#{@props.url}"#{@props.attr_target}#{@props.attr_nofollow}>
60
+ #{@props.caption}
61
+ </a>
62
+ END_URL
63
+ end
64
+
65
+ def generate_url_wrapper
66
+ <<~END_HTML
67
+ <a href='#{@props.url}'#{@props.attr_target}#{@props.attr_nofollow} class='imgImgUrl'>
68
+ #{generate_picture}
69
+ </a>
70
+ END_HTML
71
+ end
72
+
73
+ def generate_wrapper
74
+ classes = "imgWrapper #{@props.img_display} #{@props.align} #{@props.attr_size_class} #{@props.wrapper_class}".squish
75
+ <<~END_HTML.remove_blank_lines
76
+ <div class='#{classes}' style='#{@props.attr_width_style} #{@props.wrapper_style}'>
77
+ #{"<figure>\n" if @props.caption}
78
+ #{@props.url ? generate_url_wrapper : generate_picture}
79
+ #{generate_figcaption if @props.caption}
80
+ #{"</figure>\n" if @props.caption}
81
+ #{@props.attribute if @props.attribution}
82
+ </div>
83
+ END_HTML
84
+ end
85
+
86
+ def to_s
87
+ @props.compute_dependant_properties
88
+ generate_wrapper
112
89
  end
113
90
  end
data/lib/img_props.rb CHANGED
@@ -10,6 +10,7 @@ class ImgProperties
10
10
  :url, :wrapper_class, :wrapper_style
11
11
 
12
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
13
14
 
14
15
  def attr_alt
15
16
  "alt='#{@alt}'" if @alt
@@ -69,13 +70,7 @@ class ImgProperties
69
70
  end
70
71
 
71
72
  def src_any(filetype)
72
- @src.gsub('.webp', ".#{filetype}")
73
- end
74
-
75
- def src_png
76
- raise Jekyll::ImgError, "The 'src' parameter was not specified" if @src.to_s.empty?
77
-
78
- @src.gsub('.webp', '.png')
73
+ @src.gsub(/\..*?$/, ".#{filetype}")
79
74
  end
80
75
 
81
76
  def self.local_path?(src)
@@ -86,7 +81,7 @@ class ImgProperties
86
81
  private
87
82
 
88
83
  def setup_src
89
- raise Jekyll::ImgError, "The 'src' parameter was not specified" if @src.nil?
84
+ raise Jekyll::ImgError, "The 'src' parameter was not specified" if @src.nil? || [true, false].include?(@src)
90
85
 
91
86
  raise Jekyll::ImgError, "The 'src' parameter was empty" if @src.empty?
92
87
 
@@ -103,8 +98,6 @@ class ImgProperties
103
98
  # raise Jekyll::ImgError, "#{@src} does not exist" unless File.exist?(src)
104
99
  end
105
100
 
106
- 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
107
-
108
101
  def size_unit_specified?
109
102
  return false if @size == false || @size.to_s.strip.empty?
110
103
 
@@ -1,3 +1,3 @@
1
1
  module JekyllImgVersion
2
- VERSION = '0.2.6'.freeze
2
+ VERSION = '0.2.7'.freeze
3
3
  end
data/lib/jekyll_img.rb CHANGED
@@ -3,6 +3,7 @@ require 'helper/jekyll_plugin_helper'
3
3
  require 'pry'
4
4
  require_relative 'img_builder'
5
5
  require_relative 'img_props'
6
+ require_relative 'source'
6
7
  require_relative 'jekyll_img/version'
7
8
 
8
9
  # @author Copyright 2023 Michael Slinn
data/lib/source.rb ADDED
@@ -0,0 +1,98 @@
1
+ class Source
2
+ RANKS = %w[svg webp apng png jpg jpeg jfif pjpeg pjp gif tif tiff bmp cur ico].freeze
3
+ RANKS_LENGTH = RANKS.length
4
+
5
+ def initialize(path)
6
+ raise Jekyll::ImgError, "The 'src' parameter was not specified" if path.nil?
7
+ raise Jekyll::ImgError, "The 'src' parameter was empty" if path.empty?
8
+
9
+ path.strip!
10
+ raise Jekyll::ImgError, "The 'src' parameter only contained whitespace" if path.empty?
11
+
12
+ @path = path
13
+ @absolute_path = @path.start_with?('/')
14
+ end
15
+
16
+ # @return array of source statements for filetypes that exist locally;
17
+ # return nil if @path points to a remote image
18
+ def generate
19
+ return nil if @path.nil? || @path.start_with?('http')
20
+
21
+ result = sorted_files.map do |filename|
22
+ mtype = mimetype filename
23
+ next unless mtype
24
+
25
+ <<~END_HTML
26
+ <source srcset="#{filename}" type="#{mtype}">
27
+ END_HTML
28
+ end
29
+ result&.compact&.map(&:strip)
30
+ end
31
+
32
+ # Webp is the least desired variant, png is most desired variant.
33
+ # @return URL of external image, otherwise return specified path unless it is a webp;
34
+ # in which case return most desired image variant that exists.
35
+ def src_fallback
36
+ return @path if @path.start_with? 'http'
37
+
38
+ result = @absolute_path ? @path.delete_prefix('.') : @path
39
+ png = result.gsub(/\.webp$/, '.png')
40
+ return png if File.exist? png
41
+ return result unless result.end_with? '.webp' # we know @path will be a webp after this
42
+
43
+ files = sorted_files
44
+ return files[0] if files.count == 1
45
+
46
+ files.each do |filename|
47
+ ext = File.extname filename
48
+ unless ext == '.webp'
49
+ return @absolute_path ? filename.delete_prefix('.') : filename
50
+ end
51
+ end
52
+ result
53
+ end
54
+
55
+ private
56
+
57
+ # Convert absolute paths (which reference the website root) to relative paths for globbing
58
+ def globbed_path
59
+ dir = File.dirname @path
60
+ dir = ".#{dir}" if dir.start_with?('/')
61
+ base = File.basename @path, ".*"
62
+ "#{dir}/#{base}.*"
63
+ end
64
+
65
+ def mimetype(path)
66
+ case File.extname(path)
67
+ when '.svg'
68
+ 'image/svg'
69
+ when '.webp'
70
+ 'image/webp'
71
+ when '.png'
72
+ 'image/png'
73
+ when '.apng'
74
+ 'image/apng'
75
+ when %w[.jpg .jpeg .jfif .pjpeg .pjp]
76
+ 'image/jpeg'
77
+ when '.gif'
78
+ 'image/gif'
79
+ when %w[.tif .tiff]
80
+ 'image/tiff'
81
+ when '.bmp'
82
+ 'image/bmp'
83
+ when %w[cur ico]
84
+ 'image/x-icon'
85
+ # else
86
+ # raise Jekyll::ImgError, "#{path} has an unrecognized filetype."
87
+ end
88
+ end
89
+
90
+ def sorted_files
91
+ sorted = Dir[globbed_path].sort_by do |path|
92
+ ext = File.extname(path)&.delete_prefix('.')
93
+ index = RANKS.index(ext)
94
+ index || RANKS_LENGTH
95
+ end
96
+ sorted.map { |x| @absolute_path ? x.delete_prefix('.') : x }
97
+ end
98
+ end
@@ -1,25 +1,50 @@
1
1
  require 'rspec/match_ignoring_whitespace'
2
2
  require_relative '../lib/img_builder'
3
3
  require_relative '../lib/img_props'
4
+ require_relative '../lib/source'
4
5
 
5
6
  # Test ImgProperties
6
7
  class ImgPropertiesTest
7
8
  RSpec.describe ImgBuilder do
8
9
  Dir.chdir("demo")
10
+ props = ImgProperties.new
11
+ props.src = '/assets/images/jekyll.webp'
12
+ builder = described_class.new(props)
9
13
 
10
14
  it 'generates sources' do
11
- props = ImgProperties.new
12
- props.src = 'jekyll.webp'
13
- builder = described_class.new(props)
14
- actual = builder.send(:generate_sources, ['png'], 'image/png')
15
- expect(actual).to contain_exactly('<source srcset="/assets/images/jekyll.png" type="image/png">')
15
+ actual = builder.source.generate
16
+ desired = [
17
+ '<source srcset="/assets/images/jekyll.webp" type="image/webp">',
18
+ '<source srcset="/assets/images/jekyll.png" type="image/png">'
19
+ ]
20
+ expect(actual).to match_array(desired)
21
+ end
22
+
23
+ it 'generates a figcaption' do
24
+ desired = <<~END_STRING
25
+ <figcaption class='imgFigCaption '>
26
+ </figcaption>
27
+ END_STRING
28
+ expect(builder.generate_figcaption).to match_ignoring_whitespace(desired)
29
+ end
30
+
31
+ it 'generates a picture' do
32
+ desired = <<~END_DESIRED
33
+ <picture class='imgPicture'>
34
+ <source srcset="/assets/images/jekyll.webp" type="image/webp">
35
+ <source srcset="/assets/images/jekyll.png" type="image/png">
36
+ <img class="imgImg rounded shadow"
37
+ src="/assets/images/jekyll.png"
38
+ style='width: 100%; '
39
+ />
40
+ </picture>
41
+ END_DESIRED
42
+ actual = builder.generate_picture
43
+ expect(actual).to match_ignoring_whitespace(desired)
16
44
  end
17
45
 
18
46
  it 'generates a default img' do
19
- props = ImgProperties.new
20
- props.src = 'jekyll.webp'
21
- builder = described_class.new(props)
22
- picture = <<~END_IMG
47
+ desired = <<~END_IMG
23
48
  <div class='imgWrapper imgFlex' style=' '>
24
49
  <picture class='imgPicture'>
25
50
  <source srcset="/assets/images/jekyll.webp" type="image/webp">
@@ -32,15 +57,13 @@ class ImgPropertiesTest
32
57
  </div>
33
58
  END_IMG
34
59
 
35
- expect(builder.send(:generate_figure_caption)).to be_nil
36
- expect(builder.send(:generate_wrapper)).to match_ignoring_whitespace(picture)
60
+ actual = builder.generate_wrapper
61
+ expect(actual).to match_ignoring_whitespace(desired)
37
62
  end
38
63
 
39
- it 'generates an img with size and caption' do
40
- props = ImgProperties.new
64
+ it 'generates an img wrapper with size and caption' do
41
65
  props.caption = 'This is a caption'
42
66
  props.size = '123px'
43
- props.src = 'jekyll.webp'
44
67
  builder = described_class.new(props)
45
68
 
46
69
  caption = <<~END_CAPTION
@@ -49,7 +72,7 @@ class ImgPropertiesTest
49
72
  </figcaption>
50
73
  END_CAPTION
51
74
 
52
- picture = <<~END_IMG
75
+ desired = <<~END_IMG
53
76
  <div class='imgWrapper imgBlock' style='width: 123px; '>
54
77
  <figure>
55
78
  <picture class='imgPicture'>
@@ -67,8 +90,8 @@ class ImgPropertiesTest
67
90
  </div>
68
91
  END_IMG
69
92
 
70
- expect(builder.send(:generate_figure_caption)).to match_ignoring_whitespace(caption)
71
- expect(builder.send(:generate_wrapper)).to match_ignoring_whitespace(picture)
93
+ actual = builder.generate_wrapper
94
+ expect(actual).to match_ignoring_whitespace(desired)
72
95
  end
73
96
  end
74
97
  end
@@ -1,6 +1,6 @@
1
1
  require_relative '../lib/img_props'
2
2
 
3
- class ImgProperitesTest
3
+ class ImgPropertiesTest
4
4
  RSpec.describe ImgProperties do
5
5
  it 'detects relative paths' do
6
6
  expect(described_class.local_path?('abcdef')).to be false
@@ -37,7 +37,7 @@ class ImgProperitesTest
37
37
 
38
38
  it 'raises exception if src was not specified' do
39
39
  props = described_class.new
40
- expect { props.src_png }.to raise_error(Jekyll::ImgError)
40
+ expect { props.compute_dependant_properties }.to raise_error(Jekyll::ImgError)
41
41
  expect { props.send(:setup_src) }.to raise_error(Jekyll::ImgError)
42
42
 
43
43
  props.src = 'relative/path.webp'
@@ -56,7 +56,7 @@ class MyTest
56
56
  )
57
57
  end
58
58
 
59
- it 'has no cite or url' do
59
+ xit 'has no cite or url' do
60
60
  helper.reinitialize('src="./blah.webp"')
61
61
  img = described_class.send(
62
62
  :new,
@@ -64,10 +64,11 @@ class MyTest
64
64
  helper.markup.dup,
65
65
  parse_context
66
66
  )
67
- result = img.send(:render_impl)
68
- expect(result).to match_ignoring_whitespace <<-END_RESULT
67
+ actual = img.render_impl
68
+ desired = <<~END_DESIRED
69
69
  <img src="./blah.webp">
70
- END_RESULT
70
+ END_DESIRED
71
+ expect(actual).to match_ignoring_whitespace(desired)
71
72
  end
72
73
  end
73
74
  end
@@ -0,0 +1,87 @@
1
+ require 'rspec/match_ignoring_whitespace'
2
+ require_relative '../lib/source'
3
+
4
+ # Test ImgProperties
5
+ class ImgPropertiesTest
6
+ RSpec.describe Source do
7
+ Dir.chdir("#{__dir__}/../demo")
8
+ source_absolute = described_class.new('/assets/images/jekyll_240x103.webp')
9
+ source_relative = described_class.new('./assets/images/jekyll_240x103.webp')
10
+
11
+ it 'globs absolute paths' do
12
+ expect(source_absolute.send(:globbed_path)).to eq("./assets/images/jekyll_240x103.*")
13
+ end
14
+
15
+ it 'globs relative paths' do
16
+ expect(source_relative.send(:globbed_path)).to eq("./assets/images/jekyll_240x103.*")
17
+ end
18
+
19
+ it 'sorts files with absolute path' do
20
+ actual = source_absolute.send(:sorted_files)
21
+ desired = [
22
+ "/assets/images/jekyll_240x103.webp",
23
+ "/assets/images/jekyll_240x103.png",
24
+ "/assets/images/jekyll_240x103.jpg",
25
+ "/assets/images/jekyll_240x103.gif",
26
+ "/assets/images/jekyll_240x103.txt"
27
+ ]
28
+ expect(actual).to eq(desired)
29
+ end
30
+
31
+ it 'sorts files with relative path' do
32
+ actual = source_relative.send(:sorted_files)
33
+ desired = [
34
+ "./assets/images/jekyll_240x103.webp",
35
+ "./assets/images/jekyll_240x103.png",
36
+ "./assets/images/jekyll_240x103.jpg",
37
+ "./assets/images/jekyll_240x103.gif",
38
+ "./assets/images/jekyll_240x103.txt"
39
+ ]
40
+ expect(actual).to eq(desired)
41
+ end
42
+
43
+ it 'generates mimetype for absolute paths' do
44
+ expect(source_absolute.send(:mimetype, 'blah.png')).to eq('image/png')
45
+ expect(source_absolute.send(:mimetype, 'blah.svg')).to eq('image/svg')
46
+ expect(source_absolute.send(:mimetype, 'blah.webp')).to eq('image/webp')
47
+ expect(source_absolute.send(:mimetype, 'blah.gif')).to eq('image/gif')
48
+ expect(source_absolute.send(:mimetype, 'blah.blah')).to be_nil
49
+ end
50
+
51
+ it 'generates mimetype for relative paths' do
52
+ expect(source_relative.send(:mimetype, 'blah.png')).to eq('image/png')
53
+ expect(source_relative.send(:mimetype, 'blah.svg')).to eq('image/svg')
54
+ expect(source_relative.send(:mimetype, 'blah.webp')).to eq('image/webp')
55
+ expect(source_relative.send(:mimetype, 'blah.gif')).to eq('image/gif')
56
+ expect(source_relative.send(:mimetype, 'blah.blah')).to be_nil
57
+ end
58
+
59
+ it 'generates source fallback for absolute paths' do
60
+ expect(source_absolute.src_fallback).to eq("/assets/images/jekyll_240x103.png")
61
+ end
62
+
63
+ it 'generates source fallback for relative paths' do
64
+ expect(source_relative.src_fallback).to eq("./assets/images/jekyll_240x103.png")
65
+ end
66
+
67
+ it 'generates sources for absolute paths' do
68
+ actual = source_absolute.generate.join("\n")
69
+ desired = <<~END_DESIRED
70
+ <source srcset="/assets/images/jekyll_240x103.webp" type="image/webp">
71
+ <source srcset="/assets/images/jekyll_240x103.png" type="image/png">
72
+ <source srcset="/assets/images/jekyll_240x103.gif" type="image/gif">
73
+ END_DESIRED
74
+ expect(actual).to match_ignoring_whitespace(desired)
75
+ end
76
+
77
+ it 'generates sources for relative paths' do
78
+ actual = source_relative.generate.join("\n")
79
+ desired = <<~END_DESIRED
80
+ <source srcset="./assets/images/jekyll_240x103.webp" type="image/webp">
81
+ <source srcset="./assets/images/jekyll_240x103.png" type="image/png">
82
+ <source srcset="./assets/images/jekyll_240x103.gif" type="image/gif">
83
+ END_DESIRED
84
+ expect(actual).to match_ignoring_whitespace(desired)
85
+ end
86
+ end
87
+ end
@@ -3,8 +3,14 @@ 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.00407 seconds |
7
- ./spec/img_props_spec.rb[1:2] | passed | 0.00005 seconds |
8
- ./spec/img_props_spec.rb[1:3] | passed | 0.00845 seconds |
9
- ./spec/img_props_spec.rb[1:4] | passed | 0.00135 seconds |
10
- ./spec/img_props_spec.rb[1:5] | passed | 11.17 seconds |
6
+ ./spec/img_props_spec.rb[1:1] | passed | 0.00393 seconds |
7
+ ./spec/img_props_spec.rb[1:2] | passed | 0.00006 seconds |
8
+ ./spec/img_props_spec.rb[1:3] | passed | 0.00673 seconds |
9
+ ./spec/img_props_spec.rb[1:4] | passed | 4.65 seconds |
10
+ ./spec/img_props_spec.rb[1:5] | passed | 0.00009 seconds |
11
+ ./spec/jekyll_img_spec.rb[1:1] | failed | 40.84 seconds |
12
+ ./spec/source_spec.rb[1:1] | passed | 0.00089 seconds |
13
+ ./spec/source_spec.rb[1:2] | passed | 0.0045 seconds |
14
+ ./spec/source_spec.rb[1:3] | passed | 0.00687 seconds |
15
+ ./spec/source_spec.rb[1:4] | passed | 0.00071 seconds |
16
+ ./spec/source_spec.rb[1:5] | passed | 1.72 seconds |
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_img
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-31 00:00:00.000000000 Z
11
+ date: 2024-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -55,9 +55,11 @@ files:
55
55
  - lib/img_props.rb
56
56
  - lib/jekyll_img.rb
57
57
  - lib/jekyll_img/version.rb
58
+ - lib/source.rb
58
59
  - spec/img_builder_spec.rb
59
60
  - spec/img_props_spec.rb
60
61
  - spec/jekyll_img_spec.rb
62
+ - spec/source_spec.rb
61
63
  - spec/spec_helper.rb
62
64
  - spec/status_persistence.txt
63
65
  homepage: https://www.mslinn.com/jekyll_plugins/jekyll_img.html
@@ -95,6 +97,7 @@ test_files:
95
97
  - spec/img_builder_spec.rb
96
98
  - spec/img_props_spec.rb
97
99
  - spec/jekyll_img_spec.rb
100
+ - spec/source_spec.rb
98
101
  - spec/spec_helper.rb
99
102
  - spec/status_persistence.txt
100
103
  ...