jekyll_plugin_support 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/jekyll_plugin_support/version.rb +1 -1
- data/lib/jekyll_plugin_support_helper.rb +44 -27
- 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: 16fe00b243305d30e8dff85f604336e9c9802afe837a762dd295bd7283d8e1d4
|
4
|
+
data.tar.gz: c4ae30a570d27d77d17d7710be941731aefeaf11e4c2e19ec9f8fb773a9ad01d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0abe907f3c564efdf0192279e1d7b2553f3fe97ecb9cbac989defe6a9051979c295db7b0e5917a9c954bc1faab1b42b3fb88b1ac6ef4d20cf3b49217b859fae
|
7
|
+
data.tar.gz: fe6027eaccdc0e46de5d98bc954e17600d088e988fbe3798cb2ad842cdcf8b5d417cd2fdd6bdb0d27f517831d81dd8956444235c23767db222634c579d2d60e6
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 0.5.3 / 2023-03-19
|
2
|
+
* Added properties `argv_original`, `keys_values_original`, `remaining_markup_original`,
|
3
|
+
and `params_original`, which are the original values of `argv`, `keys_values`,
|
4
|
+
`remaining_markup`, and `params`, before environment variable expansion.
|
5
|
+
|
1
6
|
## 0.5.2 / 2023-03-17
|
2
7
|
* Added `@helper.remaining_markup` public method, which returns remaining markup passed to your tag, after keyword and name/value parsing is complete.
|
3
8
|
* Finally wrote proper `rspec` tests.
|
@@ -2,8 +2,10 @@ require 'shellwords'
|
|
2
2
|
require 'key_value_parser'
|
3
3
|
|
4
4
|
# Base class for all types of Jekyll plugin helpers
|
5
|
-
class JekyllPluginHelper
|
6
|
-
|
5
|
+
class JekyllPluginHelper # rubocop:disable Metrics/ClassLength
|
6
|
+
attr_accessor :liquid_context
|
7
|
+
attr_reader :argv, :keys_values, :logger, :markup, :no_arg_parsing, :params, :tag_name,
|
8
|
+
:argv_original, :keys_values_original, :params_original
|
7
9
|
|
8
10
|
# Expand an environment variable reference
|
9
11
|
def self.expand_env(str, die_if_undefined: false)
|
@@ -53,12 +55,15 @@ class JekyllPluginHelper
|
|
53
55
|
@logger.debug { "@keys_values='#{@keys_values}'" }
|
54
56
|
end
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
-
|
58
|
+
# @return if parameter was specified, removes it from the available tokens and returns value
|
59
|
+
def parameter_specified?(name)
|
60
|
+
return false if @keys_values.empty?
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
+
key = name
|
63
|
+
key = name.to_sym if @keys_values.first.first.instance_of?(Symbol)
|
64
|
+
value = @keys_values[key]
|
65
|
+
delete_parameter(name)
|
66
|
+
value
|
62
67
|
end
|
63
68
|
|
64
69
|
def reinitialize(markup)
|
@@ -71,11 +76,7 @@ class JekyllPluginHelper
|
|
71
76
|
define_singleton_method(:parameter_specified?) { |_name| warn_parse(:parameter_specified?) }
|
72
77
|
define_singleton_method(:delete_parameter) { |_name| warn_parse(:delete_parameter) }
|
73
78
|
else
|
74
|
-
|
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
|
79
|
+
parse markup
|
79
80
|
end
|
80
81
|
end
|
81
82
|
|
@@ -84,23 +85,30 @@ class JekyllPluginHelper
|
|
84
85
|
@argv.join(' ')
|
85
86
|
end
|
86
87
|
|
88
|
+
def remaining_markup_original
|
89
|
+
@argv_original.join(' ')
|
90
|
+
end
|
91
|
+
|
92
|
+
def warn_fetch(variable)
|
93
|
+
abort "Error: Argument parsing was suppressed, but an attempt to obtain the value of #{variable} was made"
|
94
|
+
end
|
95
|
+
|
96
|
+
def warn_parse(meth)
|
97
|
+
abort "Error: Argument parsing was suppressed, but an attempt to invoke #{meth} was made"
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
87
102
|
def delete_parameter(key)
|
88
103
|
return if @keys_values.empty? || @params.nil?
|
89
104
|
|
90
105
|
@params.delete(key)
|
91
106
|
@argv.delete_if { |x| x == key or x.start_with?("#{key}=") }
|
92
107
|
@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
108
|
|
99
|
-
key
|
100
|
-
|
101
|
-
|
102
|
-
delete_parameter(name)
|
103
|
-
value
|
109
|
+
@params_original.delete(key)
|
110
|
+
@argv_original.delete_if { |x| x == key or x.start_with?("#{key}=") }
|
111
|
+
@keys_values_original.delete(key)
|
104
112
|
end
|
105
113
|
|
106
114
|
PREDEFINED_SCOPE_KEYS = %i[include page].freeze
|
@@ -126,11 +134,6 @@ class JekyllPluginHelper
|
|
126
134
|
value
|
127
135
|
end
|
128
136
|
|
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
137
|
def lookup_variable(symbol)
|
135
138
|
string = symbol.to_s
|
136
139
|
return string unless string.start_with?('{{') && string.end_with?('}}')
|
@@ -141,4 +144,18 @@ class JekyllPluginHelper
|
|
141
144
|
def page
|
142
145
|
@liquid_context.registers[:page]
|
143
146
|
end
|
147
|
+
|
148
|
+
def parse(markup)
|
149
|
+
@argv_original = Shellwords.split(markup)
|
150
|
+
@keys_values_original = KeyValueParser \
|
151
|
+
.new({}, { array_values: false, normalize_keys: false, separator: /=/ }) \
|
152
|
+
.parse(@argv_original)
|
153
|
+
@params_original = @keys_values_original.map { |k, _v| lookup_variable(k) } unless respond_to?(:no_arg_parsing) && no_arg_parsing
|
154
|
+
|
155
|
+
@argv = Shellwords.split(self.class.expand_env(markup))
|
156
|
+
@keys_values = KeyValueParser \
|
157
|
+
.new({}, { array_values: false, normalize_keys: false, separator: /=/ }) \
|
158
|
+
.parse(@argv)
|
159
|
+
@params = @keys_values.map { |k, _v| lookup_variable(k) } unless respond_to?(:no_arg_parsing) && no_arg_parsing
|
160
|
+
end
|
144
161
|
end
|
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.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: 2023-03-
|
11
|
+
date: 2023-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|