jekyll_plugin_support 0.8.1 → 0.8.2

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: 4efc790e49d3b2d98eb4e96bee8c75a18df25fcf7c08d66a44ef96d7c6db19c6
4
- data.tar.gz: 6629e04d2170911427e4914c0d356e3f9c95149b7a673b2638242ba43cbe11fa
3
+ metadata.gz: cbe2d54d363697f10987c73cdd5e7f1f901f170109747f4319553b37251d14a5
4
+ data.tar.gz: 454e854eec50272cbb21bb107e9095585ea9dc4acaf066ee738cf322bdf6465a
5
5
  SHA512:
6
- metadata.gz: 5afd0123f178c5fe89ddbfbf55e48a63630a3ebdffe07b28b60e6ba5d0df0ee1c7f6c5b4dc25ca0c77c5e0fe4329a46cf9902585cadbcc9ea90fed032dc4b459
7
- data.tar.gz: fd6cb95f84f50655b12e81a069a6cdf85ec265f244159b200909ec9d7c8559871c4a781ddf162b10dd9a53eefb07614ed7cec172877130a52e2859a306df0512
6
+ metadata.gz: 58712d203762e16b5ed848f4bff32cdfb43494871c69482b3a29b5d76180dc3b67406fe42b0662e14ded8174bf4d7a49eab16c1c81c66721402d38be4a24ecd4
7
+ data.tar.gz: 10782bbeb291185bdb17a0d0cd5e37ab999f3c74569b415bc5d3892221bf8e43426cd2244be37b4a5ebc90ae2aa3d9d0327f8f5e3c5b0c7da9d9b06cc1cc3546
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Change Log
2
2
 
3
+
4
+ ## 0.8.2 / 2024-01-03
5
+
6
+ * `JekyllSupport::JekyllBlock` and `JekyllSupport::JekyllTag` subclasses now have automatically created error classes,
7
+ named after the subclass.
8
+ * Error class methods have been provided for standardized and convenient error handling:
9
+ * `shorten_backtrace`
10
+ * `logger_message`
11
+ * `html_message`
12
+ * Tags now self-report when registered.
13
+
14
+
3
15
  ## 0.8.1 / 2023-12-10
4
16
 
5
17
  * Added the `JekyllPluginHelper.remove_html_tags` method.
data/README.md CHANGED
@@ -199,6 +199,70 @@ both [`demo/_plugins/demo_inline_tag.rb`](demo/_plugins/demo_inline_tag.rb) and
199
199
  ```
200
200
 
201
201
 
202
+ ### Automatically Created Error Classes
203
+
204
+ `JekyllSupport::JekyllBlock` and `JekyllSupport::JekyllTag` subclasses
205
+ automatically create error classes, named after the subclass.
206
+
207
+ For example, if you create a `JekyllSupport::JekyllBlock` subclass called `DemoBlockTag`,
208
+ the automatically generated error class will be called `DemoBlockTagError`.
209
+
210
+ Although you could use it as you would any other error class, `JekyllPluginSupport` provides some helper methods.
211
+ These methods fill in the page path and line number that caused the error, shorten the stack trace,
212
+ log an error message, and can be used to return an HTML-friendly version of the message to the web page.
213
+
214
+ The following example is a shortened version of `demo/_plugins/demo_block_tag.rb`.
215
+ You might want to write similar code in your `rescue` blocks.
216
+
217
+ ```ruby
218
+ class DemoBlock < JekyllSupport::JekyllBlock
219
+ VERSION = '0.1.2'.freeze
220
+
221
+ def render_impl(text)
222
+ raise DemoBlockTagError, 'Fall down, go boom.'
223
+ rescue DemoBlockTagError => e
224
+ e.shorten_backtrace
225
+ @logger.error e.logger_message
226
+ raise e if @die_on_demo_block_error
227
+
228
+ e.html_message
229
+ end
230
+ end
231
+ ```
232
+
233
+ Error class methods have been provided for standardized and convenient error handling:
234
+
235
+ * `shorten_backtrace` - most of the lines that spew from a Jekyll backtrace are uninteresting.
236
+ * `logger_message` - The message is constructed from the string provided when the error was raised,
237
+ with the page path and line number added.
238
+ * `html_message` - The same as `logger_message`, but constructed with HTML.
239
+
240
+
241
+ ### Self-Reporting Upon Registration
242
+
243
+ When each tag is registered, it self-reports, for example:
244
+
245
+ ```text
246
+ INFO PluginMetaLogger: Loaded plugin demo_inline_tag v0.1.2. It has:
247
+ Error class: DemoTagError
248
+ CSS class for error messages: demo_tag_error
249
+
250
+ _config.yml contains the following configuration for this plugin:
251
+ {"die_on_demo_tag_error"=>false, "die_on_standard_error"=>false}
252
+
253
+
254
+ INFO PluginMetaLogger: Loaded plugin demo_inline_tag_no_arg v0.1.0. It has:
255
+ Error class: DemoTagNoArgsError
256
+ CSS class for error messages: demo_tag_no_args_error
257
+
258
+ _config.yml does not contain configuration information for this plugin.
259
+ You could add a section containing default values by specifying a section for the tag name,
260
+ and an entry whose name starts with `die_on_`, followed by a snake_case version of the error name.
261
+
262
+ demo_inline_tag_no_arg:
263
+ die_on_demo_tag_no_args_error: false
264
+ ```
265
+
202
266
  ### Example
203
267
 
204
268
  [`demo/index.html`](demo/index.html), contains the following inline tag invocation:
@@ -5,11 +5,10 @@ module Jekyll
5
5
  # Use like this:
6
6
  # CustomError.new(:MyError, 'blah', 'asdf')
7
7
  class CustomError < StandardError
8
- def self.factory(name)
9
- return if Object.const_defined? name
8
+ def self.factory(error_class_name)
9
+ return if Object.const_defined? "::#{error_class_name}"
10
10
 
11
- puts "Defining #{name}".yellow
12
- eval "#{name} = Class.new Jekyll::CustomError" # rubocop:disable Style/EvalWithLocation, Security/Eval
11
+ Object.const_set error_class_name, Class.new(CustomError)
13
12
  end
14
13
 
15
14
  def error_name
@@ -16,23 +16,24 @@ class JekyllPluginHelper
16
16
  end
17
17
 
18
18
  def self.generate_message(klass, tag_name, version)
19
- error_ruby_class_name = "#{klass.name.camelcase(:upper)}Error"
19
+ error_name_stub = klass.name.include?('::') ? klass.name.split('::')[1] : klass.name
20
+ error_ruby_class_name = "#{error_name_stub.camelcase(:upper)}Error"
20
21
  config_die_key = "die_on_#{error_ruby_class_name.snakecase}"
21
22
  error_css_class_name = error_ruby_class_name.split('::').last.snakecase
22
- # config_file_fq = File.realpath 'demo/_config.yml'
23
- config = YAML.load_file('demo/_config.yml')
23
+ config = YAML.load_file('_config.yml')
24
24
  tag_config = config[tag_name]
25
25
  tag_config_msg = if tag_config.nil?
26
26
  <<~END_MSG
27
27
  _config.yml does not contain configuration information for this plugin.
28
- You could add a section containing default values like this:
28
+ You could add a section containing default values by specifying a section for the tag name,
29
+ and an entry whose name starts with `die_on_`, followed by a snake_case version of the error name.
29
30
 
30
- #{tag_name}:
31
- #{config_die_key}: false
31
+ #{tag_name}:
32
+ #{config_die_key}: false
32
33
  END_MSG
33
34
  else
34
35
  <<~END_MSG
35
- _config.yml contains the following configuration for this plugin is:
36
+ _config.yml contains the following configuration for this plugin:
36
37
  #{tag_config}
37
38
  END_MSG
38
39
  end
@@ -59,7 +60,7 @@ class JekyllPluginHelper
59
60
 
60
61
  Liquid::Template.register_tag(tag_name, klass)
61
62
  msg = generate_message(klass, tag_name, version)
62
- PluginMetaLogger.instance.info msg
63
+ PluginMetaLogger.instance.info { msg }
63
64
  end
64
65
 
65
66
  def self.remove_html_tags(string)
@@ -1,3 +1,3 @@
1
1
  module JekyllPluginSupportVersion
2
- VERSION = '0.8.1'.freeze
2
+ VERSION = '0.8.2'.freeze
3
3
  end
@@ -8,14 +8,6 @@ module JekyllSupport
8
8
  include JekyllSupportErrorHandling
9
9
  extend JekyllSupportErrorHandling
10
10
 
11
- def set_error_context
12
- error_class = Object.const_get error_class_name
13
- error_class.class_variable_set(:@@argument_string, @argument_string)
14
- error_class.class_variable_set(:@@line_number, @line_number)
15
- error_class.class_variable_set(:@@path, @page['path'])
16
- error_class.class_variable_set(:@@tag_name, @tag_name)
17
- end
18
-
19
11
  # See https://github.com/Shopify/liquid/wiki/Liquid-for-Programmers#create-your-own-tags
20
12
  # @param tag_name [String] the name of the tag, which we usually know.
21
13
  # @param argument_string [String] the arguments passed to the tag, as a single string.
@@ -52,7 +44,7 @@ module JekyllSupport
52
44
  @config = @site.config
53
45
  @tag_config = @config[@tag_name]
54
46
 
55
- set_error_context @error_name
47
+ set_error_context
56
48
 
57
49
  @layout = @envs[:layout]
58
50
  @paginator = @envs[:paginator]
@@ -90,5 +82,15 @@ module JekyllSupport
90
82
  def render_impl(text)
91
83
  text
92
84
  end
85
+
86
+ def set_error_context
87
+ return unless Object.const_defined? @error_name
88
+
89
+ error_class = Object.const_get @error_name
90
+ error_class.class_variable_set(:@@argument_string, @argument_string)
91
+ error_class.class_variable_set(:@@line_number, @line_number)
92
+ error_class.class_variable_set(:@@path, @page['path'])
93
+ error_class.class_variable_set(:@@tag_name, @tag_name)
94
+ end
93
95
  end
94
96
  end
@@ -32,14 +32,6 @@ module JekyllSupport
32
32
  Jekyll::CustomError.factory @error_name
33
33
  end
34
34
 
35
- def set_error_context
36
- error_class = Object.const_get @error_name
37
- error_class.class_variable_set(:@@argument_string, @argument_string)
38
- error_class.class_variable_set(:@@line_number, @line_number)
39
- error_class.class_variable_set(:@@path, @page['path'])
40
- error_class.class_variable_set(:@@tag_name, @tag_name)
41
- end
42
-
43
35
  # Method prescribed by the Jekyll plugin lifecycle.
44
36
  def render(liquid_context)
45
37
  return if @helper.excerpt_caller
@@ -56,7 +48,7 @@ module JekyllSupport
56
48
  @jps = @config['jekyll_plugin_support']
57
49
  @pry_on_standard_error = @jps['pry_on_standard_error'] || false if @jps
58
50
 
59
- set_error_context @error_name
51
+ set_error_context
60
52
 
61
53
  # @envs.keys are :content, :highlighter_prefix, :highlighter_suffix, :jekyll, :layout, :page, :paginator, :site, :theme
62
54
  @layout = @envs[:layout]
@@ -87,5 +79,15 @@ module JekyllSupport
87
79
  def render_impl
88
80
  abort "#{self.class}.render_impl for tag #{@tag_name} must be overridden, but it was not."
89
81
  end
82
+
83
+ def set_error_context
84
+ return unless Object.const_defined? @error_name
85
+
86
+ error_class = Object.const_get @error_name
87
+ error_class.class_variable_set(:@@argument_string, @argument_string)
88
+ error_class.class_variable_set(:@@line_number, @line_number)
89
+ error_class.class_variable_set(:@@path, @page['path'])
90
+ error_class.class_variable_set(:@@tag_name, @tag_name)
91
+ end
90
92
  end
91
93
  end
@@ -1,6 +1,9 @@
1
1
  example_id | status | run_time |
2
2
  ------------------------------------------------ | ------ | --------------- |
3
- ./spec/jekyll_plugin_helper_options_spec.rb[1:1] | passed | 0.00559 seconds |
4
- ./spec/jekyll_plugin_helper_options_spec.rb[1:2] | passed | 0.00583 seconds |
5
- ./spec/jekyll_plugin_helper_options_spec.rb[1:3] | passed | 0.00543 seconds |
6
- ./spec/jekyll_plugin_helper_options_spec.rb[1:4] | passed | 0.00157 seconds |
3
+ ./spec/custom_error_spec.rb[1:1] | failed | 0.00772 seconds |
4
+ ./spec/custom_error_spec.rb[2:1] | passed | 0.0011 seconds |
5
+ ./spec/jekyll_plugin_helper_options_spec.rb[1:1] | failed | 0.00005 seconds |
6
+ ./spec/jekyll_plugin_helper_options_spec.rb[1:2] | failed | 0.00003 seconds |
7
+ ./spec/jekyll_plugin_helper_options_spec.rb[1:3] | failed | 0.00003 seconds |
8
+ ./spec/jekyll_plugin_helper_options_spec.rb[1:4] | failed | 0.00003 seconds |
9
+ ./spec/liquid_variable_parsing_spec.rb[1:1] | failed | 0.00003 seconds |
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_plugin_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
141
  requirements: []
142
- rubygems_version: 3.4.22
142
+ rubygems_version: 3.3.7
143
143
  signing_key:
144
144
  specification_version: 4
145
145
  summary: Provides a framework for writing and testing Jekyll plugins