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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75b8116adff0e7869b3d9d05def0b7cb702b67860e596e3b9901dce1f43182e7
4
- data.tar.gz: 86da2a9936cbeffb9f381d3d2031f58acee7f79d8efd7a37b2f4864c3201b20e
3
+ metadata.gz: 16fe00b243305d30e8dff85f604336e9c9802afe837a762dd295bd7283d8e1d4
4
+ data.tar.gz: c4ae30a570d27d77d17d7710be941731aefeaf11e4c2e19ec9f8fb773a9ad01d
5
5
  SHA512:
6
- metadata.gz: f944740ed80b93a8d5fa6e0e4d3a4b0fe04761aa546d2dfea10b3929d7650daf87afdcd295b3698d80ded0f50209fe04a9c918914f216cfcabc335314da7454a
7
- data.tar.gz: c5d1f11b7fb11900a94ba1430faca977794d84fd4073e793cc50128e922c401adaee2ea5ecdc2eef16b3ed1450e0ac98e5eeff1b8dc96fcc9fda1610b04dc2f8
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.
@@ -1,3 +1,3 @@
1
1
  module JekyllPluginSupportVersion
2
- VERSION = '0.5.2'.freeze
2
+ VERSION = '0.5.3'.freeze
3
3
  end
@@ -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
- attr_reader :argv, :keys_values, :liquid_context, :logger, :markup, :no_arg_parsing, :params, :tag_name
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
- def warn_fetch(variable)
57
- abort "Error: Argument parsing was suppressed, but an attempt to obtain the value of #{variable} was made"
58
- end
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
- def warn_parse(meth)
61
- abort "Error: Argument parsing was suppressed, but an attempt to invoke #{meth} was made"
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
- @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
- @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 = name
100
- key = name.to_sym if @keys_values.first.first.instance_of?(Symbol)
101
- value = @keys_values[key]
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.2
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-17 00:00:00.000000000 Z
11
+ date: 2023-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll