jekyll_from_to_until 1.0.4 → 1.0.5

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: df28899e4d0c5ef83e25c224bf13ab963540f5329fdb901e57810fc8959f6c8e
4
- data.tar.gz: 1e6159cef57b71549fb95a94052e46a535d5f9a9d05bc45aa8749102c7af9774
3
+ metadata.gz: 1a9e56c1266c423bdcca5f7fc1a5bfbd88038b3b7c92fbb84f0d05f73041f091
4
+ data.tar.gz: 6526b906d36f9937f63d0e81211dad42bec006eda5ec1cf62b286168925c489a
5
5
  SHA512:
6
- metadata.gz: ff87af96660512fa9e48546598ff7a0130db3ff83e8ed4ab6945e5261ddbd88257904a343345ec999f076be98e444a51c6ce78cc0281454fe5eec69f2a40a184
7
- data.tar.gz: 4f44c850b030ee09f151ffa98af5e2442f0285a396f004d38e637b7011c9572d894052e582c70e4bc5627295537665e7d1b6c4f336e61391cbda4642b683e332
6
+ metadata.gz: b8a0f1ec7d9032e98edc3bd6729a1037b9884fb7b1ef7614f8b9f53045f5d223cf4615588d3f62c9fa604daeef8e06dc03d371fe452b34df6152c2545d8e3cab
7
+ data.tar.gz: 7a3621381e1d6bc4258728b98520087d8954035cfceecc2932885f77f6f87879f2d8d163f7fd07552a68ec134ded6b0b6a7e206382e979bacf06e57315a889ca
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.0.5 / 2024-08-22
4
+
5
+ * Fixed method forwarding
6
+ * Regexes are now subjected to an HTML unescape, so special characters are now supported,
7
+ such as the right closing squiggly bracket:
8
+
9
+ ```html
10
+ {{ css | from: '.error' | to: '}' | strip }}
11
+ ```
12
+
13
+
3
14
  ## 1.0.4 / 2023-11-18
4
15
 
5
16
  * Now callable from any Ruby program
data/README.md CHANGED
@@ -22,7 +22,7 @@ More information is available on the [`jekyll_from_to_until` gem web page](https
22
22
  ### As a Jekyll Filter Plugin
23
23
 
24
24
  If you want to use this Ruby gem in a Jekyll application,
25
- add the following line to your application's Gemfile:
25
+ add the following line to your application's `Gemfile`:
26
26
 
27
27
  ```ruby
28
28
  group :jekyll_plugins do
@@ -100,7 +100,13 @@ All of these examples perform identically.
100
100
  {{ sourceOfLines | until: regex }}
101
101
  ```
102
102
 
103
- :warning: Important: the name of the filter must be followed by a colon (:). If you fail to do that an error will be generated and the Jekyll site building process will halt. The error message looks something like this: `Liquid Warning: Liquid syntax error (line 285): Expected end_of_string but found string in "{{ lines | from '2' | until: '4' | xml_escape }}" in /some_directory/some_files.html Liquid Exception: Liquid error (line 285): wrong number of arguments (given 1, expected 2) in /some_directory/some_file.html Error: Liquid error (line 285): wrong number of arguments (given 1, expected 2)`
103
+ :warning: Important: the name of the filter must be followed by a colon (:).
104
+ If you fail to do that an error will be generated and the Jekyll site building process will halt.
105
+ The error message looks something like this:
106
+ `Liquid Warning: Liquid syntax error (line 285): Expected end_of_string but found string in
107
+ "{{ lines | from '2' | until: '4' | xml_escape }}" in /some_directory/some_files.html Liquid Exception:
108
+ Liquid error (line 285): wrong number of arguments (given 1, expected 2) in /some_directory/some_file.
109
+ html Error: Liquid error (line 285): wrong number of arguments (given 1, expected 2)`
104
110
 
105
111
 
106
112
  ## Jekyll Usage
@@ -167,7 +173,9 @@ mslinn_aws.tar
167
173
 
168
174
  ### From the third line of string
169
175
 
170
- These examples return the lines of the file from the beginning of the until a line with the string "3" is found, including the matched line. The only difference between the examples is the delimiter around the regular expression.
176
+ These examples return the lines of the file from the beginning of the until a line with the string "3" is found,
177
+ including the matched line.
178
+ The only difference between the examples is the delimiter around the regular expression.
171
179
 
172
180
  ```html
173
181
  {{ lines | from: '3' }}
@@ -204,7 +212,9 @@ mslinn_aws.tar
204
212
 
205
213
  ### To the third line of string
206
214
 
207
- These examples return the lines of the file from the first line until a line with the string `"3"` is found, including the matched line. The only difference between the examples is the delimiter around the regular expression.
215
+ These examples return the lines of the file from the first line until a line with the string `"3"` is found,
216
+ including the matched line.
217
+ The only difference between the examples is the delimiter around the regular expression.
208
218
 
209
219
  ```html
210
220
  {{ lines | to: '3' }}
@@ -245,7 +255,8 @@ target/
245
255
 
246
256
  ### Until the third line of string
247
257
 
248
- These examples return the lines of the file until a line with the string `"3"` is found, excluding the matched line. The only difference between the examples is the delimiter around the regular expression.
258
+ These examples return the lines of the file until a line with the string `"3"` is found, excluding the matched line.
259
+ The only difference between the examples is the delimiter around the regular expression.
249
260
 
250
261
  ```html
251
262
  {{ lines | until: '3' }}
@@ -284,7 +295,8 @@ target/
284
295
 
285
296
  ### From the string "2" until the string "4"
286
297
 
287
- These examples return the lines of the file until a line with the string `"3"` is found, excluding the matched line. The only difference between the examples is the delimiter around the regular expression.
298
+ These examples return the lines of the file until a line with the string `"3"` is found, excluding the matched line.
299
+ The only difference between the examples is the delimiter around the regular expression.
288
300
 
289
301
  ```html
290
302
  {{ lines | from: '2' | until: '4' }}
@@ -302,7 +314,8 @@ line 3
302
314
 
303
315
  ### From Line In a File Containing 'idea' Until no match
304
316
 
305
- The `.gitignore` file does not contain the string `xx`. If we attempt to match against that string the remainder of the file is returned for the to and until filter, and the empty string is returned for the from filter.
317
+ The `.gitignore` file does not contain the string `xx`.
318
+ If we attempt to match against that string the remainder of the file is returned for the to and until filter.
306
319
 
307
320
  ```html
308
321
  {{ gitignore | from: 'PID' | until: 'xx' }}
@@ -338,6 +351,18 @@ mslinn_aws.tar
338
351
  ```
339
352
 
340
353
 
354
+ ### Encoding Special Characters
355
+
356
+ Special characters can be specified as HTML entities.
357
+ For example, `}` is `Open parenthesis. Belle par. A parent. 5 Resulting. OK. }`.
358
+
359
+ ```html
360
+ {{ css | from: '.error' | to: '}' | strip }}
361
+ ```
362
+
363
+ `demo/special.html` demonstrates this.
364
+
365
+
341
366
  ## Development
342
367
 
343
368
  After checking out the repo, run `bin/setup` to install dependencies.
@@ -349,7 +374,7 @@ You can also run `bin/console` for an interactive prompt that will allow you to
349
374
 
350
375
  To build and install this gem onto your local machine, run:
351
376
 
352
- ```shell
377
+ ```shellSoap. XboxXboxOur cub Our company outcome.XboxParent
353
378
  $ bundle exec rake install
354
379
  ```
355
380
 
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.test_files = spec.files.grep(%r!^(test|spec|features)/!)
33
33
  spec.version = JekyllFromToUntilVersion::VERSION
34
34
 
35
+ spec.add_dependency 'htmlentities'
35
36
  spec.add_dependency 'jekyll', '>= 3.5.0'
36
37
  spec.add_dependency 'jekyll_plugin_logger'
37
38
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllFromToUntilVersion
2
- VERSION = '1.0.4'.freeze
2
+ VERSION = '1.0.5'.freeze
3
3
  end
@@ -1,5 +1,6 @@
1
1
  # Jekyll filters for working with multiline strings.
2
2
 
3
+ require 'htmlentities'
3
4
  require_relative 'jekyll_from_to_until/version'
4
5
 
5
6
  module JekyllPluginFromToUntilName
@@ -8,95 +9,132 @@ end
8
9
 
9
10
  CALLED_FROM_JEKYLL = !$LOADED_FEATURES.grep(/.*liquid.rb/).empty?
10
11
 
11
- module FromToUntil
12
- @logger = if CALLED_FROM_JEKYLL
13
- require 'liquid'
14
- require 'jekyll_plugin_logger'
15
- PluginMetaLogger.instance.new_logger "FromToUntil", PluginMetaLogger.instance.config
16
- else
17
- require 'logger'
18
- Logger.new $stdout
19
- end
20
-
21
- # Filters a multiline string, returning the portion beginning with the line that satisfies a regex.
22
- # The regex could be enclosed in single quotes, double quotes, or nothing.
23
- # @param input_strings [String] The multi-line string to scan
24
- # @param regex [String] The regular expression to match against each line of `input_strings` until found
25
- # @return [String] The remaining multi-line string
26
- # @example Returns remaining lines starting with the line containing the word `module`.
27
- # {{ flexible_include '/blog/2020/10/03/jekyll-plugins.html' | from 'module' }}
28
- def from(input_strings, regex)
29
- return '' unless check_parameters(input_strings, regex)
30
-
31
- regex = remove_quotations(regex.to_s.strip)
32
- matched = false
33
- result = ''
34
- input_strings.each_line do |line|
35
- matched = true if !matched && line =~ %r!#{regex}!
36
- result += line if matched
12
+ module Jekyll
13
+ module FromToUntil
14
+ @logger = if CALLED_FROM_JEKYLL
15
+ require 'liquid'
16
+ require 'jekyll_plugin_logger'
17
+ PluginMetaLogger.instance.new_logger "FromToUntil", PluginMetaLogger.instance.config
18
+ else
19
+ require 'logger'
20
+ Logger.new $stdout
21
+ end
22
+
23
+ # Filters a multiline string, returning the portion beginning with the line that satisfies a regex.
24
+ # The regex could be enclosed in single quotes, double quotes, or nothing.
25
+ # @param input_strings [String] The multi-line string to scan
26
+ # @param regex [String] The regular expression to match against each line of `input_strings` until found
27
+ # @return [String] The remaining multi-line string
28
+ # @example Returns remaining lines starting with the line containing the word `module`.
29
+ # {{ flexible_include '/blog/2020/10/03/jekyll-plugins.html' | from 'module' }}
30
+ def from(input_strings, regex)
31
+ return '' unless check_parameters(input_strings, regex)
32
+
33
+ regex = remove_quotations(regex.to_s.strip)
34
+ matched = false
35
+ result = ''
36
+ input_strings.each_line do |line|
37
+ matched = true if !matched && line =~ %r!#{regex}!
38
+ result += line if matched
39
+ end
40
+ result
37
41
  end
38
- result
39
- end
40
42
 
41
- # Filters a multiline string, returning the portion from the beginning until and including the line that satisfies a regex.
42
- # The regex could be enclosed in single quotes, double quotes, or nothing.
43
- # @example Returns lines up to and including the line containing the word `module`.
44
- # {{ flexible_include '/blog/2020/10/03/jekyll-plugins.html' | to 'module' }}
45
- def to(input_strings, regex)
46
- return '' unless check_parameters(input_strings, regex)
47
-
48
- regex = remove_quotations(regex.to_s.strip)
49
- result = ''
50
- input_strings.each_line do |line|
51
- result += line
52
- return result if line.match?(%r!#{regex}!)
43
+ # Filters a multiline string, returning the portion from the beginning until and including the line that satisfies a regex.
44
+ # The regex could be enclosed in single quotes, double quotes, or nothing.
45
+ # @example Returns lines up to and including the line containing the word `module`.
46
+ # {{ flexible_include '/blog/2020/10/03/jekyll-plugins.html' | to 'module' }}
47
+ def to(input_strings, regex)
48
+ return '' unless check_parameters(input_strings, regex)
49
+
50
+ regex = remove_quotations(regex.to_s.strip)
51
+ result = ''
52
+ input_strings.each_line do |line|
53
+ result += line
54
+ return result if line.match?(%r!#{regex}!)
55
+ end
56
+ result
57
+ end
58
+
59
+ # Filters a multiline string, returning the portion from the beginning until but not including the line that satisfies a regex.
60
+ # The regex could be enclosed in single quotes, double quotes, or nothing.
61
+ # @example Returns lines up to but not including the line containing the word `module`.
62
+ # {{ flexible_include '/blog/2020/10/03/jekyll-plugins.html' | until 'module' }}
63
+ def until(input_strings, regex)
64
+ return '' unless check_parameters(input_strings, regex)
65
+
66
+ regex = remove_quotations(regex.to_s.strip)
67
+ result = ''
68
+ input_strings.each_line do |line|
69
+ return result if line.match?(%r!#{regex}!)
70
+
71
+ result += line
72
+ end
73
+ result
53
74
  end
54
- result
55
- end
56
75
 
57
- # Filters a multiline string, returning the portion from the beginning until but not including the line that satisfies a regex.
58
- # The regex could be enclosed in single quotes, double quotes, or nothing.
59
- # @example Returns lines up to but not including the line containing the word `module`.
60
- # {{ flexible_include '/blog/2020/10/03/jekyll-plugins.html' | until 'module' }}
61
- def until(input_strings, regex)
62
- return '' unless check_parameters(input_strings, regex)
76
+ private if CALLED_FROM_JEKYLL
63
77
 
64
- regex = remove_quotations(regex.to_s.strip)
65
- result = ''
66
- input_strings.each_line do |line|
67
- return result if line.match?(%r!#{regex}!)
78
+ def check_parameters(input_strings, regex)
79
+ if input_strings.nil? || input_strings.empty?
80
+ @logger.warn { "Warning: Plugin 'from' received no input for regex #{regex}." }
81
+ return false
82
+ end
68
83
 
69
- result += line
84
+ regex = regex.to_s
85
+ if regex.nil? || regex.empty?
86
+ @logger.warn { "Warning: Plugin 'from' received no regex for input #{input_strings}." }
87
+ return false
88
+ end
89
+ true
70
90
  end
71
- result
91
+
92
+ def remove_quotations(str)
93
+ str = str.slice(1..-2) if (str.start_with?('"') && str.end_with?('"')) ||
94
+ (str.start_with?("'") && str.end_with?("'"))
95
+ str
96
+ end
97
+
98
+ module_function :from, :to, :until, :check_parameters, :remove_quotations
72
99
  end
73
100
 
74
- private if CALLED_FROM_JEKYLL
101
+ # See https://www.mslinn.com/jekyll/10400-jekyll-plugin-template-collection.html#module_function
102
+ module FromToUntilFilter
103
+ def from(input_strings, regex)
104
+ input_strings = extra_decode HTMLEntities.new.decode input_strings
105
+ regex = extra_decode HTMLEntities.new.decode regex
106
+ FromToUntil.from(input_strings, regex) # method forwarding
107
+ end
75
108
 
76
- def check_parameters(input_strings, regex)
77
- if input_strings.nil? || input_strings.empty?
78
- @logger.warn { "Warning: Plugin 'from' received no input for regex #{regex}." }
79
- return false
109
+ def to(input_strings, regex)
110
+ input_strings = extra_decode HTMLEntities.new.decode input_strings
111
+ regex = extra_decode HTMLEntities.new.decode regex
112
+ FromToUntil.to(input_strings, regex) # method forwarding
80
113
  end
81
114
 
82
- regex = regex.to_s
83
- if regex.nil? || regex.empty?
84
- @logger.warn { "Warning: Plugin 'from' received no regex for input #{input_strings}." }
85
- return false
115
+ def until(input_strings, regex)
116
+ input_strings = extra_decode HTMLEntities.new.decode input_strings
117
+ regex = extra_decode HTMLEntities.new.decode regex
118
+ FromToUntil.until(input_strings, regex) # method forwarding
86
119
  end
87
- true
88
- end
89
120
 
90
- def remove_quotations(str)
91
- str = str.slice(1..-2) if (str.start_with?('"') && str.end_with?('"')) ||
92
- (str.start_with?("'") && str.end_with?("'"))
93
- str
121
+ # HTMLEntities does not support enough HTML entities
122
+ def extra_decode(line)
123
+ line.gsub('{', '{')
124
+ .gsub('}', '}')
125
+ .gsub('(', '(')
126
+ .gsub(')', ')')
127
+ .gsub('&lparen;', '(')
128
+ .gsub('&rparen;', ')')
129
+ .gsub('[', '[')
130
+ .gsub(']', ']')
131
+ .gsub('[', '[')
132
+ .gsub(']', ']')
133
+ end
94
134
  end
95
135
 
96
- module_function :from, :to, :until, :check_parameters, :remove_quotations
97
- end
98
-
99
- if CALLED_FROM_JEKYLL
100
- PluginMetaLogger.instance.info { "Loaded #{JekyllPluginFromToUntilName::PLUGIN_NAME} v#{JekyllFromToUntilVersion::VERSION} plugin." }
101
- Liquid::Template.register_filter(FromToUntil)
136
+ if CALLED_FROM_JEKYLL
137
+ PluginMetaLogger.instance.info { "Loaded #{JekyllPluginFromToUntilName::PLUGIN_NAME} v#{JekyllFromToUntilVersion::VERSION} plugin." }
138
+ Liquid::Template.register_filter(FromToUntilFilter)
139
+ end
102
140
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_from_to_until
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
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-11-22 00:00:00.000000000 Z
11
+ date: 2024-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: htmlentities
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: jekyll
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -69,7 +83,7 @@ metadata:
69
83
  source_code_uri: https://github.com/mslinn/jekyll_from_to_until
70
84
  post_install_message: |2+
71
85
 
72
- Thanks for installing jekyll_from_to_until v1.0.4!
86
+ Thanks for installing jekyll_from_to_until v1.0.5!
73
87
 
74
88
  rdoc_options: []
75
89
  require_paths:
@@ -85,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
99
  - !ruby/object:Gem::Version
86
100
  version: '0'
87
101
  requirements: []
88
- rubygems_version: 3.3.7
102
+ rubygems_version: 3.5.17
89
103
  signing_key:
90
104
  specification_version: 4
91
105
  summary: 'This Jekyll plugin provides 3 filters that return portions of a multiline