jekyll_plugin_support 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +23 -4
- data/lib/jekyll_plugin_support/version.rb +1 -1
- data/lib/jekyll_plugin_support.rb +36 -7
- data/lib/jekyll_plugin_support_helper.rb +24 -7
- 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: d0856ddeea29e8a1e24f0a4997aecb7f6b6b22eae587ca8466142686b65557b7
|
4
|
+
data.tar.gz: ac8a8a047666f89b055b6ab90d6535b59e7f34441405852f5905ed6a517cbc27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8122412d70d1c99a6195834a51faa25f0d7beb59a23c18db0beba2883c83f5625920a63495b7ff21abf891faf97ae2ffe085c764c2be9d178bfeb37a7ae4e2f5
|
7
|
+
data.tar.gz: abd34bf8420c7040e7015ce131a8ae3ea01158a552637a4e8d63c51095c138bdf87fd11bff1c3fb3f35fbd3e8b728a09934c4aefe0bbe29817703bdb032a8114
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -19,7 +19,7 @@ And then execute:
|
|
19
19
|
|
20
20
|
$ bundle install
|
21
21
|
|
22
|
-
## Usage
|
22
|
+
## General Usage
|
23
23
|
`JekyllSupport::JekyllBlock` and `JekyllSupport::JekyllTag`
|
24
24
|
provide support for Jekyll tag blocks and Jekyll tags, respectively.
|
25
25
|
They are very similar in construction and usage.
|
@@ -47,8 +47,10 @@ For block tags, a single parameter is required, which contains any text enclosed
|
|
47
47
|
Your implementation of `render_impl` can access `@page` and `@site`,
|
48
48
|
and can parse parameters passed to the tag / block tag, [as described here](https://mslinn.com/jekyll/10100-jekyll-plugin-background.html#params):
|
49
49
|
|
50
|
+
### For a tag:
|
50
51
|
```ruby
|
51
|
-
|
52
|
+
require 'jekyll_plugin_support'
|
53
|
+
|
52
54
|
module Jekyll
|
53
55
|
class MyTag < JekyllSupport::JekyllTag
|
54
56
|
VERSION = '0.1.0'.freeze
|
@@ -56,12 +58,16 @@ module Jekyll
|
|
56
58
|
def render_impl
|
57
59
|
# Your code here
|
58
60
|
end
|
61
|
+
|
62
|
+
JekyllPluginHelper.register(self, 'demo_tag')
|
59
63
|
end
|
60
64
|
end
|
61
65
|
```
|
62
66
|
|
67
|
+
### For a tag block:
|
63
68
|
```ruby
|
64
|
-
|
69
|
+
require 'jekyll_plugin_support'
|
70
|
+
|
65
71
|
module Jekyll
|
66
72
|
class MyBlock < JekyllSupport::JekyllBlock
|
67
73
|
VERSION = '0.1.0'.freeze
|
@@ -69,6 +75,8 @@ module Jekyll
|
|
69
75
|
def render_impl(text)
|
70
76
|
# Your code here
|
71
77
|
end
|
78
|
+
|
79
|
+
JekyllPluginHelper.register(self, 'demo_block')
|
72
80
|
end
|
73
81
|
end
|
74
82
|
```
|
@@ -79,12 +87,15 @@ For example, if `lib/my_plugin/version.rb` looks like this:
|
|
79
87
|
|
80
88
|
```ruby
|
81
89
|
module MyPluginVersion
|
82
|
-
VERSION = '0.5.
|
90
|
+
VERSION = '0.5.1'.freeze
|
83
91
|
end
|
84
92
|
```
|
85
93
|
|
86
94
|
Then your plugin can incorporate the `VERSION` constant into your plugin like this:
|
87
95
|
```ruby
|
96
|
+
require 'jekyll_plugin_support'
|
97
|
+
require_relative 'my_block/version'
|
98
|
+
|
88
99
|
module Jekyll
|
89
100
|
class MyBlock < JekyllSupport::JekyllBlock
|
90
101
|
include MyPluginVersion
|
@@ -92,10 +103,18 @@ module Jekyll
|
|
92
103
|
def render_impl(text)
|
93
104
|
# Your code here
|
94
105
|
end
|
106
|
+
|
107
|
+
JekyllPluginHelper.register(self, 'demo_tag')
|
95
108
|
end
|
96
109
|
end
|
97
110
|
```
|
98
111
|
|
112
|
+
### `no_arg_parsing` Optimization
|
113
|
+
If your tag or block plugin only needs access to the raw arguments passed from the web page,
|
114
|
+
without tokenization, and you expect that the plugin might be invoked with large amounts of text,
|
115
|
+
derive your plugin from `JekyllBlockNoArgParsing` or `JekyllTagNoArgParsing`.
|
116
|
+
|
117
|
+
|
99
118
|
## Additional Information
|
100
119
|
More information is available on
|
101
120
|
[Mike Slinn’s website](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html).
|
@@ -5,6 +5,12 @@ require_relative 'jekyll_plugin_support/version'
|
|
5
5
|
|
6
6
|
# @author Copyright 2022 Michael Slinn
|
7
7
|
# @license SPDX-License-Identifier: Apache-2.0``
|
8
|
+
module NoArgParsing
|
9
|
+
attr_accessor :no_arg_parsing
|
10
|
+
|
11
|
+
@no_arg_parsing = true
|
12
|
+
end
|
13
|
+
|
8
14
|
module JekyllSupport
|
9
15
|
# Base class for Jekyll block tags
|
10
16
|
class JekyllBlock < Liquid::Block
|
@@ -22,9 +28,10 @@ module JekyllSupport
|
|
22
28
|
def initialize(tag_name, argument_string, parse_context)
|
23
29
|
super
|
24
30
|
@tag_name = tag_name
|
25
|
-
@logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
26
|
-
@helper = JekyllPluginHelper.new(tag_name, argument_string, @logger)
|
27
31
|
@argument_string = argument_string
|
32
|
+
@logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
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))
|
28
35
|
end
|
29
36
|
|
30
37
|
# Method prescribed by the Jekyll plugin lifecycle.
|
@@ -33,8 +40,7 @@ module JekyllSupport
|
|
33
40
|
text = super
|
34
41
|
@helper.liquid_context = liquid_context
|
35
42
|
|
36
|
-
|
37
|
-
@page = liquid_context.registers[:page] # Jekyll::Drops::DocumentDrop
|
43
|
+
@page = liquid_context.registers[:page] # Type Jekyll::Drops::DocumentDrop
|
38
44
|
@site = liquid_context.registers[:site]
|
39
45
|
@config = @site.config
|
40
46
|
@envs = liquid_context.environments.first
|
@@ -51,6 +57,17 @@ module JekyllSupport
|
|
51
57
|
end
|
52
58
|
end
|
53
59
|
|
60
|
+
class JekyllBlockNoArgParsing < JekyllBlock
|
61
|
+
def initialize(tag_name, argument_string, parse_context)
|
62
|
+
class << self
|
63
|
+
include NoArgParsing
|
64
|
+
end
|
65
|
+
|
66
|
+
super
|
67
|
+
@logger.debug { "#{self.class}: respond_to?(:o_arg_parsing) #{respond_to?(:no_arg_parsing) ? 'yes' : 'no'}." }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
54
71
|
# Base class for Jekyll tags
|
55
72
|
class JekyllTag < Liquid::Tag
|
56
73
|
attr_reader :argument_string, :helper, :line_number, :logger, :page, :site
|
@@ -67,9 +84,10 @@ module JekyllSupport
|
|
67
84
|
def initialize(tag_name, argument_string, parse_context)
|
68
85
|
super
|
69
86
|
@tag_name = tag_name
|
70
|
-
@logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
71
|
-
@helper = JekyllPluginHelper.new(tag_name, argument_string, @logger)
|
72
87
|
@argument_string = argument_string
|
88
|
+
@logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
89
|
+
@logger.debug { "#{self.class}: respond_to?(:no_arg_parsing) #{respond_to?(:no_arg_parsing) ? 'yes' : 'no'}." }
|
90
|
+
@helper = JekyllPluginHelper.new(tag_name, argument_string, @logger, respond_to?(:no_arg_parsing))
|
73
91
|
end
|
74
92
|
|
75
93
|
# Method prescribed by the Jekyll plugin lifecycle.
|
@@ -94,7 +112,18 @@ module JekyllSupport
|
|
94
112
|
# Jekyll plugins must override this method, not render, so their plugin can be tested more easily
|
95
113
|
# @page and @site are available
|
96
114
|
def render_impl
|
97
|
-
abort "
|
115
|
+
abort "#{self.class}.render_impl for tag #{@tag_name} must be overridden, but it was not."
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
class JekyllTagNoArgParsing < JekyllTag
|
120
|
+
def initialize(tag_name, argument_string, parse_context)
|
121
|
+
class << self
|
122
|
+
include NoArgParsing
|
123
|
+
end
|
124
|
+
|
125
|
+
super
|
126
|
+
@logger.debug { "#{self.class}: respond_to?(:no_arg_parsing) #{respond_to?(:no_arg_parsing) ? 'yes' : 'no'}." }
|
98
127
|
end
|
99
128
|
end
|
100
129
|
end
|
@@ -3,7 +3,7 @@ require 'key_value_parser'
|
|
3
3
|
|
4
4
|
# Base class for all types of Jekyll plugin helpers
|
5
5
|
class JekyllPluginHelper
|
6
|
-
attr_reader :argv, :keys_values, :liquid_context, :logger, :markup, :params, :tag_name
|
6
|
+
attr_reader :argv, :keys_values, :liquid_context, :logger, :markup, :no_arg_parsing, :params, :tag_name
|
7
7
|
|
8
8
|
# Expand an environment variable reference
|
9
9
|
def self.expand_env(str, die_if_undefined: false)
|
@@ -45,20 +45,37 @@ class JekyllPluginHelper
|
|
45
45
|
# This argument is used mostly to display localized error messages on Liquid built-in Tags and Filters.
|
46
46
|
# See https://github.com/Shopify/liquid/wiki/Liquid-for-Programmers#create-your-own-tags
|
47
47
|
# @return [void]
|
48
|
-
def initialize(tag_name, markup, logger)
|
48
|
+
def initialize(tag_name, markup, logger, no_arg_parsing)
|
49
49
|
@tag_name = tag_name
|
50
50
|
@logger = logger
|
51
|
+
@no_arg_parsing = no_arg_parsing
|
51
52
|
reinitialize(markup.strip)
|
52
53
|
@logger.debug { "@keys_values='#{@keys_values}'" }
|
53
54
|
end
|
54
55
|
|
56
|
+
def warn_fetch(variable)
|
57
|
+
abort "Error: Argument parsing was suppressed, but an attempt to obtain the value of #{variable} was made"
|
58
|
+
end
|
59
|
+
|
60
|
+
def warn_parse(meth)
|
61
|
+
abort "Error: Argument parsing was suppressed, but an attempt to invoke #{meth} was made"
|
62
|
+
end
|
63
|
+
|
55
64
|
def reinitialize(markup)
|
56
65
|
# @keys_values was a Hash[Symbol, String|Boolean] but now it is Hash[String, String|Boolean]
|
57
66
|
@markup = markup
|
58
|
-
@
|
59
|
-
|
60
|
-
|
61
|
-
|
67
|
+
if @no_arg_parsing
|
68
|
+
define_singleton_method(:argv) { warn_fetch :argv }
|
69
|
+
define_singleton_method(:keys_values) { warn_fetch :keys_values }
|
70
|
+
define_singleton_method(:params) { warn_fetch :params }
|
71
|
+
define_singleton_method(:parameter_specified?) { |_name| warn_parse(:parameter_specified?) }
|
72
|
+
define_singleton_method(:delete_parameter) { |_name| warn_parse(:delete_parameter) }
|
73
|
+
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
|
+
end
|
62
79
|
end
|
63
80
|
|
64
81
|
def delete_parameter(key)
|
@@ -106,7 +123,7 @@ class JekyllPluginHelper
|
|
106
123
|
# Sets @params by replacing any Liquid variable names with their values
|
107
124
|
def liquid_context=(context)
|
108
125
|
@liquid_context = context
|
109
|
-
@params = @keys_values.map { |k, _v| lookup_variable(k) }
|
126
|
+
@params = @keys_values.map { |k, _v| lookup_variable(k) } unless respond_to?(:no_arg_parsing) && no_arg_parsing
|
110
127
|
end
|
111
128
|
|
112
129
|
def lookup_variable(symbol)
|
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.5.
|
4
|
+
version: 0.5.1
|
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-02-
|
11
|
+
date: 2023-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|