jekyll_plugin_support 0.5.2 → 0.6.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: 75b8116adff0e7869b3d9d05def0b7cb702b67860e596e3b9901dce1f43182e7
4
- data.tar.gz: 86da2a9936cbeffb9f381d3d2031f58acee7f79d8efd7a37b2f4864c3201b20e
3
+ metadata.gz: 1ce28127788362fc89e19bc132113bbc169c4bfe0501e08821a2c425451d29c6
4
+ data.tar.gz: 2e98d5294e503b7b510463037e8c93f7318df64f2e3a7728ebfd1fe82a397e6b
5
5
  SHA512:
6
- metadata.gz: f944740ed80b93a8d5fa6e0e4d3a4b0fe04761aa546d2dfea10b3929d7650daf87afdcd295b3698d80ded0f50209fe04a9c918914f216cfcabc335314da7454a
7
- data.tar.gz: c5d1f11b7fb11900a94ba1430faca977794d84fd4073e793cc50128e922c401adaee2ea5ecdc2eef16b3ed1450e0ac98e5eeff1b8dc96fcc9fda1610b04dc2f8
6
+ metadata.gz: 916d5b3f843c68faec816a307491038d1eb670015e8c38f536e0b1b9fdba0162d428477a1a592975da56dd8b26f90a9bcb16c66db7cd2cb7cbde2e041c402ff9
7
+ data.tar.gz: 3e7b7670207a9b552e28cb714ce2d3bc46c16b72259a2e58c987db41ab3e47debddcd8be2ef49b84a17c4434638ad67cd4222df18bc1d647b4ea481700aaf23b
data/.rubocop.yml CHANGED
@@ -1,61 +1,67 @@
1
- require:
2
- - rubocop-rspec
3
- - rubocop-rake
4
- # - rubocop-jekyll
1
+ require:
2
+ - rubocop-md
3
+ - rubocop-performance
4
+ - rubocop-rake
5
+ - rubocop-rspec
6
+ # - rubocop-jekyll
5
7
 
6
- AllCops:
7
- Exclude:
8
- - demo/_site/**/*
9
- - exe/**/*
10
- - vendor/**/*
11
- - Gemfile*
12
- NewCops: enable
13
- TargetRubyVersion: 2.6
8
+ AllCops:
9
+ Exclude:
10
+ - demo/_site/**/*
11
+ - exe/**/*
12
+ - vendor/**/*
13
+ - Gemfile*
14
+ NewCops: enable
15
+ TargetRubyVersion: 2.6
14
16
 
15
- Gemspec/DeprecatedAttributeAssignment:
16
- Enabled: false
17
+ Gemspec/DeprecatedAttributeAssignment:
18
+ Enabled: false
17
19
 
18
- Gemspec/RequireMFA:
19
- Enabled: false
20
+ Gemspec/RequireMFA:
21
+ Enabled: false
20
22
 
21
- Layout/HashAlignment:
22
- EnforcedHashRocketStyle: table
23
+ Layout/HashAlignment:
24
+ EnforcedColonStyle: table
25
+ EnforcedHashRocketStyle: table
23
26
 
24
- Layout/LineLength:
25
- Max: 150
27
+ Layout/LineLength:
28
+ Max: 150
26
29
 
27
- Layout/CommentIndentation:
28
- Exclude:
29
- - spec/**/*
30
+ Layout/CommentIndentation:
31
+ Exclude:
32
+ - spec/**/*
30
33
 
31
- Layout/MultilineMethodCallIndentation:
32
- Enabled: false
34
+ Layout/MultilineMethodCallIndentation:
35
+ Enabled: false
33
36
 
34
- Lint/RedundantCopDisableDirective:
35
- Exclude:
36
- - jekyll_plugin_support.gemspec
37
+ Lint/RedundantCopDisableDirective:
38
+ Exclude:
39
+ - jekyll_plugin_support.gemspec
37
40
 
38
- Metrics/AbcSize:
39
- Max: 30
41
+ Metrics/AbcSize:
42
+ Max: 30
40
43
 
41
- Metrics/BlockLength:
42
- Exclude:
43
- - jekyll_plugin_support.gemspec
44
+ Metrics/BlockLength:
45
+ Exclude:
46
+ - jekyll_plugin_support.gemspec
44
47
 
45
- Metrics/MethodLength:
46
- Max: 25
48
+ Metrics/CyclomaticComplexity:
49
+ Max: 20
47
50
 
48
- RSpec/ExampleLength:
49
- Max: 20
51
+ Metrics/MethodLength:
52
+ Max: 40
50
53
 
51
- RSpec/MultipleExpectations:
52
- Max: 15
54
+ RSpec/ExampleLength:
55
+ Max: 20
53
56
 
54
- Style/Documentation:
55
- Enabled: false
57
+ RSpec/MultipleExpectations:
58
+ Max: 15
56
59
 
57
- Style/FrozenStringLiteralComment:
58
- Enabled: false
60
+ Style/Documentation:
61
+ Enabled: false
59
62
 
60
- Style/TrailingCommaInHashLiteral:
61
- EnforcedStyleForMultiline: comma
63
+ Style/FrozenStringLiteralComment:
64
+ Enabled: false
65
+
66
+ Style/TrailingCommaInHashLiteral:
67
+ EnforcedStyleForMultiline: comma
@@ -0,0 +1,4 @@
1
+ # Notes on Attribution
2
+
3
+ The following additional public methods could be supported for the attribution string:
4
+ `full_name`, `conflicts`, `dependencies`, `platform`, `specification_version`, `summary`, `cert_chain`, `description`, `email`, `extensions`, `licenses`, `metadata`, `post_install_message`, `rg_full_gem_path`, `location`, `git_version`, `rg_extension_dir`, `nondevelopment_dependencies`, `default_executable`, `original_platform`, `gems_dir`, `groups`, `requirements`, `bin_file`, `executables`, `bindir`, `loaded_from`, `hash`, `files`, `spec_file`, `abbreviate`, `bin_dir`, `default_value`, `doc_dir`, `mark_version`, `executable`, `file_name`, `rubygems_version`, `lib_files`, `license`, `name_tuple`, `original_name`, `require_path`, `ri_dir`, `spec_dir`, `spec_name`, `source`, `validate_permissions`, `extension_dir`, `full_gem_path`, `remote`, `base_dir`, `gem_dir`, `normalize`, `match_platform`, `plugins`, `source_paths`, `datadir`, `require_paths`, and `this`.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 0.6.0 / 2023-04-05
2
+ * Added attribution support
3
+ * Renamed `jekyll_plugin_support_helper.rb` to `jekyll_plugin_helper.rb`.
4
+ * Now returns `undefined` instead of `false'` when `@keys_values.empty?`
5
+ and parameter is not specified.
6
+
7
+ ## 0.5.3 / 2023-03-19
8
+ * Added properties `argv_original`, `keys_values_original`, `remaining_markup_original`,
9
+ and `params_original`, which are the original values of `argv`, `keys_values`,
10
+ `remaining_markup`, and `params`, before environment variable expansion.
11
+
1
12
  ## 0.5.2 / 2023-03-17
2
13
  * Added `@helper.remaining_markup` public method, which returns remaining markup passed to your tag, after keyword and name/value parsing is complete.
3
14
  * Finally wrote proper `rspec` tests.
data/README.md CHANGED
@@ -5,8 +5,11 @@
5
5
  `Jekyll_plugin_support` is a Ruby gem that facilitates writing and testing Jekyll plugins.
6
6
  At present, only Jekyll tags and blocks are supported.
7
7
 
8
+
8
9
  ## Installation
10
+ `Jekyll_plugin_support` can be used to create simple Jekyll plugins in the `_plugins/` directory, or gem-based Jekyll plugins.
9
11
 
12
+ ### Simple `_plugins`
10
13
  Add this line to your Jekyll plugin's Gemfile:
11
14
 
12
15
  ```ruby
@@ -19,6 +22,19 @@ And then execute:
19
22
 
20
23
  $ bundle install
21
24
 
25
+
26
+ ### Gem-Based Plugins
27
+ Add this line to your Jekyll plugin's `.gemspec`:
28
+
29
+ ```ruby
30
+ spec.add_dependency 'jekyll_plugin_support'
31
+ ```
32
+
33
+ And then execute:
34
+
35
+ $ bundle install
36
+
37
+
22
38
  ## General Usage
23
39
  `JekyllSupport::JekyllBlock` and `JekyllSupport::JekyllTag`
24
40
  provide support for Jekyll tag blocks and Jekyll tags, respectively.
@@ -56,7 +72,10 @@ module Jekyll
56
72
  VERSION = '0.1.0'.freeze
57
73
 
58
74
  def render_impl
59
- # Your code here
75
+ my_output = "<p>blah blah</p>"
76
+ <<~END_OUTPUT
77
+ #{my_output}
78
+ END_OUTPUT
60
79
  end
61
80
 
62
81
  JekyllPluginHelper.register(self, 'demo_tag')
@@ -72,8 +91,13 @@ module Jekyll
72
91
  class MyBlock < JekyllSupport::JekyllBlock
73
92
  VERSION = '0.1.0'.freeze
74
93
 
75
- def render_impl(text)
76
- # Your code here
94
+ def render_impl(content)
95
+ @helper.gem_file __FILE__ # Enables attribution
96
+ my_output = "<p>blah blah</p>"
97
+ <<~END_OUTPUT
98
+ #{my_output}
99
+ #{@helper.attribute if @helper.attribution}
100
+ END_OUTPUT
77
101
  end
78
102
 
79
103
  JekyllPluginHelper.register(self, 'demo_block')
@@ -101,7 +125,12 @@ module Jekyll
101
125
  include MyPluginVersion
102
126
 
103
127
  def render_impl(text)
104
- # Your code here
128
+ @helper.gem_file __FILE__ # Enables attribution
129
+ my_output = "<p>blah blah</p>"
130
+ <<~END_OUTPUT
131
+ #{my_output}
132
+ #{@helper.attribute if @helper.attribution}
133
+ END_OUTPUT
105
134
  end
106
135
 
107
136
  JekyllPluginHelper.register(self, 'demo_tag')
@@ -168,9 +197,56 @@ without tokenization, and you expect that the plugin might be invoked with large
168
197
  derive your plugin from `JekyllBlockNoArgParsing` or `JekyllTagNoArgParsing`.
169
198
 
170
199
 
200
+ ## Subclass Attribution
201
+ `JekyllTag` and `JekyllBlock` subclasses of `jekyll_plugin_support` can utilize the `attribution` option IFF they are published as a gem.
202
+ `JekyllTagNoArgParsing` and `JekyllBlockNoArgParsing` subclasses cannot.
203
+
204
+ - When used as a keyword option, a default value is used for the attribution string.
205
+ - When used as a name/value option, the attribution string can be specified.
206
+
207
+ Using the `attribution` option cause subclasses to replace their usual output with HTML that looks like:
208
+
209
+ ```html
210
+ <div id="jps_attribute_12345" class="jps_attribute">
211
+ <a href="https://github.com/mslinn/jekyll_outline">
212
+ <b>Generated by <code>jekyll_outline</code>.
213
+ </a>
214
+ </div>
215
+ ```
216
+
217
+ The `id` attribute is in the sample HTML above is randomized so more than one attribution can appear on a page.
218
+
219
+
220
+ ### Usage
221
+ Typical usage for the `attribution` tag is:
222
+
223
+ ```
224
+ {% my_tag attribution %}
225
+ ```
226
+
227
+ Normal processing of `my_tag` is augmented by interpolating the attribution format string,
228
+ which is a Ruby-compatible interpolated string.
229
+
230
+ The default attribution format string is:
231
+
232
+ ```ruby
233
+ "Generated by the #{name} #{version} Jekyll plugin, written by #{author} #{date}."
234
+ ```
235
+
236
+ Because `jekyll_plugin_suppprt` subclasses are `gem`s, their `gemfile`s define values for
237
+ `name`, `version`, `homepage`, and `authors`, as well as many other properties.
238
+ The `date` property is obtained from the plugin/gem publishing date.
239
+
240
+ An alternative attribution string can be specified properties can be output using any of the above properties:
241
+
242
+ ```
243
+ {% my_tag attribution="Generated by the #{name} #{version} Jekyll plugin, written by #{author} #{date}" %}
244
+ ```
245
+
246
+
171
247
  ## Additional Information
172
248
  More information is available on
173
- [Mike Slinn&rsquo;s website](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html).
249
+ [Mike Slinn&rsquo;s website](https://www.mslinn.com/jekyll/10200-jekyll-plugin-support.html).
174
250
 
175
251
 
176
252
  ## Development
@@ -204,16 +280,28 @@ jekyll_plugin_support (0.1.0)
204
280
  ```
205
281
 
206
282
 
207
- ## Test
208
- A test website is provided in the `demo` directory.
209
- 1. Set breakpoints.
283
+ ## Demo
284
+ A demo / test website is provided in the `demo` directory.
285
+ It can be used to debug the plugin or to run freely.
286
+
287
+ ### Run Freely
288
+ 1. Run from the command line:
289
+ ```shell
290
+ $ demo/_bin/debug -r
291
+ ```
292
+
293
+ 2. View the generated website at [`http://localhost:4444`](http://localhost:4444)
294
+
295
+ ### Plugin Debugging
296
+ 1. Set breakpoints in Visual Studio Code.
210
297
 
211
298
  2. Initiate a debug session from the command line:
212
299
  ```shell
213
- $ bin/attach demo
300
+ $ demo/_bin/debug
214
301
  ```
215
302
 
216
- 3. Once the `Fast Debugger` signon appears, launch the Visual Studio Code launch configuration called `Attach rdebug-ide`.
303
+ 3. Once the `Fast Debugger` signon appears, launch the Visual Studio Code launch
304
+ configuration called `Attach rdebug-ide`.
217
305
 
218
306
  4. View the generated website at [`http://localhost:4444`](http://localhost:4444)
219
307
 
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
7
7
  spec.authors = ['Mike Slinn']
8
8
  spec.email = ['mslinn@mslinn.com']
9
9
  spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
10
- spec.homepage = 'https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#quote'
10
+ spec.homepage = 'https://www.mslinn.com/jekyll/10200-jekyll-plugin-support.html'
11
11
  spec.license = 'MIT'
12
12
  spec.metadata = {
13
13
  'allowed_push_host' => 'https://rubygems.org',
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
28
28
  spec.test_files = spec.files.grep %r{^(test|spec|features)/}
29
29
  spec.version = JekyllPluginSupportVersion::VERSION
30
30
 
31
+ spec.add_dependency 'facets'
31
32
  spec.add_dependency 'jekyll', '>= 3.5.0'
32
33
  spec.add_dependency 'jekyll_plugin_logger'
33
34
  spec.add_dependency 'key-value-parser'
data/lib/call_chain.rb ADDED
@@ -0,0 +1,42 @@
1
+ # TODO: File not used, delete
2
+
3
+ # See https://stackoverflow.com/a/23363883/553865
4
+ module CallChain
5
+ ACaller = Struct.new(:filepath, :line, :method_name)
6
+
7
+ def self.caller_method(depth = 1)
8
+ parse_caller(caller(depth + 1).first).method_name
9
+ end
10
+
11
+ def self.parse_caller(at)
12
+ return unless /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
13
+
14
+ last_match = Regexp.last_match.to_a
15
+ ACaller.new(
16
+ last_match[1],
17
+ last_match[2].to_i,
18
+ last_match[3]
19
+ )
20
+ end
21
+
22
+ # Return ACaller prior to jekyll_plugin_support
23
+ def self.jpsh_subclass_caller
24
+ state = :nothing_found
25
+ call_sequence = caller
26
+ call_sequence.each do |caller_|
27
+ parsed_caller = parse_caller caller_
28
+ filepath = parsed_caller.filepath
29
+ dirname = File.dirname filepath
30
+ jpsh = dirname.match? %r{jekyll_plugin_support[.0-9-]*/lib\z}
31
+ liquid = dirname.match? %r{liquid[.0-9-]*/lib/\z}
32
+ case state
33
+ when :nothing_found
34
+ state = :jpsh_found if jpsh
35
+ when :jpsh_found
36
+ # puts "Called from #{parsed_caller.filepath}, on line #{parsed_caller.line}, by method '#{parsed_caller.method_name}'" unless jpsh
37
+ return parsed_caller unless jpsh || liquid
38
+ end
39
+ end
40
+ nil
41
+ end
42
+ end
@@ -0,0 +1,18 @@
1
+ # See https://stackoverflow.com/a/75890279/553865
2
+ module GemSupport
3
+ # @param file must be a fully qualified file name that points to a file within a gem.
4
+ # @return Gem::Specification of gem that file points into, or nil if not called from a gem
5
+ def self.current_spec(file)
6
+ searcher = if Gem::Specification.respond_to?(:find)
7
+ Gem::Specification
8
+ elsif Gem.respond_to?(:searcher)
9
+ Gem.searcher.init_gemspecs
10
+ end
11
+
12
+ searcher&.find do |spec|
13
+ # The File.fnmatch pattern ** means to match directories recursively or files expansively.
14
+ # This makes the method return the proper Gem::Specification when pointed at any file in any directory within a gem.
15
+ File.fnmatch(File.join(spec.full_gem_path, '**'), file)
16
+ end
17
+ end
18
+ end
@@ -1,9 +1,13 @@
1
- require 'shellwords'
1
+ require 'facets/string/interpolate'
2
2
  require 'key_value_parser'
3
+ require 'shellwords'
4
+ require_relative 'gem_support'
3
5
 
4
6
  # Base class for all types of Jekyll plugin helpers
5
- class JekyllPluginHelper
6
- attr_reader :argv, :keys_values, :liquid_context, :logger, :markup, :no_arg_parsing, :params, :tag_name
7
+ class JekyllPluginHelper # rubocop:disable Metrics/ClassLength
8
+ attr_accessor :liquid_context
9
+ attr_reader :argv, :attribution, :keys_values, :logger, :markup, :no_arg_parsing, :params, :tag_name,
10
+ :argv_original, :keys_values_original, :params_original, :jpsh_subclass_caller
7
11
 
8
12
  # Expand an environment variable reference
9
13
  def self.expand_env(str, die_if_undefined: false)
@@ -24,7 +28,7 @@ class JekyllPluginHelper
24
28
 
25
29
  abort("Error: The #{name} plugin is not an instance of JekyllSupport::JekyllBlock or JekyllSupport::JekyllTag") \
26
30
  unless klass.instance_of?(Class) &&
27
- (klass.ancestors.include?(JekyllSupport::JekyllBlock) || \
31
+ (klass.ancestors.include?(JekyllSupport::JekyllBlock) ||
28
32
  klass.ancestors.include?(JekyllSupport::JekyllTag))
29
33
 
30
34
  Liquid::Template.register_tag(name, klass)
@@ -50,15 +54,53 @@ class JekyllPluginHelper
50
54
  @logger = logger
51
55
  @no_arg_parsing = no_arg_parsing
52
56
  reinitialize(markup.strip)
57
+
58
+ @attribution = parameter_specified?('attribution') || false unless no_arg_parsing
53
59
  @logger.debug { "@keys_values='#{@keys_values}'" }
60
+ rescue StandardError => e
61
+ @logger.error { "#{self.class} died with a #{e.full_message}" }
54
62
  end
55
63
 
56
- def warn_fetch(variable)
57
- abort "Error: Argument parsing was suppressed, but an attempt to obtain the value of #{variable} was made"
64
+ def attribute
65
+ return unless @current_gem
66
+
67
+ <<~END_OUTPUT
68
+ <div id="jps_attribute_#{rand(999_999)}" class="jps_attribute">
69
+ <div>
70
+ <a href="#{@homepage}" target="_blank" rel="nofollow">
71
+ #{attribution_string}
72
+ </a>
73
+ </div>
74
+ </div>
75
+ END_OUTPUT
58
76
  end
59
77
 
60
- def warn_parse(meth)
61
- abort "Error: Argument parsing was suppressed, but an attempt to invoke #{meth} was made"
78
+ def default_attribution
79
+ authors = @authors&.join(', ')
80
+ result = "Generated by the \#{@name} v\#{@version} Jekyll plugin"
81
+ result << ", written by #{authors}" if authors
82
+ result << " \#{@published_date}" if @published_date
83
+ result << '.'
84
+ result
85
+ end
86
+
87
+ # Sets @current_gem if file points at a uniquely named file within a gem.
88
+ # @param file must be a fully qualified file name in a gem, for example: __FILE__
89
+ def gem_file(file)
90
+ @current_gem = GemSupport.current_spec file
91
+ @logger.debug "No gem found for '#{file} was found." unless @current_gem
92
+ annotate_globals if @attribution && @current_gem
93
+ end
94
+
95
+ # @return undefined if parameter was specified, removes it from the available tokens and returns value
96
+ def parameter_specified?(name, delete_param: true)
97
+ return if @keys_values.empty?
98
+
99
+ key = name
100
+ key = name.to_sym if @keys_values.first.first.instance_of?(Symbol)
101
+ value = @keys_values[key]
102
+ delete_parameter(name) if delete_param
103
+ value
62
104
  end
63
105
 
64
106
  def reinitialize(markup)
@@ -71,11 +113,7 @@ class JekyllPluginHelper
71
113
  define_singleton_method(:parameter_specified?) { |_name| warn_parse(:parameter_specified?) }
72
114
  define_singleton_method(:delete_parameter) { |_name| warn_parse(:delete_parameter) }
73
115
  else
74
- @argv = Shellwords.split(self.class.expand_env(markup))
75
- @keys_values = KeyValueParser \
76
- .new({}, { array_values: false, normalize_keys: false, separator: /=/ }) \
77
- .parse(@argv)
78
- @params = @keys_values.map { |k, _v| lookup_variable(k) } unless respond_to?(:no_arg_parsing) && no_arg_parsing
116
+ parse markup
79
117
  end
80
118
  end
81
119
 
@@ -84,23 +122,50 @@ class JekyllPluginHelper
84
122
  @argv.join(' ')
85
123
  end
86
124
 
125
+ def remaining_markup_original
126
+ @argv_original.join(' ')
127
+ end
128
+
129
+ def warn_fetch(variable)
130
+ abort "Error: Argument parsing was suppressed, but an attempt to obtain the value of #{variable} was made"
131
+ end
132
+
133
+ def warn_parse(meth)
134
+ abort "Error: Argument parsing was suppressed, but an attempt to invoke #{meth} was made"
135
+ end
136
+
137
+ private
138
+
139
+ def attribution_string
140
+ string = if @attribution == true
141
+ default_attribution
142
+ else
143
+ @attribution
144
+ end
145
+ puts { "Interpolationg #{string}" }
146
+ String.interpolate { string }
147
+ end
148
+
149
+ def annotate_globals
150
+ return unless @current_gem
151
+
152
+ @name = @current_gem.name
153
+ @authors = @current_gem.authors
154
+ @homepage = @current_gem.homepage
155
+ @published_date = @current_gem.date.to_date.to_s
156
+ @version = @current_gem.version
157
+ end
158
+
87
159
  def delete_parameter(key)
88
160
  return if @keys_values.empty? || @params.nil?
89
161
 
90
162
  @params.delete(key)
91
163
  @argv.delete_if { |x| x == key or x.start_with?("#{key}=") }
92
164
  @keys_values.delete(key)
93
- end
94
-
95
- # @return if parameter was specified, removes it from the available tokens and returns value
96
- def parameter_specified?(name)
97
- return false if @keys_values.empty?
98
165
 
99
- key = name
100
- key = name.to_sym if @keys_values.first.first.instance_of?(Symbol)
101
- value = @keys_values[key]
102
- delete_parameter(name)
103
- value
166
+ @params_original.delete(key)
167
+ @argv_original.delete_if { |x| x == key or x.start_with?("#{key}=") }
168
+ @keys_values_original.delete(key)
104
169
  end
105
170
 
106
171
  PREDEFINED_SCOPE_KEYS = %i[include page].freeze
@@ -126,11 +191,6 @@ class JekyllPluginHelper
126
191
  value
127
192
  end
128
193
 
129
- # Sets @params by replacing any Liquid variable names with their values
130
- def liquid_context=(context)
131
- @liquid_context = context
132
- end
133
-
134
194
  def lookup_variable(symbol)
135
195
  string = symbol.to_s
136
196
  return string unless string.start_with?('{{') && string.end_with?('}}')
@@ -141,4 +201,25 @@ class JekyllPluginHelper
141
201
  def page
142
202
  @liquid_context.registers[:page]
143
203
  end
204
+
205
+ # rubocop:disable Style/IfUnlessModifier
206
+ def parse(markup)
207
+ @argv_original = Shellwords.split(markup)
208
+ @keys_values_original = KeyValueParser
209
+ .new({}, { array_values: false, normalize_keys: false, separator: /=/ })
210
+ .parse(@argv_original)
211
+ unless respond_to?(:no_arg_parsing) && no_arg_parsing
212
+ @params_original = @keys_values_original.map { |k, _v| lookup_variable(k) }
213
+ end
214
+
215
+ @argv = Shellwords.split(self.class.expand_env(markup))
216
+ @keys_values = KeyValueParser
217
+ .new({}, { array_values: false, normalize_keys: false, separator: /=/ })
218
+ .parse(@argv)
219
+
220
+ return if respond_to?(:no_arg_parsing) && no_arg_parsing
221
+
222
+ @params = @keys_values.map { |k, _v| lookup_variable(k) }
223
+ end
224
+ # rubocop:enable Style/IfUnlessModifier
144
225
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllPluginSupportVersion
2
- VERSION = '0.5.2'.freeze
2
+ VERSION = '0.6.0'.freeze
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require 'jekyll'
2
2
  require 'jekyll_plugin_logger'
3
- require_relative 'jekyll_plugin_support_helper'
3
+ require_relative 'jekyll_plugin_helper'
4
4
  require_relative 'jekyll_plugin_support/version'
5
5
 
6
6
  # @author Copyright 2022 Michael Slinn
@@ -31,7 +31,7 @@ module JekyllSupport
31
31
  @argument_string = argument_string
32
32
  @logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
33
33
  @logger.debug { "#{self.class}: respond_to?(:no_arg_parsing) #{respond_to?(:no_arg_parsing) ? 'yes' : 'no'}." }
34
- @helper = JekyllPluginHelper.new(tag_name, argument_string, @logger, respond_to?(:no_arg_parsing))
34
+ @helper = JekyllPluginHelper.new tag_name, argument_string, @logger, respond_to?(:no_arg_parsing)
35
35
  end
36
36
 
37
37
  # Method prescribed by the Jekyll plugin lifecycle.
@@ -47,6 +47,11 @@ module JekyllSupport
47
47
  @mode = @config['env']['JEKYLL_ENV'] || 'development'
48
48
 
49
49
  render_impl text
50
+ rescue StandardError => e
51
+ @logger.error { "#{self.class} died with a #{e.full_message}" }
52
+ # raise SystemExit, 3, []
53
+ e.set_backtrace []
54
+ raise e
50
55
  end
51
56
 
52
57
  # Jekyll plugins should override this method, not render, so their plugin can be tested more easily
@@ -65,6 +70,9 @@ module JekyllSupport
65
70
 
66
71
  super
67
72
  @logger.debug { "#{self.class}: respond_to?(:o_arg_parsing) #{respond_to?(:no_arg_parsing) ? 'yes' : 'no'}." }
73
+ rescue StandardError => e
74
+ @logger.error { "#{self.class} died with a #{e.full_message}" }
75
+ exit 2
68
76
  end
69
77
  end
70
78
 
@@ -107,6 +115,9 @@ module JekyllSupport
107
115
  @mode = @config['env']['JEKYLL_ENV'] || 'development'
108
116
 
109
117
  render_impl
118
+ rescue StandardError => e
119
+ @logger.error { "#{self.class} died with a #{e.full_message}" }
120
+ exit 3
110
121
  end
111
122
 
112
123
  # Jekyll plugins must override this method, not render, so their plugin can be tested more easily
@@ -0,0 +1,21 @@
1
+ require 'jekyll_plugin_logger'
2
+ require 'rspec/match_ignoring_whitespace'
3
+ require_relative '../lib/jekyll_plugin_support'
4
+ require_relative '../lib/jekyll_plugin_support_spec_support'
5
+
6
+ class JekyllPluginHelperCallTest
7
+ RSpec.describe JekyllPluginHelper do
8
+ it 'might not return jpsh_subclass_caller value' do
9
+ jpsh_subclass_caller = CallChain.jpsh_subclass_caller
10
+ expect(jpsh_subclass_caller).to be_nil
11
+ end
12
+
13
+ it 'asf' do
14
+ logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
15
+ jph = described_class.new('my_tag', 'attribution', logger, false)
16
+ actual = jph.jpsh_subclass_caller
17
+ expected = [__FILE__, 15, 'new'] # The 2nd element value depends on the line # of two lines up
18
+ expect(actual).to match_array(expected)
19
+ end
20
+ end
21
+ end
@@ -3,7 +3,7 @@ require 'rspec/match_ignoring_whitespace'
3
3
  require_relative '../lib/jekyll_plugin_support'
4
4
  require_relative '../lib/jekyll_plugin_support_spec_support'
5
5
 
6
- class MyTest
6
+ class JekyllPluginHelperOptionsTest
7
7
  RSpec.describe JekyllPluginHelper do
8
8
  logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
9
9
 
@@ -1,6 +1,4 @@
1
- example_id | status | run_time |
2
- ------------------------------------------------------------------------------------------------- | ------ | --------------- |
3
- /mnt/_/work/jekyll/my_plugins/jekyll_plugin_support/spec/jekyll_block_plugin_support_spec.rb[1:1] | passed | 0.00335 seconds |
4
- /mnt/_/work/jekyll/my_plugins/jekyll_plugin_support/spec/jekyll_block_plugin_support_spec.rb[1:2] | passed | 0.00019 seconds |
5
- /mnt/_/work/jekyll/my_plugins/jekyll_plugin_support/spec/jekyll_block_plugin_support_spec.rb[1:3] | passed | 0.00337 seconds |
6
- /mnt/_/work/jekyll/my_plugins/jekyll_plugin_support/spec/jekyll_block_plugin_support_spec.rb[1:4] | passed | 0.00026 seconds |
1
+ example_id | status | run_time |
2
+ ----------------------------------------------------------------------------------------------- | ------ | --------------- |
3
+ /mnt/_/work/jekyll/my_plugins/jekyll_plugin_support/spec/jekyll_plugin_helper_call_spec.rb[1:1] | passed | 0.00436 seconds |
4
+ /mnt/_/work/jekyll/my_plugins/jekyll_plugin_support/spec/jekyll_plugin_helper_call_spec.rb[1:2] | passed | 0.00476 seconds |
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_plugin_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.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-03-17 00:00:00.000000000 Z
11
+ date: 2023-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: facets
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: jekyll
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -60,26 +74,30 @@ extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
62
76
  - ".rubocop.yml"
77
+ - ATTIBUTION_NOTES.md
63
78
  - CHANGELOG.md
64
79
  - LICENSE.txt
65
80
  - README.md
66
81
  - Rakefile
67
82
  - jekyll_plugin_support.gemspec
83
+ - lib/call_chain.rb
84
+ - lib/gem_support.rb
85
+ - lib/jekyll_plugin_helper.rb
68
86
  - lib/jekyll_plugin_support.rb
69
87
  - lib/jekyll_plugin_support/version.rb
70
- - lib/jekyll_plugin_support_helper.rb
71
88
  - lib/jekyll_plugin_support_spec_support.rb
72
- - spec/jekyll_block_plugin_support_spec.rb
89
+ - spec/jekyll_plugin_helper_call_spec.rb
90
+ - spec/jekyll_plugin_helper_options_spec.rb
73
91
  - spec/spec_helper.rb
74
92
  - spec/status_persistence.txt
75
- homepage: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#quote
93
+ homepage: https://www.mslinn.com/jekyll/10200-jekyll-plugin-support.html
76
94
  licenses:
77
95
  - MIT
78
96
  metadata:
79
97
  allowed_push_host: https://rubygems.org
80
98
  bug_tracker_uri: https://github.com/mslinn/jekyll_plugin_support/issues
81
99
  changelog_uri: https://github.com/mslinn/jekyll_plugin_support/CHANGELOG.md
82
- homepage_uri: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#quote
100
+ homepage_uri: https://www.mslinn.com/jekyll/10200-jekyll-plugin-support.html
83
101
  source_code_uri: https://github.com/mslinn/jekyll_plugin_support
84
102
  post_install_message: |2+
85
103
 
@@ -104,7 +122,8 @@ signing_key:
104
122
  specification_version: 4
105
123
  summary: Provides support for writing Jekyll plugins.
106
124
  test_files:
107
- - spec/jekyll_block_plugin_support_spec.rb
125
+ - spec/jekyll_plugin_helper_call_spec.rb
126
+ - spec/jekyll_plugin_helper_options_spec.rb
108
127
  - spec/spec_helper.rb
109
128
  - spec/status_persistence.txt
110
129
  ...