jekyll_plugin_support 0.8.2 → 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +204 -98
- 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 +5 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d96d3f40ca733d7fa1322a8fbec0a70131029baa063a32c55fdc003efcf0d24
|
4
|
+
data.tar.gz: 2ebb3e46419147a2f1b60e2024fd7118617be61c6cd8f359e448aad2279bf92f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4022b99e9b6b1eef55be72e3cbe6a8d99af12e6ec0004a1e2c610325c726ffdf5cef042ce8687eb9be4e352fc7372e3a51f7053e39303cb06ff2dd5f180d530
|
7
|
+
data.tar.gz: 6d6b5d1221e8985a02bc8bfe32d6411cb516aa4376a0a3f27d9dc6d7b66bee43ce41c02b026e102f9b5035f0b6b116cf8983e1b8b6cea3847a5c2d70733cff69
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
3
|
|
4
|
+
## 0.8.4 / 2024-02-27
|
5
|
+
|
6
|
+
* Problem in error handler fixed.
|
7
|
+
|
8
|
+
|
9
|
+
## 0.8.3 / 2024-01-05
|
10
|
+
|
11
|
+
* Variables defined in front matter of layouts and pages are now handled.
|
12
|
+
|
13
|
+
|
4
14
|
## 0.8.2 / 2024-01-03
|
5
15
|
|
6
16
|
* `JekyllSupport::JekyllBlock` and `JekyllSupport::JekyllTag` subclasses now have automatically created error classes,
|
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.
|
@@ -86,20 +107,6 @@ For block tags, a single parameter is required, which contains text passed from
|
|
86
107
|
Your implementation of render_impl can parse parameters passed to the tag / block tag, as described in
|
87
108
|
[Tag Parameter Parsing](http://mslinn.com/jekyll/10100-jekyll-plugin-background.html#params).
|
88
109
|
|
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
110
|
|
104
111
|
## General Usage
|
105
112
|
|
@@ -107,8 +114,9 @@ Please see the [`demo/`](demo/) project for a well-documented set of demonstrati
|
|
107
114
|
Additional information is available [here](https://mslinn.com/jekyll/10200-jekyll-plugin-background.html) and the
|
108
115
|
[`jekyll_plugin_support`](https://www.mslinn.com/jekyll_plugins/jekyll_plugin_support.html) documentation.
|
109
116
|
|
110
|
-
`JekyllSupport::JekyllBlock` and
|
111
|
-
provide
|
117
|
+
[`JekyllSupport::JekyllBlock`](https://github.com/mslinn/jekyll_plugin_support/blob/master/lib/jekyll_plugin_support_block.rb) and
|
118
|
+
[`JekyllSupport::JekyllTag`](https://github.com/mslinn/jekyll_plugin_support/blob/master/lib/jekyll_plugin_support_tag.rb) provide
|
119
|
+
support for Jekyll block tags and Jekyll inline tags, respectively.
|
112
120
|
They are similar in construction and usage.
|
113
121
|
|
114
122
|
Instead of subclassing your Jekyll block tag class from `Liquid::Block`,
|
@@ -152,10 +160,10 @@ For block tags, a single parameter is required, which contains any text enclosed
|
|
152
160
|
|
153
161
|
* [`@layout`](https://jekyllrb.com/docs/variables/#global-variables) Layout information
|
154
162
|
|
155
|
-
*
|
163
|
+
* `@logger` [`jekyll_plugin_logger`](https://github.com/mslinn/jekyll_plugin_logger) instance for your Jekyll plugin.
|
156
164
|
|
157
165
|
* [`@mode`](https://jekyllrb.com/docs/configuration/environments/)
|
158
|
-
Indicates `production` or `development` mode.
|
166
|
+
Indicates `production`, `test` or `development` mode.
|
159
167
|
|
160
168
|
* [`@page`](https://jekyllrb.com/docs/variables/#page-variables) Page variables
|
161
169
|
|
@@ -198,91 +206,94 @@ both [`demo/_plugins/demo_inline_tag.rb`](demo/_plugins/demo_inline_tag.rb) and
|
|
198
206
|
@name2 = @helper.parameter_specified? 'name2'
|
199
207
|
```
|
200
208
|
|
209
|
+
If an argument has a variable reference in it, the value of the variable is substituted for the reference.
|
210
|
+
For example, given:
|
201
211
|
|
202
|
-
|
212
|
+
* `_layouts/default.html` defines a variable called `var_layout` in its front matter.
|
213
|
+
* `index.html` defines a variable called `var_page` in its front matter.
|
214
|
+
* `index.html` assigns a variable called `x` via the liquid `assign` statement.
|
203
215
|
|
204
|
-
|
205
|
-
automatically create error classes, named after the subclass.
|
216
|
+
... then the following references in a page will be substituted for their values in arguments and in block tag bodies:
|
206
217
|
|
207
|
-
|
208
|
-
|
218
|
+
```html
|
219
|
+
{% my_block_tag
|
220
|
+
param1="x={{x}}"
|
221
|
+
param2="var_page={{page.var_page}}"
|
222
|
+
param3="var_layout={{layout.var_layout}}"
|
223
|
+
%}
|
209
224
|
|
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.
|
225
|
+
Assigned variables do not need a namespace: x={{x}}
|
213
226
|
|
214
|
-
|
215
|
-
|
227
|
+
Page variables must be qualified with the 'page' namespace:
|
228
|
+
var_page={{page.var_page}}
|
216
229
|
|
217
|
-
|
218
|
-
|
219
|
-
|
230
|
+
Layout variables must be qualified with the 'layout' namespace:
|
231
|
+
var_layout={{layout.var_layout}}
|
232
|
+
{% endmy_block_tag %}
|
233
|
+
```
|
220
234
|
|
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
|
235
|
+
You can see similar code in [`demo/demo_inline_tag.html`](demo/demo_inline_tag.html).
|
227
236
|
|
228
|
-
|
229
|
-
|
230
|
-
end
|
231
|
-
```
|
237
|
+
The `page['excerpt']` and `page['output']` key/value pairs are removed from processing because of recursion issues.
|
238
|
+
You cannot look up those values from a `jekyll_plugin_support` plugin.
|
232
239
|
|
233
|
-
Error class methods have been provided for standardized and convenient error handling:
|
234
240
|
|
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.
|
241
|
+
### Keyword Options
|
239
242
|
|
243
|
+
For all keyword options, values specified in the document _may_ be provided.
|
244
|
+
If a value is not provided, the value `true` is assumed.
|
245
|
+
Otherwise, if a value is provided, it _must_ be wrapped in single or double quotes.
|
240
246
|
|
241
|
-
### Self-Reporting Upon Registration
|
242
247
|
|
243
|
-
|
248
|
+
### Examples
|
244
249
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
250
|
+
The following examples use the `die_if_error` keyword option for the
|
251
|
+
[`pre`](https://www.mslinn.com/jekyll_plugins/jekyll_pre.html#tag) and
|
252
|
+
[`exec`](https://www.mslinn.com/jekyll_plugins/jekyll_pre.html#tag_exec)
|
253
|
+
tags from the [`jekyll_pre`](https://www.mslinn.com/jekyll_plugins/jekyll_pre.html) plugin %}.
|
249
254
|
|
250
|
-
_config.yml contains the following configuration for this plugin:
|
251
|
-
{"die_on_demo_tag_error"=>false, "die_on_standard_error"=>false}
|
252
255
|
|
256
|
+
#### Specifying Tag Option Values
|
253
257
|
|
254
|
-
|
255
|
-
Error class: DemoTagNoArgsError
|
256
|
-
CSS class for error messages: demo_tag_no_args_error
|
258
|
+
The following sets `die_if_error` `true`:
|
257
259
|
|
258
|
-
|
259
|
-
|
260
|
-
|
260
|
+
```html
|
261
|
+
{% pre die_if_error %} ... {% endpre %}
|
262
|
+
```
|
261
263
|
|
262
|
-
|
263
|
-
|
264
|
+
The above is the same as writing:
|
265
|
+
|
266
|
+
```html
|
267
|
+
{% pre die_if_error='true' %} ... {% endpre %}
|
264
268
|
```
|
265
269
|
|
266
|
-
|
270
|
+
Or writing:
|
267
271
|
|
268
|
-
|
272
|
+
```html
|
273
|
+
{% pre die_if_error="true" %} ... {% endpre %}
|
274
|
+
```
|
275
|
+
|
276
|
+
Neglecting to provide surrounding quotes around the provided value causes the parser to not recognize the option.
|
277
|
+
Instead, what you had intended to be the keyword/value pair will be parsed as part of the command.
|
278
|
+
For the `pre` tag, this means the erroneous string becomes part of the `label` value,
|
279
|
+
unless `label` is explicitly specified.
|
280
|
+
For the `exec` tag, this means the erroneous string becomes part of the command to execute.
|
281
|
+
The following demonstrates the error.
|
269
282
|
|
270
283
|
```html
|
271
|
-
{%
|
284
|
+
{% pre die_if_error=false %} ... {% endpre %}
|
272
285
|
```
|
273
286
|
|
274
|
-
The
|
275
|
-
|
276
|
-
|
287
|
+
The above causes the label to be `die_if_error=false`.
|
288
|
+
|
289
|
+
```html
|
290
|
+
{% exec die_if_error=false ls %} ... {% endpre %}
|
291
|
+
```
|
277
292
|
|
278
|
-
|
279
|
-
that keyword option is removed from the argument string.
|
280
|
-
* Because the `name1` key/value parameter was referenced by `@helper.parameter_specified?` above,
|
281
|
-
that name/value pair is removed from the argument string.
|
282
|
-
* The remainder of the argument string is now `unreferenced_key unreferenced_name="unreferenced_value"`.
|
293
|
+
The above causes the command to be executed to be `die_if_error=false ls` instead of `ls`.
|
283
294
|
|
284
295
|
|
285
|
-
###
|
296
|
+
### Quoting
|
286
297
|
|
287
298
|
Parameter values can be quoted.
|
288
299
|
|
@@ -300,17 +311,21 @@ The following examples both yield the same result:
|
|
300
311
|
* `pay_tuesday="maybe not"`
|
301
312
|
* `pay_tuesday='maybe not'`
|
302
313
|
|
314
|
+
|
303
315
|
### Remaining Markup
|
304
316
|
|
305
317
|
After your plugin has parsed all the keyword options and name/value parameters,
|
306
318
|
call `@helper.remaining_markup` to obtain the remaining markup that was passed to your plugin.
|
307
319
|
|
308
320
|
|
309
|
-
##
|
321
|
+
## Configuration Variables
|
310
322
|
|
311
323
|
`jekyll_plugin_support` provides support for
|
312
324
|
[Liquid variables](https://shopify.github.io/liquid/tags/variable/)
|
313
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
|
+
|
314
329
|
The following `_config.yml` fragment defines 3 variables called `var1`, `var2` and `var3`:
|
315
330
|
|
316
331
|
```yaml
|
@@ -321,20 +336,45 @@ liquid-vars:
|
|
321
336
|
```
|
322
337
|
|
323
338
|
Liquid variables defined in this manner are intended to be embedded in a webpage.
|
324
|
-
They are
|
325
|
-
|
339
|
+
They are can be used like any other Liquid variable.
|
340
|
+
|
341
|
+
|
342
|
+
### Variable Expansion
|
326
343
|
|
327
|
-
|
328
|
-
|
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.
|
348
|
+
|
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`.
|
329
358
|
|
330
359
|
```html
|
331
|
-
This is the value of
|
360
|
+
<p>This is the value of var1: {{var1}}.</p>
|
332
361
|
|
333
362
|
{% my_plugin param1="{{var1}}" param2="{{var2}}" %}
|
334
363
|
```
|
335
364
|
|
336
|
-
`
|
337
|
-
|
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
|
+
|
377
|
+
`Jekyll_plugin_support` expands most of the [plugin variables described above](#predefined-variables),
|
338
378
|
replacing Liquid variable references with their values.
|
339
379
|
The exception is `@argument_string`, which is not expanded.
|
340
380
|
|
@@ -404,6 +444,71 @@ Similarly, the letters `y` and `z` are pronounced {{y}} and {{z}}.
|
|
404
444
|
```
|
405
445
|
|
406
446
|
|
447
|
+
### Automatically Created Error Classes
|
448
|
+
|
449
|
+
`JekyllSupport::JekyllBlock` and `JekyllSupport::JekyllTag` subclasses
|
450
|
+
automatically create error classes, named after the subclass.
|
451
|
+
|
452
|
+
For example, if you create a `JekyllSupport::JekyllBlock` subclass called `DemoBlockTag`,
|
453
|
+
the automatically generated error class will be called `DemoBlockTagError`.
|
454
|
+
|
455
|
+
Although you could use it as you would any other error class, `JekyllPluginSupport` provides some helper methods.
|
456
|
+
These methods fill in the page path and line number that caused the error, shorten the stack trace,
|
457
|
+
log an error message, and can be used to return an HTML-friendly version of the message to the web page.
|
458
|
+
|
459
|
+
The following example is a shortened version of `demo/_plugins/demo_block_tag.rb`.
|
460
|
+
You might want to write similar code in your `rescue` blocks.
|
461
|
+
|
462
|
+
```ruby
|
463
|
+
class DemoBlock < JekyllSupport::JekyllBlock
|
464
|
+
VERSION = '0.1.2'.freeze
|
465
|
+
|
466
|
+
def render_impl(text)
|
467
|
+
raise DemoBlockTagError, 'Fall down, go boom.'
|
468
|
+
rescue DemoBlockTagError => e
|
469
|
+
e.shorten_backtrace
|
470
|
+
@logger.error e.logger_message
|
471
|
+
raise e if @die_on_demo_block_error
|
472
|
+
|
473
|
+
e.html_message
|
474
|
+
end
|
475
|
+
end
|
476
|
+
```
|
477
|
+
|
478
|
+
Error class methods have been provided for standardized and convenient error handling:
|
479
|
+
|
480
|
+
* `shorten_backtrace` - most of the lines that spew from a Jekyll backtrace are uninteresting.
|
481
|
+
* `logger_message` - The message is constructed from the string provided when the error was raised,
|
482
|
+
with the page path and line number added.
|
483
|
+
* `html_message` - The same as `logger_message`, but constructed with HTML.
|
484
|
+
|
485
|
+
|
486
|
+
### Self-Reporting Upon Registration
|
487
|
+
|
488
|
+
When each tag is registered, it self-reports, for example:
|
489
|
+
|
490
|
+
```text
|
491
|
+
INFO PluginMetaLogger: Loaded plugin demo_inline_tag v0.1.2. It has:
|
492
|
+
Error class: DemoTagError
|
493
|
+
CSS class for error messages: demo_tag_error
|
494
|
+
|
495
|
+
_config.yml contains the following configuration for this plugin:
|
496
|
+
{"die_on_demo_tag_error"=>false, "die_on_standard_error"=>false}
|
497
|
+
|
498
|
+
|
499
|
+
INFO PluginMetaLogger: Loaded plugin demo_inline_tag_no_arg v0.1.0. It has:
|
500
|
+
Error class: DemoTagNoArgsError
|
501
|
+
CSS class for error messages: demo_tag_no_args_error
|
502
|
+
|
503
|
+
_config.yml does not contain configuration information for this plugin.
|
504
|
+
You could add a section containing default values by specifying a section for the tag name,
|
505
|
+
and an entry whose name starts with `die_on_`, followed by a snake_case version of the error name.
|
506
|
+
|
507
|
+
demo_inline_tag_no_arg:
|
508
|
+
die_on_demo_tag_no_args_error: false
|
509
|
+
```
|
510
|
+
|
511
|
+
|
407
512
|
## `no_arg_parsing` Optimization
|
408
513
|
|
409
514
|
If your tag or block plugin only needs access to the raw arguments passed from the web page,
|
@@ -434,6 +539,22 @@ Using the `attribution` option cause subclasses to replace their usual output wi
|
|
434
539
|
The `id` attribute is in the sample HTML above is randomized so more than one attribution can appear on a page.
|
435
540
|
|
436
541
|
|
542
|
+
### Attribution Generation
|
543
|
+
|
544
|
+
You can decide where you want the attribution string for your Jekyll tag to appear by invoking `@helper.attribute`.
|
545
|
+
For example, this is how the
|
546
|
+
[`jekyll_outline` tag](https://github.com/mslinn/jekyll_outline/blob/v1.1.1/lib/outline_tag.rb#L32-L46) generates output:
|
547
|
+
|
548
|
+
```html
|
549
|
+
<<~HEREDOC
|
550
|
+
<div class="outer_posts">
|
551
|
+
#{make_entries(collection)&.join("\n")}
|
552
|
+
</div>
|
553
|
+
#{@helper.attribute if @helper.attribution}
|
554
|
+
HEREDOC
|
555
|
+
```
|
556
|
+
|
557
|
+
|
437
558
|
### Usage
|
438
559
|
|
439
560
|
Typical usage for the `attribution` tag is:
|
@@ -444,7 +565,7 @@ Typical usage for the `attribution` tag is:
|
|
444
565
|
{% endmy_block_tag %}
|
445
566
|
```
|
446
567
|
|
447
|
-
|
568
|
+
The normal processing of `my_block_tag` is augmented by interpolating the attribution format string,
|
448
569
|
which is a Ruby-compatible interpolated string.
|
449
570
|
|
450
571
|
The default attribution format string is:
|
@@ -463,21 +584,6 @@ An alternative attribution string can be specified properties can be output usin
|
|
463
584
|
{% my_tag attribution="Generated by the #{name} #{version} Jekyll plugin, written by #{author} #{date}" %}
|
464
585
|
```
|
465
586
|
|
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
587
|
|
482
588
|
## Development
|
483
589
|
|
@@ -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,12 +57,15 @@ 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
|
64
65
|
e.shorten_backtrace
|
65
|
-
|
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}" }
|
66
69
|
binding.pry if @pry_on_standard_error # rubocop:disable Lint/Debugger
|
67
70
|
raise e if @die_on_standard_error
|
68
71
|
|
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.4
|
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-
|
11
|
+
date: 2024-02-27 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.
|
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
|