jekyll_img 0.1.6 → 0.2.0

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: 893b2811f139eeae284d17d29a4b9c6b8348aebaf7b5fd54015bda14316bea17
4
- data.tar.gz: 58f626e32417dfa0790115903453b575cacbab46d312144f741dbec6b05eb458
3
+ metadata.gz: 4f1c3ada28bfae9fa70ff421baa912391a64af4c156055e0f40438d6219c986b
4
+ data.tar.gz: 6915f59b67c6c0de7d91821553b4ecb7f246596f295d128ba6a850b6ddfb35af
5
5
  SHA512:
6
- metadata.gz: d43b8d2c08e13776f29fa59d56750369243909ad74cb4ff66add5050576d49e83cf53a997932f3bf12797fa0fc67ec2e65f9fa782c8a201323a92c0f6c004435
7
- data.tar.gz: 0ee7e15f89ef2a4f9755b418bd26893edcd77b3cdaa7c3015b6923509d0a0b077b1700161be9aeef227bd8f7b9fd39067e57e527d5ade7787bab577912a77019
6
+ metadata.gz: 0c8281613ba38488ce8b32ac074abca3ce3ed7310d0fd70a0f6d78c87039b66a40b25775172ff88e910dcdb09cd9b78549bf4a1773a982e5a8c23f2109679f0d
7
+ data.tar.gz: 8ada70004b3b1328372f2675ed7b80edf1c6b9a1b2fdd44154a2ad40af1d9d1a64bbda2d53034394c860b79fd9489b74de4dd4542f9daf6db6be534df13e7c85
data/.rubocop.yml CHANGED
@@ -11,15 +11,17 @@ require:
11
11
  AllCops:
12
12
  Exclude:
13
13
  - vendor/**/*
14
- - exe/**/*
14
+ - binstub/**/*
15
15
  - Gemfile*
16
16
  - Rakefile
17
17
  NewCops: enable
18
- TargetRubyVersion: 2.6
19
18
 
20
19
  Gemspec/DeprecatedAttributeAssignment:
21
20
  Enabled: false
22
21
 
22
+ Gemspec/RequiredRubyVersion:
23
+ Enabled: false
24
+
23
25
  Gemspec/RequireMFA:
24
26
  Enabled: false
25
27
 
@@ -42,7 +44,7 @@ Lint/RedundantCopDisableDirective:
42
44
  - jekyll_img.gemspec
43
45
 
44
46
  Metrics/AbcSize:
45
- Max: 45
47
+ Max: 60
46
48
 
47
49
  Metrics/BlockLength:
48
50
  Max: 30
@@ -54,7 +56,7 @@ Metrics/CyclomaticComplexity:
54
56
  Max: 10
55
57
 
56
58
  Metrics/MethodLength:
57
- Max: 30
59
+ Max: 40
58
60
 
59
61
  Metrics/PerceivedComplexity:
60
62
  Max: 10
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.2.0 / 2023-11-20
4
+
5
+ * The [demo/](demo/) webapp has been upgraded to the latest features.
6
+ * Improved error messages.
7
+ * Renamed the `img` section of `_config.yml` to `jekyll_img`.
8
+ * Renamed `continue_on_error` to `die_on_img_error` and reversed the meaning.
9
+ * Now dependant on `jekyll_plugin_support` v0.8.0 or later, which had several breaking changes.
10
+ * CSS for this plugin is now defined in `demo/assets/css/jekyll_img.css`.
11
+ * Added a `pry_on_img_error` setting, which causes the `pry` debugger to be invoked when an `ImgError` is raised.
12
+ `pry` is now opened when an `ImgError` is raised if `_config.yml` contains:
13
+
14
+ ```yaml
15
+ jekyll_img:
16
+ pry_on_img_error: true
17
+ ```
18
+
3
19
  ## 0.1.6 / 2023-08-10
4
20
 
5
21
  * `.webp` file type is assumed and no longer needs to be specified.
@@ -34,7 +50,7 @@
34
50
 
35
51
  ## 0.1.2 / 2023-02-14
36
52
 
37
- * Fixed `img_props.rb:91:in `size_unit_specified?': undefined method `end_with?' for false:FalseClass (NoMethodError)`
53
+ * Fixed `img_props.rb:91:in size_unit_specified?: undefined method end_with? for false:FalseClass (NoMethodError)`
38
54
 
39
55
 
40
56
  ## 0.1.1 / 2023-02-12
data/README.md CHANGED
@@ -33,7 +33,7 @@ For example, these two invocations yield the same result:
33
33
  {% img src="blah.webp" %}
34
34
  ```
35
35
 
36
- Would conceptually generate the following
36
+ The above generates the following
37
37
  (to support the other options, the generated HTML can be a lot more complex):
38
38
 
39
39
  ```html
@@ -86,23 +86,26 @@ $ demo/_bin/debug -r
86
86
  - `wrapper_class='class1 class2 classN'` Extra CSS classes for wrapper <div>; no default value
87
87
  - `wrapper_style='background-color: black;'` CSS style for wrapper <div>; no default value
88
88
 
89
- [`unit`](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units#numbers_lengths_and_percentages) is one of: `Q`, `ch`, `cm`, `em`, `dvh`, `dvw`, `ex`, `in`, `lh`,
89
+ [`unit`](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units#numbers_lengths_and_percentages)
90
+ is one of: `Q`, `ch`, `cm`, `em`, `dvh`, `dvw`, `ex`, `in`, `lh`,
90
91
  `lvh`, `lvw`, `mm`, `pc`, `px`, `pt`, `rem`, `rlh`, `svh`, `svw`, `vb`,
91
92
  `vh`, `vi`, `vmax`, `vmin`, or `vw`.
92
93
 
93
- CSS classes referenced by the `jekyll_img` plugin are at the bottom of
94
- [`demo/assets/css/style.css`](demo/assets/css/style.css).
94
+ CSS classes referenced by the `jekyll_img` plugin are in
95
+ [`demo/assets/css/jekyll_img.css`](demo/assets/css/jekyll_img.css) and
96
+ [`demo/assets/css/jekyll_plugin_support.css`](demo/assets/css/jekyll_plugin_support.css).
95
97
  CSS marker classes are included, so CSS selectors can be used for additional styling.
96
98
 
97
99
 
98
100
  ## Configuration
99
101
 
100
- By default, any errors cause Jekyll to abort.
101
- You can allow Jekyll to continue by setting the following in `_config.yml`:
102
+ By default, errors cause Jekyll to abort.
103
+ You can allow Jekyll to halt by setting the following in `_config.yml`:
102
104
 
103
105
  ```yaml
104
- img:
105
- continue_on_error: true
106
+ jekyll_img:
107
+ die_on_img_error: true
108
+ pry_on_img_error: true
106
109
  ```
107
110
 
108
111
 
@@ -119,7 +122,8 @@ CSS behavior differs for `<figure />` and `<img />`.
119
122
  For example, centering, floating right and left.
120
123
  That means the CSS and where it would need to be applied are completely different for
121
124
  naked `<img />` and `<figure />` tags.
122
- Handling all possible situations of these two scenarios would significantly raise the complexity of the plugin code. I know, because I went down that rabbit hole.
125
+ Handling all possible situations of these two scenarios would significantly raise the complexity of the plugin code.
126
+ I know, because I went down that rabbit hole.
123
127
 
124
128
 
125
129
  ### Wrapper &lt;div /&gt;
@@ -133,9 +137,12 @@ Within the wrapper `<div />`, the embedded `<img />` is displayed with `width=10
133
137
  If a caption is required, the generated `<figure />` only makes the space taken by the generated HTML longer;
134
138
  the image&rsquo;s width and height are not affected.
135
139
 
136
- The wrapper will not exceed the width of the tag that encloses it if the `size` parameter has values `eighthsize`, `fullsize`, `halfsize`, `initial` or `quartersize`.
140
+ The wrapper will not exceed the width of the tag that encloses it if the `size` parameter has values
141
+ `eighthsize`, `fullsize`, `halfsize`, `initial` or `quartersize`.
137
142
 
138
- The wrapper's width can be defined independently of its enclosing tag by using [CSS units](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units#numbers_lengths_and_percentages) for the `size` parameter:
143
+ The wrapper's width can be defined independently of its enclosing tag by using
144
+ [CSS units](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units#numbers_lengths_and_percentages)
145
+ for the `size` parameter:
139
146
  `Q`, `ch`, `cm`, `em`, `dvh`, `dvw`, `ex`, `in`, `lh`,
140
147
  `lvh`, `lvw`, `mm`, `pc`, `px`, `pt`, `rem`, `rlh`, `svh`, `svw`, `vb`,
141
148
  `vh`, `vi`, `vmax`, `vmin`, or `vw`.
@@ -197,6 +204,17 @@ jekyll_img (0.1.0)
197
204
  Generates Jekyll logger with colored output.
198
205
  ```
199
206
 
207
+
208
+ ### Debugging
209
+
210
+ You can cause `pry` to open when an `ImgError` is raised by setting the following in `_config.yml`:
211
+
212
+ ```yaml
213
+ jekyll_img:
214
+ pry_on_img_error: true
215
+ ```
216
+
217
+
200
218
  ### Testing
201
219
 
202
220
  Examine the output by running:
data/jekyll_img.gemspec CHANGED
@@ -29,5 +29,5 @@ Gem::Specification.new do |spec|
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.7.0'
32
+ spec.add_dependency 'jekyll_plugin_support', '>= 0.8.0'
33
33
  end
data/lib/img_props.rb CHANGED
@@ -1,12 +1,10 @@
1
- class ImgError < StandardError; end
2
-
3
1
  # Properties from user
4
2
  # All methods are idempotent.
5
3
  # attr_ methods can be called after compute_dependant_properties
6
4
  # All methods except compute_dependant_properties can be called in any order
7
5
  class ImgProperties
8
- attr_accessor :align, :alt, :attr_wrapper_align_class, :attribute, :attribution, :caption, :classes, :continue_on_error,
9
- :id, :img_display, :nofollow, :src, :size, :style, :target, :title,
6
+ attr_accessor :align, :alt, :attr_wrapper_align_class, :attribute, :attribution, :caption, :classes, :die_on_img_error,
7
+ :id, :img_display, :local_src, :nofollow, :src, :size, :style, :target, :title,
10
8
  :url, :wrapper_class, :wrapper_style
11
9
 
12
10
  SIZES = %w[eighthsize fullsize halfsize initial quartersize].freeze
@@ -33,7 +31,7 @@ class ImgProperties
33
31
 
34
32
  unless SIZES.include?(@size)
35
33
  msg = "'#{@size}' is not a recognized size; must be one of #{SIZES.join(', ')}, or an explicit unit."
36
- raise ImgError, msg
34
+ raise Jekyll::ImgError, msg
37
35
  end
38
36
  @size
39
37
  end
@@ -69,7 +67,7 @@ class ImgProperties
69
67
  end
70
68
 
71
69
  def src_png
72
- raise ImgError, "The 'src' parameter was not specified" if @src.to_s.empty?
70
+ raise Jekyll::ImgError, "The 'src' parameter was not specified" if @src.to_s.empty?
73
71
 
74
72
  @src.gsub('.webp', '.png')
75
73
  end
@@ -83,12 +81,16 @@ class ImgProperties
83
81
 
84
82
  def setup_src
85
83
  @src = @src.to_s.strip
86
- raise ImgError, "The 'src' parameter was not specified", [] if @src.empty?
84
+ raise Jekyll::ImgError, "The 'src' parameter was not specified" if @src.empty?
87
85
 
88
86
  filetype = File.extname(URI(@src).path)
89
87
  @src += '.webp' if filetype.empty?
90
88
 
91
89
  @src = "/assets/images/#{@src}" unless ImgProperties.local_path?(@src) || url?(@src)
90
+ return unless ImgProperties.local_path?(@src)
91
+
92
+ src = @src.start_with?('/') ? ".#{@src}" : @src
93
+ raise Jekyll::ImgError, "#{@src} does not exist" unless File.exist?(src)
92
94
  end
93
95
 
94
96
  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
@@ -1,3 +1,3 @@
1
1
  module JekyllImgVersion
2
- VERSION = '0.1.6'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/lib/jekyll_img.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'jekyll_plugin_support'
2
2
  require 'jekyll_plugin_helper'
3
+ require 'pry'
3
4
  require_relative 'img_builder'
4
5
  require_relative 'img_props'
5
6
  require_relative 'jekyll_img/version'
@@ -12,15 +13,17 @@ module ImgModule
12
13
  end
13
14
 
14
15
  module Jekyll
16
+ ImgError = JekyllSupport.define_error
17
+
15
18
  # Plugin implementation
16
19
  class Img < JekyllSupport::JekyllTag
17
20
  include JekyllImgVersion
18
21
 
19
- def render_impl # rubocop:disable Metrics/AbcSize
22
+ def render_impl
20
23
  @helper.gem_file __FILE__ # This enables plugin attribution
21
24
 
22
- config = @config['img']
23
- @continue_on_error = config['continue_on_error'] == true if config
25
+ @die_on_img_error = @tag_config['die_on_img_error'] == true if @tag_config
26
+ @pry_on_img_error = @tag_config['pry_on_img_error'] == true if @tag_config
24
27
 
25
28
  props = ImgProperties.new
26
29
  props.attribute = @helper.attribute
@@ -29,7 +32,7 @@ module Jekyll
29
32
  props.alt = @helper.parameter_specified? 'alt'
30
33
  props.caption = @helper.parameter_specified? 'caption'
31
34
  props.classes = @helper.parameter_specified? 'class'
32
- props.continue_on_error = @continue_on_error
35
+ props.die_on_img_error = @die_on_img_error
33
36
  props.id = @helper.parameter_specified? 'id'
34
37
  props.nofollow = @helper.parameter_specified? 'nofollow'
35
38
  props.size = @helper.parameter_specified?('size') || @helper.parameter_specified?('_size')
@@ -43,14 +46,14 @@ module Jekyll
43
46
 
44
47
  @builder = ImgBuilder.new(props)
45
48
  @builder.to_s
46
- rescue ImgError => e
47
- msg = <<~END_ERR
48
- #{e.message} on line #{@line_number} (after front matter) of #{@page['path']}.
49
- The offending argument string was: #{@argument_string}
50
- END_ERR
51
- raise ImgError, msg.red, [] unless @continue_on_error
52
-
53
- @logger.warn msg
49
+ rescue ImgError => e # jekyll_plugin_support handles StandardError
50
+ e.shorten_backtrace
51
+ msg = format_error_message e.message
52
+ @logger.error { "#{e.class} raised #{msg}" }
53
+ binding.pry if @pry_on_img_error # rubocop:disable Lint/Debugger
54
+ raise e if @die_on_img_error
55
+
56
+ "<div class='jekyll_img_error'>#{e.class} raised in #{@tag_name} tag\n#{msg}</div>"
54
57
  end
55
58
 
56
59
  JekyllPluginHelper.register(self, ImgModule::PLUGIN_NAME)
data/spec/spec_helper.rb CHANGED
@@ -2,9 +2,8 @@ require 'jekyll'
2
2
  require_relative '../lib/jekyll_img'
3
3
 
4
4
  RSpec.configure do |config|
5
- config.filter_run :focus
5
+ config.filter_run_when_matching focus: true
6
6
  config.order = 'random'
7
- config.run_all_when_everything_filtered = true
8
7
 
9
8
  # See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
10
9
  config.example_status_persistence_file_path = 'spec/status_persistence.txt'
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.6
4
+ version: 0.2.0
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-08-10 00:00:00.000000000 Z
11
+ date: 2023-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.7.0
33
+ version: 0.8.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.7.0
40
+ version: 0.8.0
41
41
  description:
42
42
  email:
43
43
  - mslinn@mslinn.com
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []
89
- rubygems_version: 3.3.3
89
+ rubygems_version: 3.3.7
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: Provides a Jekyll tag that generates images.