jekyll_plugin_support 0.8.3 → 0.8.5

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: c9953a9a01da37cddcb43f16784ba12afbb90eeea9df7b7346b6593e7d7b483e
4
- data.tar.gz: 69d7a9885fc9d3dfaa8308f8a4cfc989a42e3a0b6e5af76ce65a9b0b7dd081b1
3
+ metadata.gz: 20c575e857da7ffa50f37a587494b25232e1eb1309040946dd13d8f896250f07
4
+ data.tar.gz: 4aa5e163875f4e99adca9a6bc4ca97927c95c4cc4d017f52ca0b108d9ea24670
5
5
  SHA512:
6
- metadata.gz: ca1c2618a298fda325a4aa4a4b9d62e1c16d1ead64c1737390aa73fdd4326f7c7d6f3830155a6c6aa7c286fc50ec376c8c4ffcd4ba6698b00f1ce85769217368
7
- data.tar.gz: 32702f17fbfb0bcc87df9f6f7033b210adade31c67d29aaa4daa7ebc0d3c4677a885ec088404caa787f00697d4d81f1e017108e4fc6c2a5ec9f5f19a5c16839a
6
+ metadata.gz: f2a2123c073c9e344e097e3eecd364606037bdd0213045d7060a09d48acaac1810eb609e201126e3f4fc8e5edc0e4e6e81db43800aa4eea954490d4e21e91cdc
7
+ data.tar.gz: 2d4e8daa6ea71e412065356a7029f3ff0b432fb7a06cdc98f403ba02709106f75c62e8236bae12668e6b181f4c52ccba328811fdb9619cd075597fea622052e7
data/CHANGELOG.md CHANGED
@@ -1,6 +1,17 @@
1
1
  # Change Log
2
2
 
3
3
 
4
+ ## 0.8.5 / 2024-03-25
5
+
6
+ * Empty block tags now return a value. See https://talk.jekyllrb.com/t/empty-liquid-block-not-rendering
7
+
8
+
9
+ ## 0.8.4 / 2024-02-27
10
+
11
+ * Problem in error handler fixed.
12
+ * A warning is logged if an environment variable is undefined and `die_if_undefined` is not set.
13
+
14
+
4
15
  ## 0.8.3 / 2024-01-05
5
16
 
6
17
  * Variables defined in front matter of layouts and pages are now handled.
data/README.md CHANGED
@@ -26,6 +26,27 @@ Plugins that use `jekyll_plugin_support` include:
26
26
  [`jekyll_plugin_support`](https://github.com/mslinn/jekyll_plugin_support/tree/master/demo/_plugins)
27
27
 
28
28
 
29
+ ## Features
30
+
31
+ Jekyll plugin tags created from `jekyll_plugin_support` framework automatically have the following features:
32
+
33
+ 1. Boilerplate is removed, so you can focus on the required logic and output.
34
+ 2. Arguments are parsed for keywords and name/value parameters.
35
+ 3. Single or double quotes can be used for arguments and parameters.
36
+ 4. Important variables are defined.
37
+ 5. Error handling is standardized, and includes an automatically defined error type
38
+ and corresponding CSS tag for each Jekyll tag.
39
+ 6. Liquid variables can be passed as parameters to tags, and used in the body of block tags.
40
+ 7. Registration is automatic, and important configuration details are reported during registration.
41
+ 8. A custom logger is created for each tag, independent of the default Jekyll logger.
42
+ 9. Variables can be defined in `_config.yml`, and optionally have different values for debug mode,
43
+ production mode and test mode.
44
+ 10. An attribution message is available.
45
+ 11. Draft pages are automatically detected.
46
+
47
+ In addition, a demonstration website is provided for easy testing of your plugins.
48
+
49
+
29
50
  ## Installation
30
51
 
31
52
  `Jekyll_plugin_support` is packaged as a Ruby gem.
@@ -297,11 +318,14 @@ After your plugin has parsed all the keyword options and name/value parameters,
297
318
  call `@helper.remaining_markup` to obtain the remaining markup that was passed to your plugin.
298
319
 
299
320
 
300
- ## Liquid Variable Definitions
321
+ ## Configuration Variables
301
322
 
302
323
  `jekyll_plugin_support` provides support for
303
324
  [Liquid variables](https://shopify.github.io/liquid/tags/variable/)
304
325
  to be defined in `_config.yml`, in a section called `liquid-vars`.
326
+ These variables behave exactly like Liquid variables defined by `assign` and `capture` expressions,
327
+ except they are global in scope; these variables are available in every Jekyll web page.
328
+
305
329
  The following `_config.yml` fragment defines 3 variables called `var1`, `var2` and `var3`:
306
330
 
307
331
  ```yaml
@@ -312,18 +336,44 @@ liquid-vars:
312
336
  ```
313
337
 
314
338
  Liquid variables defined in this manner are intended to be embedded in a webpage.
315
- They are expanded transparently, and can be referenced like any other Liquid variable.
316
- These Liquid variables can be passed as parameters to other plugins and includes.
339
+ They are can be used like any other Liquid variable.
340
+
341
+
342
+ ### Variable Expansion
343
+
344
+ Jekyll expands Liquid variable references during the page rendering process.
345
+ Jekyll does not expand Liquid variable references passes as parameters to tag and block plugins, however.
346
+ However, plugins made from `jekyll_plugin_support` automatically
347
+ expand all types of variable references passed as parameters and in block tag bodies.
317
348
 
318
- In the following example web page, the Liquid variable called `var1` is expanded as part of the displayed page.
319
- Liquid variables `var1` and `var2` are expanded and passed to the `my_plugin` plugin.
349
+ `Jekyll_plugin_support` tag and block plugins expand the following types of variables:
350
+
351
+ * Jekyll_plugin_support configuration variables, discussed above.
352
+ * Jekyll [page](https://jekyllrb.com/docs/variables/#page-variables) and
353
+ [layout](https://jekyllrb.com/docs/layouts/#variables) variables.
354
+ * Inline Liquid variables (defined in [assign](https://shopify.dev/docs/api/liquid/tags/assign) and [capture](https://shopify.dev/docs/api/liquid/tags/capture) statements).
355
+
356
+ In the following example web page, Jekyll expands the `var1` reference within the `<p></p>` tag,
357
+ but not the `var1` or `var2` references passed to `my_plugin`.
320
358
 
321
359
  ```html
322
- This is the value of var1: {{var1}}.
360
+ <p>This is the value of var1: {{var1}}.</p>
323
361
 
324
362
  {% my_plugin param1="{{var1}}" param2="{{var2}}" %}
325
363
  ```
326
364
 
365
+ Assuming that `my_plugin` was written as a `jekyll_plugin_support` plugin,
366
+ all variable references in its parameters are expanded.
367
+ Thus, the above is interpreted as follows when `my_plugin` is evaluated during the Jekyll rendering process:
368
+ </p>
369
+
370
+ ```html
371
+ <p>This is the value of var1: value1.</p>
372
+
373
+ {% my_plugin param1="value1" param2="value 2" %}
374
+ ```
375
+
376
+
327
377
  `Jekyll_plugin_support` expands most of the [plugin variables described above](#predefined-variables),
328
378
  replacing Liquid variable references with their values.
329
379
  The exception is `@argument_string`, which is not expanded.
@@ -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 }
@@ -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,3 +1,3 @@
1
1
  module JekyllPluginSupportVersion
2
- VERSION = '0.8.3'.freeze
2
+ VERSION = '0.8.5'.freeze
3
3
  end
@@ -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]
@@ -52,7 +58,7 @@ module JekyllSupport
52
58
 
53
59
  @mode = @config['env']&.key?('JEKYLL_ENV') ? @config['env']['JEKYLL_ENV'] : 'development'
54
60
 
55
- @helper.reinitialize(@markup.strip)
61
+ @helper.reinitialize @markup.strip
56
62
 
57
63
  @attribution = @helper.parameter_specified?('attribution') || false unless @no_arg_parsing
58
64
  @logger.debug { "@keys_values='#{@keys_values}'" }
@@ -60,7 +66,7 @@ module JekyllSupport
60
66
  markup = JekyllSupport.lookup_liquid_variables liquid_context, @argument_string
61
67
  @helper.reinitialize markup
62
68
 
63
- render_impl text
69
+ render_impl(text)
64
70
  rescue StandardError => e
65
71
  e.shorten_backtrace
66
72
  @logger.error { "#{e.class} on line #{@line_number} of #{e.backtrace[0].split(':').first} by #{tag_name} - #{e.message}" }
@@ -63,7 +63,10 @@ module JekyllSupport
63
63
  render_impl
64
64
  rescue StandardError => e
65
65
  e.shorten_backtrace
66
- @logger.error { "#{e.class} on line #{@line_number} of #{e.backtrace[0].split(':').first} while processing #{tag_name} - #{e.message}" }
66
+ file_name = e.backtrace[0]&.split(':')&.first
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}" }
67
70
  binding.pry if @pry_on_standard_error # rubocop:disable Lint/Debugger
68
71
  raise e if @die_on_standard_error
69
72
 
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.3
4
+ version: 0.8.5
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-01-06 00:00:00.000000000 Z
11
+ date: 2024-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: facets
@@ -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.3.7
142
+ rubygems_version: 3.5.6
143
143
  signing_key:
144
144
  specification_version: 4
145
145
  summary: Provides a framework for writing and testing Jekyll plugins