jekyll_plugin_support 0.8.2 → 0.8.3
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +149 -93
- data/lib/jekyll_plugin_support/version.rb +1 -1
- data/lib/jekyll_plugin_support_class.rb +42 -4
- data/lib/jekyll_plugin_support_tag.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9953a9a01da37cddcb43f16784ba12afbb90eeea9df7b7346b6593e7d7b483e
|
4
|
+
data.tar.gz: 69d7a9885fc9d3dfaa8308f8a4cfc989a42e3a0b6e5af76ce65a9b0b7dd081b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca1c2618a298fda325a4aa4a4b9d62e1c16d1ead64c1737390aa73fdd4326f7c7d6f3830155a6c6aa7c286fc50ec376c8c4ffcd4ba6698b00f1ce85769217368
|
7
|
+
data.tar.gz: 32702f17fbfb0bcc87df9f6f7033b210adade31c67d29aaa4daa7ebc0d3c4677a885ec088404caa787f00697d4d81f1e017108e4fc6c2a5ec9f5f19a5c16839a
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
3
|
|
4
|
+
## 0.8.3 / 2024-01-05
|
5
|
+
|
6
|
+
* Variables defined in front matter of layouts and pages are now handled.
|
7
|
+
|
8
|
+
|
4
9
|
## 0.8.2 / 2024-01-03
|
5
10
|
|
6
11
|
* `JekyllSupport::JekyllBlock` and `JekyllSupport::JekyllTag` subclasses now have automatically created error classes,
|
data/README.md
CHANGED
@@ -86,20 +86,6 @@ For block tags, a single parameter is required, which contains text passed from
|
|
86
86
|
Your implementation of render_impl can parse parameters passed to the tag / block tag, as described in
|
87
87
|
[Tag Parameter Parsing](http://mslinn.com/jekyll/10100-jekyll-plugin-background.html#params).
|
88
88
|
|
89
|
-
The following variables are predefined within `render`.
|
90
|
-
See the [Jekyll documentation](https://jekyllrb.com/docs/variables/) for more information.
|
91
|
-
|
92
|
-
* `@argument_string` – Original unparsed string from the tag in the web page
|
93
|
-
* `@config` – Jekyll [configuration data](https://jekyllrb.com/docs/configuration/)
|
94
|
-
* `@layout` – Front matter specified in layouts
|
95
|
-
* `@mode` – [possible values](https://jekyllrb.com/docs/configuration/environments/)
|
96
|
-
are `development`, `production`, or `test`
|
97
|
-
* `@page` – Jekyll [page variable](https://jekyllrb.com/docs/variables/#page-variables)
|
98
|
-
* `@paginator` – Only has a value when a paginator is active; they are only available in index files.
|
99
|
-
* `@site` – Jekyll [site variable](https://jekyllrb.com/docs/variables/#site-variables)
|
100
|
-
* `@tag_name` – Name of the inline tag or block plugin
|
101
|
-
* `@theme` – Theme variables (introduced in Jekyll 4.3.0)
|
102
|
-
|
103
89
|
|
104
90
|
## General Usage
|
105
91
|
|
@@ -107,8 +93,9 @@ Please see the [`demo/`](demo/) project for a well-documented set of demonstrati
|
|
107
93
|
Additional information is available [here](https://mslinn.com/jekyll/10200-jekyll-plugin-background.html) and the
|
108
94
|
[`jekyll_plugin_support`](https://www.mslinn.com/jekyll_plugins/jekyll_plugin_support.html) documentation.
|
109
95
|
|
110
|
-
`JekyllSupport::JekyllBlock` and
|
111
|
-
provide
|
96
|
+
[`JekyllSupport::JekyllBlock`](https://github.com/mslinn/jekyll_plugin_support/blob/master/lib/jekyll_plugin_support_block.rb) and
|
97
|
+
[`JekyllSupport::JekyllTag`](https://github.com/mslinn/jekyll_plugin_support/blob/master/lib/jekyll_plugin_support_tag.rb) provide
|
98
|
+
support for Jekyll block tags and Jekyll inline tags, respectively.
|
112
99
|
They are similar in construction and usage.
|
113
100
|
|
114
101
|
Instead of subclassing your Jekyll block tag class from `Liquid::Block`,
|
@@ -152,10 +139,10 @@ For block tags, a single parameter is required, which contains any text enclosed
|
|
152
139
|
|
153
140
|
* [`@layout`](https://jekyllrb.com/docs/variables/#global-variables) Layout information
|
154
141
|
|
155
|
-
*
|
142
|
+
* `@logger` [`jekyll_plugin_logger`](https://github.com/mslinn/jekyll_plugin_logger) instance for your Jekyll plugin.
|
156
143
|
|
157
144
|
* [`@mode`](https://jekyllrb.com/docs/configuration/environments/)
|
158
|
-
Indicates `production` or `development` mode.
|
145
|
+
Indicates `production`, `test` or `development` mode.
|
159
146
|
|
160
147
|
* [`@page`](https://jekyllrb.com/docs/variables/#page-variables) Page variables
|
161
148
|
|
@@ -198,91 +185,94 @@ both [`demo/_plugins/demo_inline_tag.rb`](demo/_plugins/demo_inline_tag.rb) and
|
|
198
185
|
@name2 = @helper.parameter_specified? 'name2'
|
199
186
|
```
|
200
187
|
|
188
|
+
If an argument has a variable reference in it, the value of the variable is substituted for the reference.
|
189
|
+
For example, given:
|
201
190
|
|
202
|
-
|
191
|
+
* `_layouts/default.html` defines a variable called `var_layout` in its front matter.
|
192
|
+
* `index.html` defines a variable called `var_page` in its front matter.
|
193
|
+
* `index.html` assigns a variable called `x` via the liquid `assign` statement.
|
203
194
|
|
204
|
-
|
205
|
-
automatically create error classes, named after the subclass.
|
195
|
+
... then the following references in a page will be substituted for their values in arguments and in block tag bodies:
|
206
196
|
|
207
|
-
|
208
|
-
|
197
|
+
```html
|
198
|
+
{% my_block_tag
|
199
|
+
param1="x={{x}}"
|
200
|
+
param2="var_page={{page.var_page}}"
|
201
|
+
param3="var_layout={{layout.var_layout}}"
|
202
|
+
%}
|
209
203
|
|
210
|
-
|
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.
|
204
|
+
Assigned variables do not need a namespace: x={{x}}
|
213
205
|
|
214
|
-
|
215
|
-
|
206
|
+
Page variables must be qualified with the 'page' namespace:
|
207
|
+
var_page={{page.var_page}}
|
216
208
|
|
217
|
-
|
218
|
-
|
219
|
-
|
209
|
+
Layout variables must be qualified with the 'layout' namespace:
|
210
|
+
var_layout={{layout.var_layout}}
|
211
|
+
{% endmy_block_tag %}
|
212
|
+
```
|
220
213
|
|
221
|
-
|
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
|
214
|
+
You can see similar code in [`demo/demo_inline_tag.html`](demo/demo_inline_tag.html).
|
227
215
|
|
228
|
-
|
229
|
-
|
230
|
-
end
|
231
|
-
```
|
216
|
+
The `page['excerpt']` and `page['output']` key/value pairs are removed from processing because of recursion issues.
|
217
|
+
You cannot look up those values from a `jekyll_plugin_support` plugin.
|
232
218
|
|
233
|
-
Error class methods have been provided for standardized and convenient error handling:
|
234
219
|
|
235
|
-
|
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.
|
220
|
+
### Keyword Options
|
239
221
|
|
222
|
+
For all keyword options, values specified in the document _may_ be provided.
|
223
|
+
If a value is not provided, the value `true` is assumed.
|
224
|
+
Otherwise, if a value is provided, it _must_ be wrapped in single or double quotes.
|
240
225
|
|
241
|
-
### Self-Reporting Upon Registration
|
242
226
|
|
243
|
-
|
227
|
+
### Examples
|
244
228
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
229
|
+
The following examples use the `die_if_error` keyword option for the
|
230
|
+
[`pre`](https://www.mslinn.com/jekyll_plugins/jekyll_pre.html#tag) and
|
231
|
+
[`exec`](https://www.mslinn.com/jekyll_plugins/jekyll_pre.html#tag_exec)
|
232
|
+
tags from the [`jekyll_pre`](https://www.mslinn.com/jekyll_plugins/jekyll_pre.html) plugin %}.
|
249
233
|
|
250
|
-
_config.yml contains the following configuration for this plugin:
|
251
|
-
{"die_on_demo_tag_error"=>false, "die_on_standard_error"=>false}
|
252
234
|
|
235
|
+
#### Specifying Tag Option Values
|
253
236
|
|
254
|
-
|
255
|
-
Error class: DemoTagNoArgsError
|
256
|
-
CSS class for error messages: demo_tag_no_args_error
|
237
|
+
The following sets `die_if_error` `true`:
|
257
238
|
|
258
|
-
|
259
|
-
|
260
|
-
|
239
|
+
```html
|
240
|
+
{% pre die_if_error %} ... {% endpre %}
|
241
|
+
```
|
261
242
|
|
262
|
-
|
263
|
-
|
243
|
+
The above is the same as writing:
|
244
|
+
|
245
|
+
```html
|
246
|
+
{% pre die_if_error='true' %} ... {% endpre %}
|
264
247
|
```
|
265
248
|
|
266
|
-
|
249
|
+
Or writing:
|
250
|
+
|
251
|
+
```html
|
252
|
+
{% pre die_if_error="true" %} ... {% endpre %}
|
253
|
+
```
|
267
254
|
|
268
|
-
|
255
|
+
Neglecting to provide surrounding quotes around the provided value causes the parser to not recognize the option.
|
256
|
+
Instead, what you had intended to be the keyword/value pair will be parsed as part of the command.
|
257
|
+
For the `pre` tag, this means the erroneous string becomes part of the `label` value,
|
258
|
+
unless `label` is explicitly specified.
|
259
|
+
For the `exec` tag, this means the erroneous string becomes part of the command to execute.
|
260
|
+
The following demonstrates the error.
|
269
261
|
|
270
262
|
```html
|
271
|
-
{%
|
263
|
+
{% pre die_if_error=false %} ... {% endpre %}
|
272
264
|
```
|
273
265
|
|
274
|
-
The
|
275
|
-
`jekyll_support_plugin` to parse the string passed to the tag, which is
|
276
|
-
`keyword1 name1='value1' unreferenced_key unreferenced_name="unreferenced_value"`.
|
266
|
+
The above causes the label to be `die_if_error=false`.
|
277
267
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
268
|
+
```html
|
269
|
+
{% exec die_if_error=false ls %} ... {% endpre %}
|
270
|
+
```
|
271
|
+
|
272
|
+
The above causes the command to be executed to be `die_if_error=false ls` instead of `ls`.
|
283
273
|
|
284
274
|
|
285
|
-
###
|
275
|
+
### Quoting
|
286
276
|
|
287
277
|
Parameter values can be quoted.
|
288
278
|
|
@@ -300,6 +290,7 @@ The following examples both yield the same result:
|
|
300
290
|
* `pay_tuesday="maybe not"`
|
301
291
|
* `pay_tuesday='maybe not'`
|
302
292
|
|
293
|
+
|
303
294
|
### Remaining Markup
|
304
295
|
|
305
296
|
After your plugin has parsed all the keyword options and name/value parameters,
|
@@ -328,13 +319,12 @@ In the following example web page, the Liquid variable called `var1` is expanded
|
|
328
319
|
Liquid variables `var1` and `var2` are expanded and passed to the `my_plugin` plugin.
|
329
320
|
|
330
321
|
```html
|
331
|
-
This is the value of
|
322
|
+
This is the value of var1: {{var1}}.
|
332
323
|
|
333
324
|
{% my_plugin param1="{{var1}}" param2="{{var2}}" %}
|
334
325
|
```
|
335
326
|
|
336
|
-
`Jekyll_plugin_support` expands
|
337
|
-
[plugin variables described above](#predefined-variables),
|
327
|
+
`Jekyll_plugin_support` expands most of the [plugin variables described above](#predefined-variables),
|
338
328
|
replacing Liquid variable references with their values.
|
339
329
|
The exception is `@argument_string`, which is not expanded.
|
340
330
|
|
@@ -404,6 +394,71 @@ Similarly, the letters `y` and `z` are pronounced {{y}} and {{z}}.
|
|
404
394
|
```
|
405
395
|
|
406
396
|
|
397
|
+
### Automatically Created Error Classes
|
398
|
+
|
399
|
+
`JekyllSupport::JekyllBlock` and `JekyllSupport::JekyllTag` subclasses
|
400
|
+
automatically create error classes, named after the subclass.
|
401
|
+
|
402
|
+
For example, if you create a `JekyllSupport::JekyllBlock` subclass called `DemoBlockTag`,
|
403
|
+
the automatically generated error class will be called `DemoBlockTagError`.
|
404
|
+
|
405
|
+
Although you could use it as you would any other error class, `JekyllPluginSupport` provides some helper methods.
|
406
|
+
These methods fill in the page path and line number that caused the error, shorten the stack trace,
|
407
|
+
log an error message, and can be used to return an HTML-friendly version of the message to the web page.
|
408
|
+
|
409
|
+
The following example is a shortened version of `demo/_plugins/demo_block_tag.rb`.
|
410
|
+
You might want to write similar code in your `rescue` blocks.
|
411
|
+
|
412
|
+
```ruby
|
413
|
+
class DemoBlock < JekyllSupport::JekyllBlock
|
414
|
+
VERSION = '0.1.2'.freeze
|
415
|
+
|
416
|
+
def render_impl(text)
|
417
|
+
raise DemoBlockTagError, 'Fall down, go boom.'
|
418
|
+
rescue DemoBlockTagError => e
|
419
|
+
e.shorten_backtrace
|
420
|
+
@logger.error e.logger_message
|
421
|
+
raise e if @die_on_demo_block_error
|
422
|
+
|
423
|
+
e.html_message
|
424
|
+
end
|
425
|
+
end
|
426
|
+
```
|
427
|
+
|
428
|
+
Error class methods have been provided for standardized and convenient error handling:
|
429
|
+
|
430
|
+
* `shorten_backtrace` - most of the lines that spew from a Jekyll backtrace are uninteresting.
|
431
|
+
* `logger_message` - The message is constructed from the string provided when the error was raised,
|
432
|
+
with the page path and line number added.
|
433
|
+
* `html_message` - The same as `logger_message`, but constructed with HTML.
|
434
|
+
|
435
|
+
|
436
|
+
### Self-Reporting Upon Registration
|
437
|
+
|
438
|
+
When each tag is registered, it self-reports, for example:
|
439
|
+
|
440
|
+
```text
|
441
|
+
INFO PluginMetaLogger: Loaded plugin demo_inline_tag v0.1.2. It has:
|
442
|
+
Error class: DemoTagError
|
443
|
+
CSS class for error messages: demo_tag_error
|
444
|
+
|
445
|
+
_config.yml contains the following configuration for this plugin:
|
446
|
+
{"die_on_demo_tag_error"=>false, "die_on_standard_error"=>false}
|
447
|
+
|
448
|
+
|
449
|
+
INFO PluginMetaLogger: Loaded plugin demo_inline_tag_no_arg v0.1.0. It has:
|
450
|
+
Error class: DemoTagNoArgsError
|
451
|
+
CSS class for error messages: demo_tag_no_args_error
|
452
|
+
|
453
|
+
_config.yml does not contain configuration information for this plugin.
|
454
|
+
You could add a section containing default values by specifying a section for the tag name,
|
455
|
+
and an entry whose name starts with `die_on_`, followed by a snake_case version of the error name.
|
456
|
+
|
457
|
+
demo_inline_tag_no_arg:
|
458
|
+
die_on_demo_tag_no_args_error: false
|
459
|
+
```
|
460
|
+
|
461
|
+
|
407
462
|
## `no_arg_parsing` Optimization
|
408
463
|
|
409
464
|
If your tag or block plugin only needs access to the raw arguments passed from the web page,
|
@@ -434,6 +489,22 @@ Using the `attribution` option cause subclasses to replace their usual output wi
|
|
434
489
|
The `id` attribute is in the sample HTML above is randomized so more than one attribution can appear on a page.
|
435
490
|
|
436
491
|
|
492
|
+
### Attribution Generation
|
493
|
+
|
494
|
+
You can decide where you want the attribution string for your Jekyll tag to appear by invoking `@helper.attribute`.
|
495
|
+
For example, this is how the
|
496
|
+
[`jekyll_outline` tag](https://github.com/mslinn/jekyll_outline/blob/v1.1.1/lib/outline_tag.rb#L32-L46) generates output:
|
497
|
+
|
498
|
+
```html
|
499
|
+
<<~HEREDOC
|
500
|
+
<div class="outer_posts">
|
501
|
+
#{make_entries(collection)&.join("\n")}
|
502
|
+
</div>
|
503
|
+
#{@helper.attribute if @helper.attribution}
|
504
|
+
HEREDOC
|
505
|
+
```
|
506
|
+
|
507
|
+
|
437
508
|
### Usage
|
438
509
|
|
439
510
|
Typical usage for the `attribution` tag is:
|
@@ -444,7 +515,7 @@ Typical usage for the `attribution` tag is:
|
|
444
515
|
{% endmy_block_tag %}
|
445
516
|
```
|
446
517
|
|
447
|
-
|
518
|
+
The normal processing of `my_block_tag` is augmented by interpolating the attribution format string,
|
448
519
|
which is a Ruby-compatible interpolated string.
|
449
520
|
|
450
521
|
The default attribution format string is:
|
@@ -463,21 +534,6 @@ An alternative attribution string can be specified properties can be output usin
|
|
463
534
|
{% my_tag attribution="Generated by the #{name} #{version} Jekyll plugin, written by #{author} #{date}" %}
|
464
535
|
```
|
465
536
|
|
466
|
-
### Attribution Generation
|
467
|
-
|
468
|
-
You can decide where you want the attribution string for your Jekyll tag to appear by invoking `@helper.attribute`.
|
469
|
-
For example, this is how the
|
470
|
-
[`jekyll_outline` tag](https://github.com/mslinn/jekyll_outline/blob/v1.1.1/lib/outline_tag.rb#L32-L46) generates output:
|
471
|
-
|
472
|
-
```html
|
473
|
-
<<~HEREDOC
|
474
|
-
<div class="outer_posts">
|
475
|
-
#{make_entries(collection)&.join("\n")}
|
476
|
-
</div>
|
477
|
-
#{@helper.attribute if @helper.attribution}
|
478
|
-
HEREDOC
|
479
|
-
```
|
480
|
-
|
481
537
|
|
482
538
|
## Development
|
483
539
|
|
@@ -40,11 +40,13 @@ module JekyllSupport
|
|
40
40
|
end
|
41
41
|
|
42
42
|
# Add variable definitions from _config.yml to liquid_context
|
43
|
-
# Modifies liquid_context in the caller
|
43
|
+
# Modifies liquid_context in the caller
|
44
|
+
# (call by object reference, see https://stackoverflow.com/a/1872159/553865)
|
44
45
|
# @return modified liquid_context
|
45
46
|
# See README.md#configuration-variable-definitions
|
46
47
|
# See demo/variables.html
|
47
48
|
def self.inject_vars(_logger, liquid_context)
|
49
|
+
# TODO: Modify a deep clone? Do I dare?
|
48
50
|
site = liquid_context.registers[:site]
|
49
51
|
|
50
52
|
plugin_variables = site.config['liquid_vars']
|
@@ -68,10 +70,46 @@ module JekyllSupport
|
|
68
70
|
liquid_context
|
69
71
|
end
|
70
72
|
|
71
|
-
def self.
|
73
|
+
def self.dump_stack(stack, cycles, interval)
|
74
|
+
stack_depth = stack.length
|
75
|
+
puts "Stack depth is #{stack_depth}"
|
76
|
+
num_entries = cycles * interval
|
77
|
+
return unless stack_depth > interval * 5
|
78
|
+
|
79
|
+
stack.last(num_entries).each_with_index do |x, i|
|
80
|
+
msg = " #{i}: #{x}"
|
81
|
+
(i % interval).zero? ? puts(msg.yellow) : puts(msg)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Modifies a clone of markup_original so variable references are replaced by their values
|
86
|
+
# @param markup_original to be cloned
|
87
|
+
# @return modified markup_original
|
88
|
+
def self.lookup_liquid_variables(liquid_context, markup_original)
|
89
|
+
markup = markup_original.clone
|
90
|
+
page = liquid_context.registers[:page]
|
91
|
+
envs = liquid_context.environments.first
|
92
|
+
layout = envs[:layout]
|
93
|
+
|
94
|
+
# process layout variables
|
95
|
+
layout&.each do |name, value|
|
96
|
+
markup.gsub!("{{layout.#{name}}}", value.to_s)
|
97
|
+
end
|
98
|
+
|
99
|
+
# process page variables
|
100
|
+
# puts "\nStarting page variable processing of #{page['path']}; stack has #{caller.length} elements".green
|
101
|
+
keys = page.keys
|
102
|
+
%w[excerpt output].each { |key| keys.delete key }
|
103
|
+
# puts " Filtered keys: #{keys.join ' '}"
|
104
|
+
# keys.each { |key| puts " #{key}: #{page[key]}" }
|
105
|
+
keys&.each do |key|
|
106
|
+
markup.gsub!("{{page.#{key}}}", page[key].to_s)
|
107
|
+
end
|
108
|
+
|
109
|
+
# Process assigned, captured and injected variables
|
72
110
|
liquid_context.scopes.each do |scope|
|
73
|
-
scope
|
74
|
-
markup
|
111
|
+
scope&.each do |name, value|
|
112
|
+
markup.gsub!("{{#{name}}}", value.to_s)
|
75
113
|
end
|
76
114
|
end
|
77
115
|
markup
|
@@ -57,7 +57,8 @@ module JekyllSupport
|
|
57
57
|
|
58
58
|
@mode = @config['env']&.key?('JEKYLL_ENV') ? @config['env']['JEKYLL_ENV'] : 'development'
|
59
59
|
|
60
|
-
|
60
|
+
markup = JekyllSupport.lookup_liquid_variables liquid_context, @argument_string
|
61
|
+
@helper.reinitialize markup
|
61
62
|
|
62
63
|
render_impl
|
63
64
|
rescue StandardError => e
|
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
|
+
version: 0.8.3
|
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-
|
11
|
+
date: 2024-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: facets
|