jekyll_img 0.1.1 → 0.1.3

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: 364a5201d2ce55db3436164ed8f4430c22533e4cea3e8b188794b919e56c3b17
4
- data.tar.gz: df95180013a8deaa425a364474eb3afd2fffce5b859dafe7e9a0fe0989b4676b
3
+ metadata.gz: 8d314eb97784260ac71168aa8dc6da63e0dec2238d75a9e57b4662ba103cf47c
4
+ data.tar.gz: b353c583b4334d7c49c1961b6c383b34014449834f852e9f14e9eeccb31b78b4
5
5
  SHA512:
6
- metadata.gz: fe8432b3c99ba15ba90c5cdb61c4cb70de160f2fd1cbb86f44a52b581205bbad04ca28f2b102279c469680f136ddf41e05d302ce8c5b54418ee72346d2596ca8
7
- data.tar.gz: 880d4924b96382076caef882d1585c1b76a5f5a5cfb8c651c0420ac5973a80c96fbe38de873f1b7191fcdbd9257fd5843598cbf43671bf8cbfe6bb4a722ab315
6
+ metadata.gz: 30ae18bc4ff268d928b503f55e7ba847a7ae767864a0dad41ffc80728afaab88aae8b8e17b4f5d2381ff75c0ecfb7a4a5f4cf3dd399fe05a8a1268f1d1a32505
7
+ data.tar.gz: 91bfb7286db21ac8933a823cdaa2c6af2d31dc1734d9dd0b2222bf90a515a1b04d3119f21b438badd7fddf969ed9f1a2c93e2642763cd1af3a1a5b00b9807bea
data/.rubocop.yml CHANGED
@@ -1,3 +1,13 @@
1
+ require:
2
+ # - rubocop-jekyll
3
+ - rubocop-md
4
+ - rubocop-performance
5
+ - rubocop-rake
6
+ - rubocop-rspec
7
+
8
+ # inherit_gem:
9
+ # rubocop-jekyll: .rubocop.yml
10
+
1
11
  AllCops:
2
12
  Exclude:
3
13
  - vendor/**/*
@@ -7,17 +17,33 @@ AllCops:
7
17
  NewCops: enable
8
18
  TargetRubyVersion: 2.6
9
19
 
10
- Layout/HashAlignment:
20
+ Gemspec/DeprecatedAttributeAssignment:
21
+ Enabled: false
22
+
23
+ Gemspec/RequireMFA:
11
24
  Enabled: false
12
25
 
26
+ Layout/InitialIndentation:
27
+ Exclude:
28
+ - README.md
29
+
30
+ Layout/HashAlignment:
31
+ EnforcedColonStyle: table
32
+ Exclude:
33
+ - jekyll_img.gemspec
34
+
13
35
  Layout/LineLength:
14
36
  Max: 150
15
37
 
16
38
  Layout/MultilineMethodCallIndentation:
17
39
  Enabled: false
18
40
 
41
+ Lint/RedundantCopDisableDirective:
42
+ Exclude:
43
+ - jekyll_img.gemspec
44
+
19
45
  Metrics/AbcSize:
20
- Max: 40
46
+ Max: 45
21
47
 
22
48
  Metrics/BlockLength:
23
49
  Max: 30
@@ -34,8 +60,40 @@ Metrics/MethodLength:
34
60
  Metrics/PerceivedComplexity:
35
61
  Max: 10
36
62
 
63
+ Naming/FileName:
64
+ Exclude:
65
+ - Rakefile
66
+
67
+ Naming/MemoizedInstanceVariableName:
68
+ Enabled: false
69
+
70
+ RSpec/ExampleLength:
71
+ Enabled: false
72
+
73
+ RSpec/MultipleExpectations:
74
+ Enabled: false
75
+
76
+ Style/CommandLiteral:
77
+ Enabled: false
78
+
79
+ Style/CommentedKeyword:
80
+ Enabled: false
81
+
82
+ Style/Documentation:
83
+ Enabled: false
84
+
37
85
  Style/FrozenStringLiteralComment:
38
86
  Enabled: false
39
87
 
40
- Style/TrailingCommaInHashLiteral:
88
+ Style/StringConcatenation:
89
+ Exclude:
90
+ - spec/**/*
91
+
92
+ Style/StringLiterals:
41
93
  Enabled: false
94
+
95
+ Style/StringLiteralsInInterpolation:
96
+ Enabled: false
97
+
98
+ Style/TrailingCommaInHashLiteral:
99
+ EnforcedStyleForMultiline: comma
data/CHANGELOG.md CHANGED
@@ -1,2 +1,9 @@
1
+ ## 0.1.3 / 2023-02-22
2
+ * Added `img/continue_on_error` configuration parameter.
3
+
4
+ ## 0.1.2 / 2023-02-14
5
+ * Fixed `img_props.rb:91:in `size_unit_specified?': undefined method `end_with?' for false:FalseClass (NoMethodError)`
6
+
7
+
1
8
  ## 0.1.1 / 2023-02-12
2
9
  * Initial release
data/README.md CHANGED
@@ -44,6 +44,16 @@ $ demo/_bin/debug -r
44
44
  CSS classes referenced by the `jekyll_img` plugin are at the bottom of [demo/assets/css/style.css](demo/assets/css/style.css). CSS marker classes are included, so CSS selectors can be used for additional styling.
45
45
 
46
46
 
47
+ ## Configuration
48
+ By default, any errors cause Jekyll to abort.
49
+ You can allow Jekyll to continue by setting the following in `_config.yml`:
50
+
51
+ ```yaml
52
+ img:
53
+ continue_on_error: true
54
+ ```
55
+
56
+
47
57
  ## Design
48
58
  The most significant design issue was the decision that image size and formatting should not change
49
59
  whether it had a caption.
data/jekyll_img.gemspec CHANGED
@@ -29,8 +29,5 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
29
29
  spec.version = JekyllImgVersion::VERSION
30
30
 
31
31
  spec.add_dependency 'jekyll', '>= 3.5.0'
32
- spec.add_dependency 'jekyll_plugin_support', '>= 0.3.1'
33
-
34
- spec.add_development_dependency 'rspec'
35
- spec.add_development_dependency 'rspec-match_ignoring_whitespace'
32
+ spec.add_dependency 'jekyll_plugin_support', '~> 0.5.1'
36
33
  end
data/lib/img_props.rb CHANGED
@@ -1,10 +1,13 @@
1
+ class ImgError < StandardError; end
2
+
1
3
  # Properties from user
2
4
  # All methods are idempotent.
3
5
  # attr_ methods can be called after compute_dependant_properties
4
6
  # All methods except compute_dependant_properties can be called in any order
5
7
  class ImgProperties
6
- attr_accessor :align, :alt, :attr_wrapper_align_class, :caption, :classes, :id, :img_display, :nofollow, \
7
- :src, :size, :style, :target, :title, :url, :wrapper_class, :wrapper_style
8
+ attr_accessor :align, :alt, :attr_wrapper_align_class, :caption, :classes, :continue_on_error, \
9
+ :id, :img_display, :nofollow, :src, :size, :style, :target, :title, \
10
+ :url, :wrapper_class, :wrapper_style
8
11
 
9
12
  SIZES = %w[eighthsize fullsize halfsize initial quartersize].freeze
10
13
 
@@ -26,10 +29,12 @@ class ImgProperties
26
29
  end
27
30
 
28
31
  def attr_size_class
29
- return nil if @size.nil? || size_unit_specified?
32
+ return nil if @size == false || @size.nil? || size_unit_specified?
30
33
 
31
- abort "'#{@size}' is not a recognized size; must be one of #{SIZES.join(', ')}, or an explicit unit." \
32
- unless SIZES.include?(@size)
34
+ unless SIZES.include?(@size)
35
+ msg = "'#{@size}' is not a recognized size; must be one of #{SIZES.join(', ')}, or an explicit unit."
36
+ raise ImgError, msg
37
+ end
33
38
  @size
34
39
  end
35
40
 
@@ -60,11 +65,11 @@ class ImgProperties
60
65
  @img_display = @caption && @size ? 'imgBlock' : 'imgFlex'
61
66
 
62
67
  @alt ||= @caption || @title
63
- @title ||= @caption || @alt # rubocop:disable Naming/MemoizedInstanceVariableName
68
+ @title ||= @caption || @alt
64
69
  end
65
70
 
66
71
  def src_png
67
- abort 'src parameter was not specified' if @src.to_s.empty?
72
+ raise ImgError, "The 'src' parameter was not specified" if @src.to_s.empty?
68
73
 
69
74
  @src.gsub('.webp', '.png')
70
75
  end
@@ -78,7 +83,7 @@ class ImgProperties
78
83
 
79
84
  def setup_src
80
85
  @src = @src.to_s.strip
81
- abort 'src parameter was not specified' if @src.empty?
86
+ raise ImgError, "The 'src' parameter was not specified", [] if @src.empty?
82
87
 
83
88
  @src = "/assets/images/#{@src}" unless ImgProperties.local_path?(@src) || url?(@src)
84
89
  end
@@ -86,7 +91,7 @@ class ImgProperties
86
91
  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
87
92
 
88
93
  def size_unit_specified?
89
- return false if @size.to_s.strip.empty?
94
+ return false if @size == false || @size.to_s.strip.empty?
90
95
 
91
96
  @size.end_with?(*UNITS)
92
97
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllImgVersion
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
data/lib/jekyll_img.rb CHANGED
@@ -14,28 +14,41 @@ end
14
14
  module Jekyll
15
15
  # Plugin implementation
16
16
  class Img < JekyllSupport::JekyllTag
17
- def render_impl
17
+ include JekyllImgVersion
18
+
19
+ def render_impl # rubocop:disable Metrics/AbcSize
20
+ config = @config['img']
21
+ @continue_on_error = config['continue_on_error'] == true if config
22
+
18
23
  props = ImgProperties.new
19
- props.align = @helper.parameter_specified?('align') || 'inline'
20
- props.alt = @helper.parameter_specified? 'alt'
21
- props.caption = @helper.parameter_specified? 'caption'
22
- props.classes = @helper.parameter_specified? 'class'
23
- props.id = @helper.parameter_specified? 'id'
24
- props.nofollow = @helper.parameter_specified? 'nofollow'
25
- props.size = @helper.parameter_specified?('size') || @helper.parameter_specified?('_size')
26
- props.src = @helper.parameter_specified? 'src'
27
- props.style = @helper.parameter_specified? 'style'
28
- props.target = @helper.parameter_specified? 'target'
29
- props.title = @helper.parameter_specified? 'title'
30
- props.url = @helper.parameter_specified? 'url'
31
- props.wrapper_class = @helper.parameter_specified? 'wrapper_class'
32
- props.wrapper_style = @helper.parameter_specified? 'wrapper_style'
24
+ props.align = @helper.parameter_specified?('align') || 'inline'
25
+ props.alt = @helper.parameter_specified? 'alt'
26
+ props.caption = @helper.parameter_specified? 'caption'
27
+ props.classes = @helper.parameter_specified? 'class'
28
+ props.continue_on_error = @continue_on_error
29
+ props.id = @helper.parameter_specified? 'id'
30
+ props.nofollow = @helper.parameter_specified? 'nofollow'
31
+ props.size = @helper.parameter_specified?('size') || @helper.parameter_specified?('_size')
32
+ props.src = @helper.parameter_specified? 'src'
33
+ props.style = @helper.parameter_specified? 'style'
34
+ props.target = @helper.parameter_specified? 'target'
35
+ props.title = @helper.parameter_specified? 'title'
36
+ props.url = @helper.parameter_specified? 'url'
37
+ props.wrapper_class = @helper.parameter_specified? 'wrapper_class'
38
+ props.wrapper_style = @helper.parameter_specified? 'wrapper_style'
33
39
 
34
40
  @builder = ImgBuilder.new(props)
35
41
  @builder.to_s
42
+ rescue ImgError => e
43
+ msg = <<~END_ERR
44
+ #{e.message} on line #{@line_number} (after front matter) of #{@page['path']}.
45
+ The offending argument string was: #{@argument_string}
46
+ END_ERR
47
+ raise ImgError, msg.red, [] unless @continue_on_error
48
+
49
+ @logger.warn msg
36
50
  end
51
+
52
+ JekyllPluginHelper.register(self, ImgModule::PLUGIN_NAME)
37
53
  end
38
54
  end
39
-
40
- PluginMetaLogger.instance.info { "Loaded #{ImgModule::PLUGIN_NAME} v0.1.0 plugin." }
41
- Liquid::Template.register_tag(ImgModule::PLUGIN_NAME, Jekyll::Img)
@@ -4,11 +4,11 @@ require_relative '../lib/img_props'
4
4
 
5
5
  # Test ImgProperties
6
6
  class ImgPropertiesTest
7
- RSpec.describe ImgBuilder do # rubocop:disable Metrics/BlockLength
7
+ RSpec.describe ImgBuilder do
8
8
  it 'generates a default img' do
9
9
  props = ImgProperties.new
10
10
  props.src = 'blah.webp'
11
- builder = ImgBuilder.new(props)
11
+ builder = described_class.new(props)
12
12
  picture = <<~END_IMG
13
13
  <div class='imgWrapper imgFlex' style=' '>
14
14
  <picture class='imgPicture'>
@@ -22,7 +22,7 @@ class ImgPropertiesTest
22
22
  </div>
23
23
  END_IMG
24
24
 
25
- expect(builder.send(:generate_figure_caption)).to be nil
25
+ expect(builder.send(:generate_figure_caption)).to be_nil
26
26
  expect(builder.send(:generate_wrapper)).to match_ignoring_whitespace(picture)
27
27
  end
28
28
 
@@ -31,7 +31,7 @@ class ImgPropertiesTest
31
31
  props.caption = 'This is a caption'
32
32
  props.size = '123px'
33
33
  props.src = 'blah.webp'
34
- builder = ImgBuilder.new(props)
34
+ builder = described_class.new(props)
35
35
 
36
36
  caption = <<~END_CAPTION
37
37
  <figcaption class='imgFigCaption '>
@@ -1,39 +1,38 @@
1
1
  require_relative '../lib/img_props'
2
2
 
3
- # Test ImgProperties
4
3
  class ImgProperitesTest
5
- RSpec.describe ImgProperties do # rubocop:disable Metrics/BlockLength
4
+ RSpec.describe ImgProperties do
6
5
  it 'detects relative paths' do
7
- expect(ImgProperties.local_path?('abcdef')).to be false
8
- expect(ImgProperties.local_path?('./abc')).to be true
9
- expect(ImgProperties.local_path?('/abc')).to be true
6
+ expect(described_class.local_path?('abcdef')).to be false
7
+ expect(described_class.local_path?('./abc')).to be true
8
+ expect(described_class.local_path?('/abc')).to be true
10
9
  end
11
10
 
12
11
  it 'has other class methods' do
13
- props = ImgProperties.new
12
+ props = described_class.new
14
13
  expect(props.send(:size_unit_specified?)).to be false
15
14
  expect(props.send(:url?, 'blah')).to be false
16
15
  expect(props.send(:url?, 'http://blah')).to be true
17
16
  end
18
17
 
19
18
  it 'does not generate attributes for most empty properties' do
20
- props = ImgProperties.new
21
- expect(props.attr_alt).to be nil
19
+ props = described_class.new
20
+ expect(props.attr_alt).to be_nil
22
21
  expect(props.attr_img_classes).to eq('rounded shadow')
23
- expect(props.attr_id).to be nil
24
- expect(props.attr_nofollow).to be nil
25
- expect(props.attr_size_class).to be nil
22
+ expect(props.attr_id).to be_nil
23
+ expect(props.attr_nofollow).to be_nil
24
+ expect(props.attr_size_class).to be_nil
26
25
  expect(props.attr_style_img).to eq("style='width: 100%; '")
27
26
  expect(props.attr_target).to eq(" target='_blank'")
28
- expect(props.attr_title).to be nil
29
- expect(props.attr_width_style).to be nil
27
+ expect(props.attr_title).to be_nil
28
+ expect(props.attr_width_style).to be_nil
30
29
 
31
30
  props.compute_dependant_properties
32
31
  expect(props.attr_wrapper_align_class).to eq('inline')
33
32
  end
34
33
 
35
34
  it 'raises exception if src was not specified' do
36
- props = ImgProperties.new
35
+ props = described_class.new
37
36
  expect { props.src_png }.to raise_error(SystemExit)
38
37
  expect { props.send(:setup_src) }.to raise_error(SystemExit)
39
38
 
@@ -50,8 +49,8 @@ class ImgProperitesTest
50
49
  expect(props.src).to eq('/absolute/path.webp')
51
50
  end
52
51
 
53
- it 'generates proper simple attributes' do # rubocop:disable Metrics/BlockLength
54
- props = ImgProperties.new
52
+ it 'generates proper simple attributes' do
53
+ props = described_class.new
55
54
 
56
55
  props.alt = 'blah'
57
56
  expect(props.attr_alt).to eq("alt='blah'")
@@ -69,18 +68,18 @@ class ImgProperitesTest
69
68
  expect(props.attr_size_class).to eq('initial')
70
69
 
71
70
  props.size = '100px'
72
- expect(props.attr_size_class).to be nil
71
+ expect(props.attr_size_class).to be_nil
73
72
  expect(props.attr_style_img).to eq("style='max-width: 100px;'")
74
73
  expect(props.attr_width_style).to eq('width: 100px;')
75
74
 
76
75
  props.size = '10%'
77
- expect(props.attr_size_class).to be nil
76
+ expect(props.attr_size_class).to be_nil
78
77
  expect(props.attr_style_img).to eq("style='max-width: 10%;'")
79
78
  expect(props.attr_width_style).to eq('width: 10%;')
80
79
 
81
80
  props.size = 'fullsize'
82
81
  expect(props.attr_size_class).to eq('fullsize')
83
- expect(props.attr_width_style).to be nil
82
+ expect(props.attr_width_style).to be_nil
84
83
 
85
84
  props.style = 'width: 30rem;'
86
85
  expect(props.attr_style_img).to eq("style='width: 30rem;'")
@@ -93,12 +92,12 @@ class ImgProperitesTest
93
92
 
94
93
  props.size = '100px'
95
94
  props.caption = 'A caption'
96
- expect(props.attr_size_class).to be nil
95
+ expect(props.attr_size_class).to be_nil
97
96
  expect(props.attr_width_style).to eq('width: 100px;')
98
97
  end
99
98
 
100
99
  it 'generates proper alignment attributes' do
101
- props = ImgProperties.new
100
+ props = described_class.new
102
101
 
103
102
  props.align = 'inline'
104
103
  props.compute_dependant_properties
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require 'jekyll'
4
2
  require 'jekyll_plugin_logger'
5
3
  require 'rspec/match_ignoring_whitespace'
@@ -32,7 +30,7 @@ class TestParseContext < Liquid::ParseContext
32
30
  @line_number = 123
33
31
 
34
32
  @registers = Registers.new(
35
- { },
33
+ {},
36
34
  SiteMock.new
37
35
  )
38
36
  end
@@ -57,7 +55,7 @@ class MyTest
57
55
 
58
56
  it 'has no cite or url' do
59
57
  helper.reinitialize('src="./blah.webp"')
60
- quote = Jekyll::Img.send(
58
+ quote = described_class.send(
61
59
  :new,
62
60
  'img',
63
61
  helper.markup.dup,
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.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-12 00:00:00.000000000 Z
11
+ date: 2023-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -28,44 +28,16 @@ dependencies:
28
28
  name: jekyll_plugin_support
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.3.1
33
+ version: 0.5.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: 0.3.1
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec-match_ignoring_whitespace
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
38
+ - - "~>"
67
39
  - !ruby/object:Gem::Version
68
- version: '0'
40
+ version: 0.5.1
69
41
  description:
70
42
  email:
71
43
  - mslinn@mslinn.com
@@ -87,7 +59,6 @@ files:
87
59
  - spec/img_props_spec.rb
88
60
  - spec/jekyll_img_spec.rb
89
61
  - spec/spec_helper.rb
90
- - spec/status_persistence.txt
91
62
  homepage: https://mslinn.com/jekyll/3000-jekyll-plugins.html#jekyll_img
92
63
  licenses:
93
64
  - MIT
@@ -124,5 +95,4 @@ test_files:
124
95
  - spec/img_props_spec.rb
125
96
  - spec/jekyll_img_spec.rb
126
97
  - spec/spec_helper.rb
127
- - spec/status_persistence.txt
128
98
  ...
@@ -1,10 +0,0 @@
1
- example_id | status | run_time |
2
- ------------------------------- | ------ | --------------- |
3
- ./spec/img_builder_spec.rb[1:1] | passed | 0.00073 seconds |
4
- ./spec/img_props_spec.rb[1:1] | passed | 0.0001 seconds |
5
- ./spec/img_props_spec.rb[1:2] | passed | 0.00008 seconds |
6
- ./spec/img_props_spec.rb[1:3] | failed | 0.00051 seconds |
7
- ./spec/img_props_spec.rb[1:4] | passed | 0.0011 seconds |
8
- ./spec/img_props_spec.rb[1:5] | passed | 0.00019 seconds |
9
- ./spec/img_props_spec.rb[1:6] | failed | 0.00008 seconds |
10
- ./spec/jekyll_img_spec.rb[1:1] | failed | 0.00037 seconds |