jekyll_from_to_until 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e9c06080cf832cfcda1eb6c9cd671885c26f512947574df19e6a6ac1fe5c35a
4
- data.tar.gz: dd4b79b63729f6317cee948f042ce2988668115b9a0a90c654e95518c9902f1f
3
+ metadata.gz: 1a9e56c1266c423bdcca5f7fc1a5bfbd88038b3b7c92fbb84f0d05f73041f091
4
+ data.tar.gz: 6526b906d36f9937f63d0e81211dad42bec006eda5ec1cf62b286168925c489a
5
5
  SHA512:
6
- metadata.gz: e9586ed9c90b47badb95791248aee4b8774b7c335314881902182f499be6afb173cdc085925186c164bb2bdc77192546ede605579cc39cf3b2b58f5a62f23ddd
7
- data.tar.gz: f662add178d12e1be22f3595781e974908c6d0b637d78af8d2abd6c03aadc3b6918e4c115723bd5ebaf67966196b969569869695fb3191efea5fe48974acb44e
6
+ metadata.gz: b8a0f1ec7d9032e98edc3bd6729a1037b9884fb7b1ef7614f8b9f53045f5d223cf4615588d3f62c9fa604daeef8e06dc03d371fe452b34df6152c2545d8e3cab
7
+ data.tar.gz: 7a3621381e1d6bc4258728b98520087d8954035cfceecc2932885f77f6f87879f2d8d163f7fd07552a68ec134ded6b0b6a7e206382e979bacf06e57315a889ca
data/.rubocop.yml CHANGED
@@ -11,11 +11,11 @@ require:
11
11
  AllCops:
12
12
  Exclude:
13
13
  - demo/_site/**/*
14
+ - binstub/**/*
14
15
  - exe/**/*
15
16
  - vendor/**/*
16
17
  - Gemfile*
17
18
  NewCops: enable
18
- TargetRubyVersion: 2.6
19
19
 
20
20
  Gemspec/DeprecatedAttributeAssignment:
21
21
  Enabled: false
@@ -23,6 +23,9 @@ Gemspec/DeprecatedAttributeAssignment:
23
23
  Gemspec/RequireMFA:
24
24
  Enabled: false
25
25
 
26
+ Gemspec/RequiredRubyVersion:
27
+ Enabled: false
28
+
26
29
  Layout/HashAlignment:
27
30
  EnforcedColonStyle: table
28
31
  Exclude:
data/CHANGELOG.md CHANGED
@@ -1,18 +1,45 @@
1
+ # Change Log
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
+
14
+ ## 1.0.4 / 2023-11-18
15
+
16
+ * Now callable from any Ruby program
17
+
18
+
1
19
  ## 1.0.3 / 2023-02-25
2
- * Fixed `undefined method 'registers' for nil:NilClass (NoMethodError)`
20
+
21
+ * Fixed `undefined method 'registers' for nil:NilClass (NoMethodError)`
22
+
3
23
 
4
24
  ## 1.0.2 / 2023-02-21
5
- * Improved how the logger was used.
6
- * Added `demo` website
25
+
26
+ * Improved how the logger was used.
27
+ * Added `demo` website
28
+
7
29
 
8
30
  ## 1.0.1 / 2022-04-05
9
- * Updated to `jekyll_plugin_logger` v2.1.0
31
+
32
+ * Updated to `jekyll_plugin_logger` v2.1.0
33
+
10
34
 
11
35
  ## 1.0.0 / 2022-03-14
12
- * Made into a Ruby gem and published on RubyGems.org as [jekyll_from_to_until](https://rubygems.org/gems/jekyll_from_to_until).
13
- * `bin/attach` script added for debugging
14
- * Rubocop standards added
15
- * Proper versioning and CHANGELOG.md added
36
+
37
+ * Made into a Ruby gem and published on RubyGems.org as [jekyll_from_to_until](https://rubygems.org/gems/jekyll_from_to_until).
38
+ * `bin/attach` script added for debugging
39
+ * Rubocop standards added
40
+ * Proper versioning and CHANGELOG.md added
41
+
16
42
 
17
43
  ## 0.1.0 / 2020-12-29
18
- * Initial version published
44
+
45
+ * Initial version published
data/README.md CHANGED
@@ -1,65 +1,119 @@
1
- `jekyll_from_to_until`
2
- [![Gem Version](https://badge.fury.io/rb/jekyll_from_to_until.svg)](https://badge.fury.io/rb/jekyll_from_to_until)
3
- ===========
1
+ # `jekyll_from_to_until` [![Gem Version](https://badge.fury.io/rb/jekyll_from_to_until.svg)](https://badge.fury.io/rb/jekyll_from_to_until)
4
2
 
5
- This Jekyll plugin provides 3 filters that return portions of a multiline string.
6
- Regular expression is used to specify matches; the simplest regular expression is a string.
7
- * `from` — returns the portion beginning with the line that satisfies a regular expression to the end of the multiline string.
8
- * `to` returns the portion from the first line to the line that satisfies a regular expression, including the matched line.
9
- * `until` — returns the portion from the first line to the line that satisfies a regular expression, excluding the matched line.
3
+ This module provides 3 filters that return portions of a multiline string.
4
+ It can be used as a Jekyll plugin, or it can be called from any Ruby program.
5
+
6
+ Matches are specified by regular expressions; the simplest regular expression is a string.
7
+
8
+ * `from` — returns the portion beginning with the line that satisfies a regular expression to the end of the multiline string.
9
+ * `to` — returns the portion from the first line to the line that satisfies a regular expression, including the matched line.
10
+ * `until` — returns the portion from the first line to the line that satisfies a regular expression, excluding the matched line.
10
11
 
11
12
  [Rubular](https://rubular.com/) is a handy online tool to try out regular expressions.
12
13
 
13
14
 
14
- ### Additional Information
15
- More information is available on my web site about [my Jekyll plugins](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html).
15
+ ## Additional Information
16
+
17
+ More information is available on the [`jekyll_from_to_until` gem web page](https://www.mslinn.com/jekyll_plugins/jekyll_from_to_until.html).
16
18
 
17
19
 
18
20
  ## Installation
19
21
 
20
- Add this line to your application's Gemfile:
22
+ ### As a Jekyll Filter Plugin
23
+
24
+ If you want to use this Ruby gem in a Jekyll application,
25
+ add the following line to your application's `Gemfile`:
21
26
 
22
27
  ```ruby
23
- gem 'jekyll_from_to_until'
28
+ group :jekyll_plugins do
29
+ gem 'jekyll_from_to_until'
30
+ end
24
31
  ```
25
32
 
26
33
  And then install in the usual fashion:
27
34
 
28
- $ bundle install
35
+ ```shell
36
+ $ bundle
37
+ ```
38
+
39
+ ### As a Dependency Of a Gem
40
+
41
+ Add the following line to your application's `.gemspec`:
42
+
43
+ ```ruby
44
+ spec.add_dependency 'jekyll_from_to_until'
45
+ ```
46
+
47
+ And then install the dependencies in the usual fashion:
48
+
49
+ ```shell
50
+ $ bundle
51
+ ```
29
52
 
53
+ ### As a Ruby Module In a Ruby Program
54
+
55
+ Add the following line to your application's `Gemfile`:
56
+
57
+ ```ruby
58
+ gem 'jekyll_from_to_until'
59
+ ```
60
+
61
+ And then install the dependencies in the usual fashion:
62
+
63
+ ```shell
64
+ $ bundle
65
+ ```
66
+
67
+
68
+ ## Jekyll Syntax
30
69
 
31
- ## Syntax
32
70
  The regular expression may be enclosed in single quotes, double quotes, or nothing.
33
71
 
72
+
34
73
  ### `from`
74
+
35
75
  All of these examples perform identically.
36
- ```
76
+
77
+ ```html
37
78
  {{ sourceOfLines | from: 'regex' }}
38
79
  {{ sourceOfLines | from: "regex" }}
39
80
  {{ sourceOfLines | from: regex }}
40
81
  ```
41
82
 
42
83
  ### `to`
84
+
43
85
  All of these examples perform identically.
44
- ```
86
+
87
+ ```html
45
88
  {{ sourceOfLines | to: 'regex' }}
46
89
  {{ sourceOfLines | to: "regex" }}
47
90
  {{ sourceOfLines | to: regex }}
48
91
  ```
49
92
 
50
93
  ### `until`
94
+
51
95
  All of these examples perform identically.
52
- ```
96
+
97
+ ```text
53
98
  {{ sourceOfLines | until: 'regex' }}
54
99
  {{ sourceOfLines | until: "regex" }}
55
100
  {{ sourceOfLines | until: regex }}
56
101
  ```
57
- :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)`
58
- ## Usage
102
+
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)`
110
+
111
+
112
+ ## Jekyll Usage
59
113
 
60
114
  Some of the following examples use a multiline string called `lines` that contains 5 lines, which was created this way:
61
115
 
62
- ```
116
+ ```html
63
117
  {% capture lines %}line 1
64
118
  line 2
65
119
  line 3
@@ -68,8 +122,10 @@ line 5
68
122
  {% endcapture %}
69
123
  ```
70
124
 
71
- Other examples use a multiline string called `gitignore` that contains the contents of a mythical `.gitignore` file, which looks like this:
72
- ```
125
+ Other examples use a multiline string called `gitignore` that contains the contents of a mythical `.gitignore` file,
126
+ which looks like this:
127
+
128
+ ```text
73
129
  .bsp/
74
130
  project/
75
131
  target/
@@ -114,27 +170,38 @@ cloud9.zip
114
170
  mslinn_aws.tar
115
171
  ```
116
172
 
173
+
117
174
  ### From the third line of string
118
- 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.
119
- ```
175
+
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.
179
+
180
+ ```html
120
181
  {{ lines | from: '3' }}
121
182
  {{ lines | from: "3" }}
122
183
  {{ lines | from: 3 }}
123
184
  ```
185
+
124
186
  The above all generate:
125
- ```
187
+
188
+ ```plain
126
189
  line 3
127
190
  line 4
128
191
  line 5
129
192
  ```
130
193
 
194
+
131
195
  ### From Line In a File Containing 'PID'
132
- ```
196
+
197
+ ```html
133
198
  {% capture gitignore %}{% flexible_include '.gitignore' %}{% endcapture %}
134
199
  {{ gitignore | from: 'PID' | xml_escape }}
135
200
  ```
201
+
136
202
  The above generates:
137
- ```
203
+
204
+ ```text
138
205
  RUNNING_PID
139
206
  mslinn_jekyll_plugins.zip
140
207
  cloud9.tar
@@ -142,26 +209,37 @@ cloud9.zip
142
209
  mslinn_aws.tar
143
210
  ```
144
211
 
212
+
145
213
  ### To the third line of string
146
- 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.
147
- ```
214
+
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.
218
+
219
+ ```html
148
220
  {{ lines | to: '3' }}
149
221
  {{ lines | to: "3" }}
150
222
  {{ lines | to: 3 }}
151
223
  ```
224
+
152
225
  The above all generate:
153
- ```
226
+
227
+ ```text
154
228
  line 1
155
229
  line 2
156
230
  line 3
157
231
  ```
158
232
 
233
+
159
234
  ### To Line In a File Containing 'idea'
160
- ```
235
+
236
+ ```html
161
237
  {{ gitignore | to: 'idea' }}
162
238
  ```
239
+
163
240
  The above generates:
164
- ```
241
+
242
+ ```text
165
243
  .bsp/
166
244
  project/
167
245
  target/
@@ -174,25 +252,35 @@ target/
174
252
  .idea*
175
253
  ```
176
254
 
255
+
177
256
  ### Until the third line of string
178
- 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.
179
- ```
257
+
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.
260
+
261
+ ```html
180
262
  {{ lines | until: '3' }}
181
263
  {{ lines | until: "3" }}
182
264
  {{ lines | until: 3 }}
183
265
  ```
266
+
184
267
  The above all generate:
185
- ```
268
+
269
+ ```text
186
270
  line 1
187
271
  line 2
188
272
  ```
189
273
 
274
+
190
275
  ### Until Line In a File Containing 'idea'
191
- ```
276
+
277
+ ```html
192
278
  {{ gitignore | until: 'idea' }}
193
279
  ```
280
+
194
281
  The above generates:
195
- ```
282
+
283
+ ```text
196
284
  .bsp/
197
285
  project/
198
286
  target/
@@ -204,26 +292,38 @@ target/
204
292
  *.log
205
293
  ```
206
294
 
295
+
207
296
  ### From the string "2" until the string "4"
208
- 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.
209
- ```
297
+
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.
300
+
301
+ ```html
210
302
  {{ lines | from: '2' | until: '4' }}
211
303
  {{ lines | from: "2" | until: "4" }}
212
304
  {{ lines | from: 2 | until: 4 }}
213
305
  ```
306
+
214
307
  The above all generate:
215
- ```
308
+
309
+ ```text
216
310
  line 2
217
311
  line 3
218
312
  ```
219
313
 
314
+
220
315
  ### From Line In a File Containing 'idea' Until no match
221
- 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.
222
- ```
316
+
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.
319
+
320
+ ```html
223
321
  {{ gitignore | from: 'PID' | until: 'xx' }}
224
322
  ```
323
+
225
324
  The above generates:
226
- ```
325
+
326
+ ```text
227
327
  RUNNING_PID
228
328
  mslinn_jekyll_plugins.zip
229
329
  cloud9.tar
@@ -231,21 +331,38 @@ cloud9.zip
231
331
  mslinn_aws.tar
232
332
  ```
233
333
 
334
+
234
335
  ### More Complex Regular Expressions
336
+
235
337
  The `from`, `to` and `until` filters can all accept regular expressions.
236
338
  The regular expression matches lines that have either the string `sun` or `cloud`
237
339
  at the beginning of the line.
238
- ```
340
+
341
+ ```html
239
342
  {{ gitignore | from: '^(cloud|sun)' }}
240
343
  ```
344
+
241
345
  The above generates:
242
- ```
346
+
347
+ ```text
243
348
  cloud9.tar
244
349
  cloud9.zip
245
350
  mslinn_aws.tar
246
351
  ```
247
352
 
248
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
+
249
366
  ## Development
250
367
 
251
368
  After checking out the repo, run `bin/setup` to install dependencies.
@@ -254,12 +371,15 @@ You can also run `bin/console` for an interactive prompt that will allow you to
254
371
 
255
372
 
256
373
  ### Build and Install Locally
374
+
257
375
  To build and install this gem onto your local machine, run:
258
- ```shell
376
+
377
+ ```shellSoap. XboxXboxOur cub Our company outcome.XboxParent
259
378
  $ bundle exec rake install
260
379
  ```
261
380
 
262
381
  Examine the newly built gem:
382
+
263
383
  ```shell
264
384
  $ gem info jekyll_from_to_until
265
385
 
@@ -275,12 +395,15 @@ jekyll_from_to_until (1.0.0)
275
395
  Generates Jekyll logger with colored output.
276
396
  ```
277
397
 
398
+
278
399
  ## Demo Website
400
+
279
401
  A test/demo website is provided in the `demo` directory.
280
402
  You can run it under a debugger, or let it run free.
281
403
 
282
404
  The `demo/_bin/debug` script can set various parameters for the demo.
283
405
  View the help information with the `-h` option:
406
+
284
407
  ```shell
285
408
  $ demo/_bin/debug -h
286
409
 
@@ -297,29 +420,34 @@ Options:
297
420
 
298
421
 
299
422
  ### Debugging the Demo
423
+
300
424
  To run under a debugger, for example Visual Studio Code:
301
- 1. Set breakpoints.
302
425
 
303
- 2. Initiate a debug session from the command line:
304
- ```shell
305
- $ demo/bin/debug
306
- ```
426
+ 1. Set breakpoints.
427
+ 2. Initiate a debug session from the command line:
307
428
 
308
- 3. Once the `Fast Debugger` signon appears, launch the Visual Studio Code launch configuration called `Attach rdebug-ide`.
429
+ ```shell
430
+ $ demo/bin/debug
431
+ ```
309
432
 
310
- 4. View the generated website at [`http://localhost:4444`](http://localhost:4444).
433
+ 3. Once the `Fast Debugger` signon appears, launch the Visual Studio Code launch configuration called `Attach rdebug-ide`.
434
+ 4. View the generated website at [`http://localhost:4444`](http://localhost:4444).
311
435
 
312
436
 
313
437
  ### Build and Push to RubyGems
438
+
314
439
  To release a new version,
315
- 1. Update the version number in `version.rb`.
316
- 2. Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
317
- 3. Run the following:
318
- ```shell
319
- $ bundle exec rake release
320
- ```
321
- The above creates a git tag for the version, commits the created tag,
322
- and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
440
+
441
+ 1. Update the version number in `version.rb`.
442
+ 2. Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
443
+ 3. Run the following:
444
+
445
+ ```shell
446
+ $ bundle exec rake release
447
+ ```
448
+
449
+ The above creates a git tag for the version, commits the created tag,
450
+ and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
323
451
 
324
452
 
325
453
  ## Contributing
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  END_DESC
12
12
  spec.email = ['mslinn@mslinn.com']
13
13
  spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
14
- spec.homepage = 'https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#from_to_until'
14
+ spec.homepage = 'https://www.mslinn.com/jekyll_plugins/jekyll_from_to_until.html'
15
15
  spec.license = 'MIT'
16
16
  spec.metadata = {
17
17
  'allowed_push_host' => 'https://rubygems.org',
@@ -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.3'.freeze
2
+ VERSION = '1.0.5'.freeze
3
3
  end
@@ -1,92 +1,140 @@
1
- # @author Copyright 2020 Michael Slinn
2
1
  # Jekyll filters for working with multiline strings.
3
2
 
4
- require 'jekyll_plugin_logger'
5
- require 'liquid'
3
+ require 'htmlentities'
6
4
  require_relative 'jekyll_from_to_until/version'
7
5
 
8
6
  module JekyllPluginFromToUntilName
9
7
  PLUGIN_NAME = 'jekyll_from_to_until'.freeze
10
8
  end
11
9
 
12
- module FromToUntil
13
- @logger = PluginMetaLogger.instance.new_logger("FromToUntil", PluginMetaLogger.instance.config)
14
-
15
- # Filters a multiline string, returning the portion beginning with the line that satisfies a regex.
16
- # The regex could be enclosed in single quotes, double quotes, or nothing.
17
- # @param input_strings [String] The multi-line string to scan
18
- # @param regex [String] The regular expression to match against each line of `input_strings` until found
19
- # @return [String] The remaining multi-line string
20
- # @example Returns remaining lines starting with the line containing the word `module`.
21
- # {{ flexible_include '/blog/2020/10/03/jekyll-plugins.html' | from 'module' }}
22
- def from(input_strings, regex)
23
- return '' unless check_parameters(input_strings, regex)
24
-
25
- regex = remove_quotations(regex.to_s.strip)
26
- matched = false
27
- result = ''
28
- input_strings.each_line do |line|
29
- matched = true if !matched && line =~ %r!#{regex}!
30
- result += line if matched
10
+ CALLED_FROM_JEKYLL = !$LOADED_FEATURES.grep(/.*liquid.rb/).empty?
11
+
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
31
41
  end
32
- result
33
- end
34
42
 
35
- # Filters a multiline string, returning the portion from the beginning until and including the line that satisfies a regex.
36
- # The regex could be enclosed in single quotes, double quotes, or nothing.
37
- # @example Returns lines up to and including the line containing the word `module`.
38
- # {{ flexible_include '/blog/2020/10/03/jekyll-plugins.html' | to 'module' }}
39
- def to(input_strings, regex)
40
- return '' unless check_parameters(input_strings, regex)
41
-
42
- regex = remove_quotations(regex.to_s.strip)
43
- result = ''
44
- input_strings.each_line do |line|
45
- result += line
46
- 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
47
57
  end
48
- result
49
- end
50
58
 
51
- # Filters a multiline string, returning the portion from the beginning until but not including the line that satisfies a regex.
52
- # The regex could be enclosed in single quotes, double quotes, or nothing.
53
- # @example Returns lines up to but not including the line containing the word `module`.
54
- # {{ flexible_include '/blog/2020/10/03/jekyll-plugins.html' | until 'module' }}
55
- def until(input_strings, regex)
56
- return '' unless check_parameters(input_strings, regex)
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)
57
65
 
58
- regex = remove_quotations(regex.to_s.strip)
59
- result = ''
60
- input_strings.each_line do |line|
61
- return result if line.match?(%r!#{regex}!)
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}!)
62
70
 
63
- result += line
71
+ result += line
72
+ end
73
+ result
64
74
  end
65
- result
75
+
76
+ private if CALLED_FROM_JEKYLL
77
+
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
83
+
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
90
+ end
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
66
99
  end
67
100
 
68
- private
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
108
+
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
113
+ end
69
114
 
70
- def check_parameters(input_strings, regex)
71
- if input_strings.nil? || input_strings.empty?
72
- @logger.warn { "Warning: Plugin 'from' received no input for regex #{regex}." }
73
- 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
74
119
  end
75
120
 
76
- regex = regex.to_s
77
- if regex.nil? || regex.empty?
78
- @logger.warn { "Warning: Plugin 'from' received no regex for input #{input_strings}." }
79
- return false
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(']', ']')
80
133
  end
81
- true
82
134
  end
83
135
 
84
- def remove_quotations(str)
85
- str = str.slice(1..-2) if (str.start_with?('"') && str.end_with?('"')) ||
86
- (str.start_with?("'") && str.end_with?("'"))
87
- str
136
+ if CALLED_FROM_JEKYLL
137
+ PluginMetaLogger.instance.info { "Loaded #{JekyllPluginFromToUntilName::PLUGIN_NAME} v#{JekyllFromToUntilVersion::VERSION} plugin." }
138
+ Liquid::Template.register_filter(FromToUntilFilter)
88
139
  end
89
140
  end
90
-
91
- PluginMetaLogger.instance.info { "Loaded #{JekyllPluginFromToUntilName::PLUGIN_NAME} v#{JekyllFromToUntilVersion::VERSION} plugin." }
92
- Liquid::Template.register_filter(FromToUntil)
@@ -2,8 +2,8 @@ require 'jekyll'
2
2
  require 'fileutils'
3
3
  require_relative '../lib/jekyll_from_to_until'
4
4
 
5
- RSpec.describe(JekyllFromToUntil) do
6
- include JekyllFromToUntil
5
+ RSpec.describe(FromToUntil) do
6
+ include described_class
7
7
 
8
8
  let(:lines) do
9
9
  <<~END_OF_LINES
data/spec/spec_helper.rb CHANGED
@@ -5,9 +5,8 @@ require_relative '../lib/jekyll_from_to_until'
5
5
  Jekyll.logger.log_level = :info
6
6
 
7
7
  RSpec.configure do |config|
8
- config.filter_run :focus
9
- config.order = 'random'
10
- config.run_all_when_everything_filtered = true
8
+ config.filter_run_when_matching focus: true
9
+ # config.order = 'random'
11
10
 
12
11
  # See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
13
12
  config.example_status_persistence_file_path = "spec/status_persistence.txt"
@@ -0,0 +1,6 @@
1
+ example_id | status | run_time |
2
+ ---------------------------------------- | ------ | --------------- |
3
+ ./spec/jekyll_from_to_until_spec.rb[1:1] | passed | 0.00121 seconds |
4
+ ./spec/jekyll_from_to_until_spec.rb[1:2] | passed | 0.00007 seconds |
5
+ ./spec/jekyll_from_to_until_spec.rb[1:3] | passed | 0.00005 seconds |
6
+ ./spec/jekyll_from_to_until_spec.rb[1:4] | passed | 0.00015 seconds |
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.3
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-02-27 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
@@ -55,20 +69,21 @@ files:
55
69
  - jekyll_from_to_until.gemspec
56
70
  - lib/jekyll_from_to_until.rb
57
71
  - lib/jekyll_from_to_until/version.rb
58
- - spec/from_to_until_spec.rb
72
+ - spec/jekyll_from_to_until_spec.rb
59
73
  - spec/spec_helper.rb
60
- homepage: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#from_to_until
74
+ - spec/status_persistence.txt
75
+ homepage: https://www.mslinn.com/jekyll_plugins/jekyll_from_to_until.html
61
76
  licenses:
62
77
  - MIT
63
78
  metadata:
64
79
  allowed_push_host: https://rubygems.org
65
80
  bug_tracker_uri: https://github.com/mslinn/jekyll_from_to_until/issues
66
81
  changelog_uri: https://github.com/mslinn/jekyll_from_to_until/CHANGELOG.md
67
- homepage_uri: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#from_to_until
82
+ homepage_uri: https://www.mslinn.com/jekyll_plugins/jekyll_from_to_until.html
68
83
  source_code_uri: https://github.com/mslinn/jekyll_from_to_until
69
84
  post_install_message: |2+
70
85
 
71
- Thanks for installing jekyll_from_to_until v1.0.3!
86
+ Thanks for installing jekyll_from_to_until v1.0.5!
72
87
 
73
88
  rdoc_options: []
74
89
  require_paths:
@@ -84,12 +99,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
99
  - !ruby/object:Gem::Version
85
100
  version: '0'
86
101
  requirements: []
87
- rubygems_version: 3.3.3
102
+ rubygems_version: 3.5.17
88
103
  signing_key:
89
104
  specification_version: 4
90
105
  summary: 'This Jekyll plugin provides 3 filters that return portions of a multiline
91
106
  string: from, to and until.'
92
107
  test_files:
93
- - spec/from_to_until_spec.rb
108
+ - spec/jekyll_from_to_until_spec.rb
94
109
  - spec/spec_helper.rb
110
+ - spec/status_persistence.txt
95
111
  ...