jekyll_plugin_support 0.8.4 → 0.8.6

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: 0d96d3f40ca733d7fa1322a8fbec0a70131029baa063a32c55fdc003efcf0d24
4
- data.tar.gz: 2ebb3e46419147a2f1b60e2024fd7118617be61c6cd8f359e448aad2279bf92f
3
+ metadata.gz: 6bf93dd0ea77ecf7c70380afdddc398824f3e1e27226ed3b8e996e8170a15443
4
+ data.tar.gz: 32e434ab647fcfc81e674a54fb676b1b17450ceef5c38f0f51c1a5f59588f666
5
5
  SHA512:
6
- metadata.gz: f4022b99e9b6b1eef55be72e3cbe6a8d99af12e6ec0004a1e2c610325c726ffdf5cef042ce8687eb9be4e352fc7372e3a51f7053e39303cb06ff2dd5f180d530
7
- data.tar.gz: 6d6b5d1221e8985a02bc8bfe32d6411cb516aa4376a0a3f27d9dc6d7b66bee43ce41c02b026e102f9b5035f0b6b116cf8983e1b8b6cea3847a5c2d70733cff69
6
+ metadata.gz: 2c254100e325c89dfd874e7403d83c5e3b10a808de8d987748fca7ef955d92dba2a90157868d7dd525953661968eb142a208bafc0015dbf99f357b1bf255dcf0
7
+ data.tar.gz: ae9cf29baf54d74c957bea4ff126edfe49ddcebb3ba327b2ae7729ef2e783fbe6f1df73a0a635f865a8f8fcbd00b33ebbc3e94ba949c892480a33543a31d21d4
data/CHANGELOG.md CHANGED
@@ -1,9 +1,20 @@
1
1
  # Change Log
2
2
 
3
3
 
4
+ ## 0.8.6 / 2024-06-11
5
+
6
+ * Fixup version, containing what was supposed to be in v0.8.5
7
+
8
+
9
+ ## 0.8.5 / 2024-03-25
10
+
11
+ * Empty block tags now return a value. See https://talk.jekyllrb.com/t/empty-liquid-block-not-rendering
12
+
13
+
4
14
  ## 0.8.4 / 2024-02-27
5
15
 
6
16
  * Problem in error handler fixed.
17
+ * A warning is logged if an environment variable is undefined and `die_if_undefined` is not set.
7
18
 
8
19
 
9
20
  ## 0.8.3 / 2024-01-05
@@ -1,4 +1,4 @@
1
- require_relative 'jekyll_plugin_error_handling'
1
+ require_relative '../error/jekyll_plugin_error_handling'
2
2
 
3
3
  module JekyllSupport
4
4
  # Base class for Jekyll block tags
@@ -29,6 +29,12 @@ module JekyllSupport
29
29
  Jekyll::CustomError.factory @error_name
30
30
  end
31
31
 
32
+ # Liquid::Block subclasses do not render if there is no content within the tag
33
+ # This override fixes that
34
+ def blank?
35
+ false
36
+ end
37
+
32
38
  # Method prescribed by the Jekyll plugin lifecycle.
33
39
  # Defines @config, @envs, @mode, @page and @site
34
40
  # @return [String]
@@ -50,9 +56,10 @@ module JekyllSupport
50
56
  @paginator = @envs[:paginator]
51
57
  @theme = @envs[:theme]
52
58
 
53
- @mode = @config['env']&.key?('JEKYLL_ENV') ? @config['env']['JEKYLL_ENV'] : 'development'
59
+ env = @config['env']
60
+ @mode = env&.key?('JEKYLL_ENV') ? env['JEKYLL_ENV'] : 'development'
54
61
 
55
- @helper.reinitialize(@markup.strip)
62
+ @helper.reinitialize @markup.strip
56
63
 
57
64
  @attribution = @helper.parameter_specified?('attribution') || false unless @no_arg_parsing
58
65
  @logger.debug { "@keys_values='#{@keys_values}'" }
@@ -60,16 +67,16 @@ module JekyllSupport
60
67
  markup = JekyllSupport.lookup_liquid_variables liquid_context, @argument_string
61
68
  @helper.reinitialize markup
62
69
 
63
- render_impl text
70
+ render_impl(text)
64
71
  rescue StandardError => e
65
72
  e.shorten_backtrace
66
- @logger.error { "#{e.class} on line #{@line_number} of #{e.backtrace[0].split(':').first} by #{tag_name} - #{e.message}" }
73
+ @logger.error { "#{e.class} on line #{@line_number} of #{e.backtrace[0].split(':').first} by #{@tag_name} - #{e.message}" }
67
74
  binding.pry if @pry_on_standard_error # rubocop:disable Lint/Debugger
68
75
  raise e if @die_on_standard_error
69
76
 
70
77
  <<~END_MSG
71
78
  <div class='standard_error'>
72
- #{e.class} on line #{@line_number} of #{e.backtrace[0].split(':').first} by #{tag_name}: #{e.message}
79
+ #{e.class} on line #{@line_number} of #{e.backtrace[0].split(':').first} by #{@tag_name}: #{e.message}
73
80
  </div>
74
81
  END_MSG
75
82
  end
@@ -1,4 +1,4 @@
1
- require_relative 'jekyll_plugin_error_handling'
1
+ require_relative '../error/jekyll_plugin_error_handling'
2
2
 
3
3
  module JekyllSupport
4
4
  class JekyllBlockNoArgParsing < JekyllBlock
@@ -20,6 +20,12 @@ module JekyllSupport
20
20
  JekyllSupport.error_short_trace(@logger, e)
21
21
  end
22
22
 
23
+ # Liquid::Block subclasses do not render if there is no content within the tag
24
+ # This override fixes that
25
+ def blank?
26
+ false
27
+ end
28
+
23
29
  # Jekyll plugins must override this method, not render, so their plugin can be tested more easily
24
30
  # The following variables are predefined:
25
31
  # @argument_string, @config, @envs, @helper, @layout, @logger, @mode, @page, @paginator, @site, @tag_name and @theme
@@ -35,7 +35,6 @@ module JekyllSupportErrorHandling
35
35
  string.gsub(/\e\[([;\d]+)?m/, '')
36
36
  end
37
37
 
38
- # TODO: Delete this
39
38
  def maybe_reraise_error(error, throw_error: true)
40
39
  fmsg = format_error_message "#{error.class}: #{error.message.strip}"
41
40
  @logger.error { fmsg }
@@ -0,0 +1,78 @@
1
+ require 'jekyll'
2
+ require_relative '../error/jekyll_plugin_error_handling'
3
+
4
+ module JekyllSupport
5
+ # Base class for Jekyll generators.
6
+ # PluginMetaLogger.instance.config is populated with the contents of `_config.yml` before Jekyll::Generator instances run.
7
+ class JekyllGenerator < Jekyll::Generator
8
+ attr_reader :helper, :line_number, :logger, :site
9
+
10
+ include JekyllSupportErrorHandling
11
+ extend JekyllSupportErrorHandling
12
+
13
+ # Method prescribed by the Jekyll plugin lifecycle.
14
+ # Defines @config, @envs, @mode and @site
15
+ # @return [void]
16
+ def generate(site)
17
+ @logger ||= PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
18
+
19
+ @error_name = "#{self.class.name}Error"
20
+ # Jekyll::CustomError.factory @error_name
21
+
22
+ @site = site
23
+ @config = @site.config
24
+ @envs = site.config['env']
25
+ @theme = @site.theme
26
+
27
+ @mode = ENV['JEKYLL_ENV'] || 'development'
28
+
29
+ # set_error_context(self.class)
30
+
31
+ generate_impl
32
+ rescue StandardError => e
33
+ e.shorten_backtrace
34
+ @logger.error { "#{e.class} on line #{@line_number} of #{e.backtrace[0].split(':').first} by #{self.class.name} - #{e.message}" }
35
+ binding.pry if @pry_on_standard_error # rubocop:disable Lint/Debugger
36
+ raise e if @die_on_standard_error
37
+
38
+ <<~END_MSG
39
+ <div class='standard_error'>
40
+ #{e.class} on line #{@line_number} of #{e.backtrace[0].split(':').first} by #{self.class.name}: #{e.message}
41
+ </div>
42
+ END_MSG
43
+ end
44
+
45
+ # Jekyll plugins should override this method, not `generate`, so they can be tested more easily.
46
+ # The following variables are predefined:
47
+ # @config, @envs, @helper, @logger, @mode, @paginator, @site and @theme
48
+ # @return [void]
49
+ def generate_impl; end
50
+
51
+ def self.register(klass)
52
+ abort("Error: The #{klass.name} plugin does not define VERSION") \
53
+ unless klass.const_defined?(:VERSION)
54
+
55
+ version = klass.const_get(:VERSION)
56
+ error_name_stub = klass.name.include?('::') ? klass.name.split('::')[1] : klass.name
57
+ error_ruby_class_name = "#{error_name_stub.camelcase(:upper)}Error"
58
+ error_css_class_name = error_ruby_class_name.split('::').last.snakecase
59
+ msg = <<~END_MSG
60
+ Loaded generator plugin #{klass.name} v#{version}. It has:
61
+ Error class: #{@error_name}
62
+ CSS class for error messages: #{error_css_class_name}
63
+ END_MSG
64
+
65
+ PluginMetaLogger.instance.info { msg }
66
+ end
67
+
68
+ def set_error_context(klass)
69
+ return unless Object.const_defined? @error_name
70
+
71
+ error_class = Object.const_get @error_name
72
+ error_class.class_variable_set(:@@argument_string, @argument_string)
73
+ error_class.class_variable_set(:@@line_number, @line_number)
74
+ error_class.class_variable_set(:@@path, @page['path'])
75
+ error_class.class_variable_set(:@@tag_name, klass.name)
76
+ end
77
+ end
78
+ end
@@ -98,7 +98,7 @@ class JekyllPluginHelper
98
98
  .parse(@argv_original)
99
99
  @params_original = @keys_values_original unless respond_to?(:no_arg_parsing) && no_arg_parsing
100
100
 
101
- @argv = Shellwords.split(self.class.expand_env(markup))
101
+ @argv = Shellwords.split(self.class.expand_env(markup, logger))
102
102
  @keys_values = KeyValueParser
103
103
  .new({}, { array_values: false, normalize_keys: false, separator: /=/ })
104
104
  .parse(@argv)
@@ -5,12 +5,19 @@ require 'yaml'
5
5
  # Class methods for JekyllPluginHelper
6
6
  class JekyllPluginHelper
7
7
  # Expand an environment variable reference
8
- def self.expand_env(str, die_if_undefined: false)
9
- str&.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/) do
8
+ def self.expand_env(str, logger = nil, die_if_undefined: false)
9
+ str&.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}/) do
10
10
  envar = Regexp.last_match(1)
11
- raise JekyllPluginSupportError, "jekyll_plugin_support error: #{envar} is undefined".red, [] \
12
- if !ENV.key?(envar) && die_if_undefined # Suppress stack trace
11
+ unless ENV.key? envar
12
+ msg = "jekyll_plugin_support error: environment variable #{envar} is undefined"
13
+ raise JekyllPluginSupportError, msg.red, [] if die_if_undefined
13
14
 
15
+ if logger
16
+ logger.warn msg
17
+ else
18
+ puts msg.red
19
+ end
20
+ end
14
21
  ENV.fetch(envar, nil)
15
22
  end
16
23
  end
@@ -1,4 +1,4 @@
1
- require_relative 'jekyll_custom_error'
1
+ require_relative '../error/jekyll_custom_error'
2
2
 
3
3
  # Monkey patch StandardError so a new method called shorten_backtrace is added.
4
4
  class StandardError
@@ -1,3 +1,3 @@
1
1
  module JekyllPluginSupportVersion
2
- VERSION = '0.8.4'.freeze
2
+ VERSION = '0.8.6'.freeze
3
3
  end
@@ -1,8 +1,12 @@
1
1
  require 'colorator'
2
2
  require 'jekyll'
3
3
  require 'jekyll_plugin_logger'
4
- require_relative 'jekyll_plugin_helper'
5
- require_relative 'jekyll_plugin_support/version'
4
+
5
+ def require_directory(dir)
6
+ Dir[File.join(dir, '*.rb')].sort.each do |file|
7
+ require file unless file == __FILE__
8
+ end
9
+ end
6
10
 
7
11
  module NoArgParsing
8
12
  attr_accessor :no_arg_parsing
@@ -10,9 +14,10 @@ module NoArgParsing
10
14
  @no_arg_parsing = true
11
15
  end
12
16
 
13
- require_relative 'jekyll_plugin_support_class'
14
- require_relative 'jekyll_plugin_support_block'
15
- require_relative 'jekyll_plugin_support_block_noarg'
16
- require_relative 'jekyll_plugin_support_tag'
17
- require_relative 'jekyll_plugin_support_tag_noarg'
18
- require_relative 'jekyll_custom_error'
17
+ require_directory __dir__
18
+ require_directory "#{__dir__}/block"
19
+ require_directory "#{__dir__}/error"
20
+ require_directory "#{__dir__}/generator"
21
+ require_directory "#{__dir__}/helper"
22
+ require_directory "#{__dir__}/jekyll_plugin_support"
23
+ require_directory "#{__dir__}/tag"
@@ -1,5 +1,5 @@
1
1
  require 'pry'
2
- require_relative 'jekyll_plugin_error_handling'
2
+ require_relative '../error/jekyll_plugin_error_handling'
3
3
 
4
4
  module JekyllSupport
5
5
  # Base class for Jekyll tags
@@ -64,8 +64,9 @@ module JekyllSupport
64
64
  rescue StandardError => e
65
65
  e.shorten_backtrace
66
66
  file_name = e.backtrace[0]&.split(':')&.first
67
- of_file_name = "of #{file_name} " if file_name
68
- @logger.error { "#{e.class} on line #{@line_number} #{of_file_name}while processing #{tag_name} - #{e.message}" }
67
+ in_file_name = "in '#{file_name}' " if file_name
68
+ of_page = "of '#{@page['path']}'" if @page
69
+ @logger.error { "#{e.class} on line #{@line_number} #{of_page}while processing #{tag_name} #{in_file_name}- #{e.message}" }
69
70
  binding.pry if @pry_on_standard_error # rubocop:disable Lint/Debugger
70
71
  raise e if @die_on_standard_error
71
72
 
@@ -1,4 +1,4 @@
1
- require_relative 'jekyll_plugin_error_handling'
1
+ require_relative '../error/jekyll_plugin_error_handling'
2
2
 
3
3
  module JekyllSupport
4
4
  class JekyllTagNoArgParsing < JekyllTag
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_plugin_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-27 00:00:00.000000000 Z
11
+ date: 2024-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: facets
@@ -94,19 +94,20 @@ files:
94
94
  - README.md
95
95
  - Rakefile
96
96
  - jekyll_plugin_support.gemspec
97
- - lib/jekyll_custom_error.rb
98
- - lib/jekyll_plugin_error_handling.rb
99
- - lib/jekyll_plugin_helper.rb
100
- - lib/jekyll_plugin_helper_attribution.rb
101
- - lib/jekyll_plugin_helper_class.rb
97
+ - lib/block/jekyll_plugin_support_block.rb
98
+ - lib/block/jekyll_plugin_support_block_noarg.rb
99
+ - lib/error/jekyll_custom_error.rb
100
+ - lib/error/jekyll_plugin_error_handling.rb
101
+ - lib/generator/jekyll_plugin_support_generator.rb
102
+ - lib/helper/jekyll_plugin_helper.rb
103
+ - lib/helper/jekyll_plugin_helper_attribution.rb
104
+ - lib/helper/jekyll_plugin_helper_class.rb
102
105
  - lib/jekyll_plugin_support.rb
106
+ - lib/jekyll_plugin_support/jekyll_plugin_support_class.rb
107
+ - lib/jekyll_plugin_support/jekyll_plugin_support_spec_support.rb
103
108
  - lib/jekyll_plugin_support/version.rb
104
- - lib/jekyll_plugin_support_block.rb
105
- - lib/jekyll_plugin_support_block_noarg.rb
106
- - lib/jekyll_plugin_support_class.rb
107
- - lib/jekyll_plugin_support_spec_support.rb
108
- - lib/jekyll_plugin_support_tag.rb
109
- - lib/jekyll_plugin_support_tag_noarg.rb
109
+ - lib/tag/jekyll_plugin_support_tag.rb
110
+ - lib/tag/jekyll_plugin_support_tag_noarg.rb
110
111
  - spec/custom_error_spec.rb
111
112
  - spec/jekyll_plugin_helper_options_spec.rb
112
113
  - spec/liquid_variable_parsing_spec.rb
@@ -139,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
140
  - !ruby/object:Gem::Version
140
141
  version: '0'
141
142
  requirements: []
142
- rubygems_version: 3.5.6
143
+ rubygems_version: 3.5.10
143
144
  signing_key:
144
145
  specification_version: 4
145
146
  summary: Provides a framework for writing and testing Jekyll plugins