jekyll_plugin_support 0.5.3 → 0.6.1
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 +4 -4
- data/.rubocop.yml +51 -45
- data/ATTIBUTION_NOTES.md +4 -0
- data/CHANGELOG.md +9 -0
- data/README.md +110 -10
- data/jekyll_plugin_support.gemspec +2 -1
- data/lib/call_chain.rb +54 -0
- data/lib/gem_support.rb +19 -0
- data/lib/{jekyll_plugin_support_helper.rb → jekyll_plugin_helper.rb} +78 -14
- data/lib/jekyll_plugin_support/version.rb +1 -1
- data/lib/jekyll_plugin_support.rb +15 -2
- data/spec/jekyll_plugin_helper_call_spec.rb +21 -0
- data/spec/{jekyll_block_plugin_support_spec.rb → jekyll_plugin_helper_options_spec.rb} +1 -1
- data/spec/status_persistence.txt +4 -6
- metadata +26 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fa04aaa91759fb0cea5d52005f80d854c0e88bdc6c7300d167fd85737cdc584
|
4
|
+
data.tar.gz: '0183049f3234a4d97e071dc00055fd79d844da86ef8c6d836c1c8be3b1430d1b'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48bcfac7c6a918b7ad182bdcb5890c5707a5955d119df6ad03304c0a4712e07b7b5d523668fa6fc391a41e403706810d8939ac8c5c6ff1d7616db35ee804f017
|
7
|
+
data.tar.gz: 6adc3d6a4b5cebbf081b8b53abe3cc6abdac822046abbfe1d350f85f18d4c45f4861c0bed91cad29117d88605e49f22afb79d4b65adc6b35413924df6556d579
|
data/.rubocop.yml
CHANGED
@@ -1,61 +1,67 @@
|
|
1
|
-
require:
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require:
|
2
|
+
- rubocop-md
|
3
|
+
- rubocop-performance
|
4
|
+
- rubocop-rake
|
5
|
+
- rubocop-rspec
|
6
|
+
# - rubocop-jekyll
|
5
7
|
|
6
|
-
AllCops:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
AllCops:
|
9
|
+
Exclude:
|
10
|
+
- demo/_site/**/*
|
11
|
+
- exe/**/*
|
12
|
+
- vendor/**/*
|
13
|
+
- Gemfile*
|
14
|
+
NewCops: enable
|
15
|
+
TargetRubyVersion: 2.6
|
14
16
|
|
15
|
-
Gemspec/DeprecatedAttributeAssignment:
|
16
|
-
|
17
|
+
Gemspec/DeprecatedAttributeAssignment:
|
18
|
+
Enabled: false
|
17
19
|
|
18
|
-
Gemspec/RequireMFA:
|
19
|
-
|
20
|
+
Gemspec/RequireMFA:
|
21
|
+
Enabled: false
|
20
22
|
|
21
|
-
Layout/HashAlignment:
|
22
|
-
|
23
|
+
Layout/HashAlignment:
|
24
|
+
EnforcedColonStyle: table
|
25
|
+
EnforcedHashRocketStyle: table
|
23
26
|
|
24
|
-
Layout/LineLength:
|
25
|
-
|
27
|
+
Layout/LineLength:
|
28
|
+
Max: 150
|
26
29
|
|
27
|
-
Layout/CommentIndentation:
|
28
|
-
|
29
|
-
|
30
|
+
Layout/CommentIndentation:
|
31
|
+
Exclude:
|
32
|
+
- spec/**/*
|
30
33
|
|
31
|
-
Layout/MultilineMethodCallIndentation:
|
32
|
-
|
34
|
+
Layout/MultilineMethodCallIndentation:
|
35
|
+
Enabled: false
|
33
36
|
|
34
|
-
Lint/RedundantCopDisableDirective:
|
35
|
-
|
36
|
-
|
37
|
+
Lint/RedundantCopDisableDirective:
|
38
|
+
Exclude:
|
39
|
+
- jekyll_plugin_support.gemspec
|
37
40
|
|
38
|
-
Metrics/AbcSize:
|
39
|
-
|
41
|
+
Metrics/AbcSize:
|
42
|
+
Max: 30
|
40
43
|
|
41
|
-
Metrics/BlockLength:
|
42
|
-
|
43
|
-
|
44
|
+
Metrics/BlockLength:
|
45
|
+
Exclude:
|
46
|
+
- jekyll_plugin_support.gemspec
|
44
47
|
|
45
|
-
Metrics/
|
46
|
-
|
48
|
+
Metrics/CyclomaticComplexity:
|
49
|
+
Max: 20
|
47
50
|
|
48
|
-
|
49
|
-
|
51
|
+
Metrics/MethodLength:
|
52
|
+
Max: 40
|
50
53
|
|
51
|
-
RSpec/
|
52
|
-
|
54
|
+
RSpec/ExampleLength:
|
55
|
+
Max: 20
|
53
56
|
|
54
|
-
|
55
|
-
|
57
|
+
RSpec/MultipleExpectations:
|
58
|
+
Max: 15
|
56
59
|
|
57
|
-
Style/
|
58
|
-
|
60
|
+
Style/Documentation:
|
61
|
+
Enabled: false
|
59
62
|
|
60
|
-
Style/
|
61
|
-
|
63
|
+
Style/FrozenStringLiteralComment:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
Style/TrailingCommaInHashLiteral:
|
67
|
+
EnforcedStyleForMultiline: comma
|
data/ATTIBUTION_NOTES.md
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
# Notes on Attribution
|
2
|
+
|
3
|
+
The following additional public methods could be supported for the attribution string:
|
4
|
+
`full_name`, `conflicts`, `dependencies`, `platform`, `specification_version`, `summary`, `cert_chain`, `description`, `email`, `extensions`, `licenses`, `metadata`, `post_install_message`, `rg_full_gem_path`, `location`, `git_version`, `rg_extension_dir`, `nondevelopment_dependencies`, `default_executable`, `original_platform`, `gems_dir`, `groups`, `requirements`, `bin_file`, `executables`, `bindir`, `loaded_from`, `hash`, `files`, `spec_file`, `abbreviate`, `bin_dir`, `default_value`, `doc_dir`, `mark_version`, `executable`, `file_name`, `rubygems_version`, `lib_files`, `license`, `name_tuple`, `original_name`, `require_path`, `ri_dir`, `spec_dir`, `spec_name`, `source`, `validate_permissions`, `extension_dir`, `full_gem_path`, `remote`, `base_dir`, `gem_dir`, `normalize`, `match_platform`, `plugins`, `source_paths`, `datadir`, `require_paths`, and `this`.
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 0.6.1 / 2023-04-12
|
2
|
+
* Added `CallChain.excerpt_caller` to detect if an excerpt is being generated.
|
3
|
+
|
4
|
+
## 0.6.0 / 2023-04-05
|
5
|
+
* Added attribution support
|
6
|
+
* Renamed `jekyll_plugin_support_helper.rb` to `jekyll_plugin_helper.rb`.
|
7
|
+
* Now returns `undefined` instead of `false'` when `@keys_values.empty?`
|
8
|
+
and parameter is not specified.
|
9
|
+
|
1
10
|
## 0.5.3 / 2023-03-19
|
2
11
|
* Added properties `argv_original`, `keys_values_original`, `remaining_markup_original`,
|
3
12
|
and `params_original`, which are the original values of `argv`, `keys_values`,
|
data/README.md
CHANGED
@@ -5,8 +5,11 @@
|
|
5
5
|
`Jekyll_plugin_support` is a Ruby gem that facilitates writing and testing Jekyll plugins.
|
6
6
|
At present, only Jekyll tags and blocks are supported.
|
7
7
|
|
8
|
+
|
8
9
|
## Installation
|
10
|
+
`Jekyll_plugin_support` can be used to create simple Jekyll plugins in the `_plugins/` directory, or gem-based Jekyll plugins.
|
9
11
|
|
12
|
+
### Simple `_plugins`
|
10
13
|
Add this line to your Jekyll plugin's Gemfile:
|
11
14
|
|
12
15
|
```ruby
|
@@ -19,6 +22,19 @@ And then execute:
|
|
19
22
|
|
20
23
|
$ bundle install
|
21
24
|
|
25
|
+
|
26
|
+
### Gem-Based Plugins
|
27
|
+
Add this line to your Jekyll plugin's `.gemspec`:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
spec.add_dependency 'jekyll_plugin_support'
|
31
|
+
```
|
32
|
+
|
33
|
+
And then execute:
|
34
|
+
|
35
|
+
$ bundle install
|
36
|
+
|
37
|
+
|
22
38
|
## General Usage
|
23
39
|
`JekyllSupport::JekyllBlock` and `JekyllSupport::JekyllTag`
|
24
40
|
provide support for Jekyll tag blocks and Jekyll tags, respectively.
|
@@ -56,7 +72,10 @@ module Jekyll
|
|
56
72
|
VERSION = '0.1.0'.freeze
|
57
73
|
|
58
74
|
def render_impl
|
59
|
-
|
75
|
+
my_output = "<p>blah blah</p>"
|
76
|
+
<<~END_OUTPUT
|
77
|
+
#{my_output}
|
78
|
+
END_OUTPUT
|
60
79
|
end
|
61
80
|
|
62
81
|
JekyllPluginHelper.register(self, 'demo_tag')
|
@@ -72,8 +91,13 @@ module Jekyll
|
|
72
91
|
class MyBlock < JekyllSupport::JekyllBlock
|
73
92
|
VERSION = '0.1.0'.freeze
|
74
93
|
|
75
|
-
def render_impl(
|
76
|
-
#
|
94
|
+
def render_impl(content)
|
95
|
+
@helper.gem_file __FILE__ # Enables attribution
|
96
|
+
my_output = "<p>blah blah</p>"
|
97
|
+
<<~END_OUTPUT
|
98
|
+
#{my_output}
|
99
|
+
#{@helper.attribute if @helper.attribution}
|
100
|
+
END_OUTPUT
|
77
101
|
end
|
78
102
|
|
79
103
|
JekyllPluginHelper.register(self, 'demo_block')
|
@@ -101,7 +125,12 @@ module Jekyll
|
|
101
125
|
include MyPluginVersion
|
102
126
|
|
103
127
|
def render_impl(text)
|
104
|
-
#
|
128
|
+
@helper.gem_file __FILE__ # Enables attribution
|
129
|
+
my_output = "<p>blah blah</p>"
|
130
|
+
<<~END_OUTPUT
|
131
|
+
#{my_output}
|
132
|
+
#{@helper.attribute if @helper.attribution}
|
133
|
+
END_OUTPUT
|
105
134
|
end
|
106
135
|
|
107
136
|
JekyllPluginHelper.register(self, 'demo_tag')
|
@@ -168,9 +197,68 @@ without tokenization, and you expect that the plugin might be invoked with large
|
|
168
197
|
derive your plugin from `JekyllBlockNoArgParsing` or `JekyllTagNoArgParsing`.
|
169
198
|
|
170
199
|
|
200
|
+
## Subclass Attribution
|
201
|
+
`JekyllTag` and `JekyllBlock` subclasses of `jekyll_plugin_support` can utilize the `attribution` option IFF they are published as a gem.
|
202
|
+
`JekyllTagNoArgParsing` and `JekyllBlockNoArgParsing` subclasses cannot.
|
203
|
+
|
204
|
+
- When used as a keyword option, a default value is used for the attribution string.
|
205
|
+
- When used as a name/value option, the attribution string can be specified.
|
206
|
+
|
207
|
+
Using the `attribution` option cause subclasses to replace their usual output with HTML that looks like:
|
208
|
+
|
209
|
+
```html
|
210
|
+
<div id="jps_attribute_12345" class="jps_attribute">
|
211
|
+
<a href="https://github.com/mslinn/jekyll_outline">
|
212
|
+
<b>Generated by <code>jekyll_outline</code>.
|
213
|
+
</a>
|
214
|
+
</div>
|
215
|
+
```
|
216
|
+
|
217
|
+
The `id` attribute is in the sample HTML above is randomized so more than one attribution can appear on a page.
|
218
|
+
|
219
|
+
|
220
|
+
### Usage
|
221
|
+
Typical usage for the `attribution` tag is:
|
222
|
+
|
223
|
+
```
|
224
|
+
{% my_tag attribution %}
|
225
|
+
```
|
226
|
+
|
227
|
+
Normal processing of `my_tag` is augmented by interpolating the attribution format string,
|
228
|
+
which is a Ruby-compatible interpolated string.
|
229
|
+
|
230
|
+
The default attribution format string is:
|
231
|
+
|
232
|
+
```ruby
|
233
|
+
"Generated by the #{name} #{version} Jekyll plugin, written by #{author} #{date}."
|
234
|
+
```
|
235
|
+
|
236
|
+
Because `jekyll_plugin_suppprt` subclasses are `gem`s, their `gemfile`s define values for
|
237
|
+
`name`, `version`, `homepage`, and `authors`, as well as many other properties.
|
238
|
+
The `date` property is obtained from the plugin/gem publishing date.
|
239
|
+
|
240
|
+
An alternative attribution string can be specified properties can be output using any of the above properties:
|
241
|
+
|
242
|
+
```
|
243
|
+
{% my_tag attribution="Generated by the #{name} #{version} Jekyll plugin, written by #{author} #{date}" %}
|
244
|
+
```
|
245
|
+
|
246
|
+
### Attribution Generation
|
247
|
+
You can decide where you want the attribution string for your Jekyll tag to appear by invoking `@helper.attribute`. For example, this is how the [`jekyll_outline` tag](https://github.com/mslinn/jekyll_outline/blob/v1.1.1/lib/outline_tag.rb#L32-L46) generates output:
|
248
|
+
|
249
|
+
```
|
250
|
+
<<~HEREDOC
|
251
|
+
<div class="outer_posts">
|
252
|
+
#{make_entries(collection)&.join("\n")}
|
253
|
+
</div>
|
254
|
+
#{@helper.attribute if @helper.attribution}
|
255
|
+
HEREDOC
|
256
|
+
```
|
257
|
+
|
258
|
+
|
171
259
|
## Additional Information
|
172
260
|
More information is available on
|
173
|
-
[Mike Slinn’s website](https://www.mslinn.com/
|
261
|
+
[Mike Slinn’s website](https://www.mslinn.com/jekyll/10200-jekyll-plugin-support.html).
|
174
262
|
|
175
263
|
|
176
264
|
## Development
|
@@ -204,16 +292,28 @@ jekyll_plugin_support (0.1.0)
|
|
204
292
|
```
|
205
293
|
|
206
294
|
|
207
|
-
##
|
208
|
-
A test website is provided in the `demo` directory.
|
209
|
-
|
295
|
+
## Demo
|
296
|
+
A demo / test website is provided in the `demo` directory.
|
297
|
+
It can be used to debug the plugin or to run freely.
|
298
|
+
|
299
|
+
### Run Freely
|
300
|
+
1. Run from the command line:
|
301
|
+
```shell
|
302
|
+
$ demo/_bin/debug -r
|
303
|
+
```
|
304
|
+
|
305
|
+
2. View the generated website at [`http://localhost:4444`](http://localhost:4444)
|
306
|
+
|
307
|
+
### Plugin Debugging
|
308
|
+
1. Set breakpoints in Visual Studio Code.
|
210
309
|
|
211
310
|
2. Initiate a debug session from the command line:
|
212
311
|
```shell
|
213
|
-
$
|
312
|
+
$ demo/_bin/debug
|
214
313
|
```
|
215
314
|
|
216
|
-
3. Once the `Fast Debugger` signon appears, launch the Visual Studio Code launch
|
315
|
+
3. Once the `Fast Debugger` signon appears, launch the Visual Studio Code launch
|
316
|
+
configuration called `Attach rdebug-ide`.
|
217
317
|
|
218
318
|
4. View the generated website at [`http://localhost:4444`](http://localhost:4444)
|
219
319
|
|
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
|
7
7
|
spec.authors = ['Mike Slinn']
|
8
8
|
spec.email = ['mslinn@mslinn.com']
|
9
9
|
spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
|
10
|
-
spec.homepage = 'https://www.mslinn.com/
|
10
|
+
spec.homepage = 'https://www.mslinn.com/jekyll/10200-jekyll-plugin-support.html'
|
11
11
|
spec.license = 'MIT'
|
12
12
|
spec.metadata = {
|
13
13
|
'allowed_push_host' => 'https://rubygems.org',
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
|
28
28
|
spec.test_files = spec.files.grep %r{^(test|spec|features)/}
|
29
29
|
spec.version = JekyllPluginSupportVersion::VERSION
|
30
30
|
|
31
|
+
spec.add_dependency 'facets'
|
31
32
|
spec.add_dependency 'jekyll', '>= 3.5.0'
|
32
33
|
spec.add_dependency 'jekyll_plugin_logger'
|
33
34
|
spec.add_dependency 'key-value-parser'
|
data/lib/call_chain.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# TODO: File not used, delete
|
2
|
+
|
3
|
+
# See https://stackoverflow.com/a/23363883/553865
|
4
|
+
module CallChain
|
5
|
+
ACaller = Struct.new(:filepath, :line, :method_name)
|
6
|
+
|
7
|
+
def self.caller_method(depth = 1)
|
8
|
+
parse_caller(caller(depth + 1).first).method_name
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.parse_caller(at)
|
12
|
+
return unless /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
|
13
|
+
|
14
|
+
last_match = Regexp.last_match.to_a
|
15
|
+
ACaller.new(
|
16
|
+
last_match[1],
|
17
|
+
last_match[2].to_i,
|
18
|
+
last_match[3]
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.excerpt_caller
|
23
|
+
call_sequence = caller
|
24
|
+
call_sequence.each do |caller_|
|
25
|
+
parsed_caller = parse_caller caller_
|
26
|
+
filepath = parsed_caller.filepath
|
27
|
+
excerpt = filepath.match? %r{jekyll[.0-9-]*/lib/jekyll/excerpt.rb\z}
|
28
|
+
puts "excerpt matched #{filepath}" if excerpt
|
29
|
+
return true if excerpt
|
30
|
+
end
|
31
|
+
false
|
32
|
+
end
|
33
|
+
|
34
|
+
# Return ACaller prior to jekyll_plugin_support
|
35
|
+
def self.jpsh_subclass_caller
|
36
|
+
state = :nothing_found
|
37
|
+
call_sequence = caller
|
38
|
+
call_sequence.each do |caller_|
|
39
|
+
parsed_caller = parse_caller caller_
|
40
|
+
filepath = parsed_caller.filepath
|
41
|
+
dirname = File.dirname filepath
|
42
|
+
jpsh = dirname.match? %r{jekyll_plugin_support[.0-9-]*/lib\z}
|
43
|
+
liquid = dirname.match? %r{liquid[.0-9-]*/lib/\z}
|
44
|
+
case state
|
45
|
+
when :nothing_found
|
46
|
+
state = :jpsh_found if jpsh
|
47
|
+
when :jpsh_found
|
48
|
+
# puts "Called from #{parsed_caller.filepath}, on line #{parsed_caller.line}, by method '#{parsed_caller.method_name}'" unless jpsh
|
49
|
+
return parsed_caller unless jpsh || liquid
|
50
|
+
end
|
51
|
+
end
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
end
|
data/lib/gem_support.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# See https://stackoverflow.com/a/75890279/553865
|
2
|
+
module GemSupport
|
3
|
+
# @param file must be a fully qualified file name that points to a file within a gem.
|
4
|
+
# @return Gem::Specification of gem that file points into, or nil if not called from a gem
|
5
|
+
def self.current_spec(file)
|
6
|
+
abort 'GemSupport::current_spec: file is nil' if file.nil?
|
7
|
+
return nil unless File.exist?(file)
|
8
|
+
|
9
|
+
searcher = if Gem::Specification.respond_to?(:find)
|
10
|
+
Gem::Specification
|
11
|
+
elsif Gem.respond_to?(:searcher)
|
12
|
+
Gem.searcher.init_gemspecs
|
13
|
+
end
|
14
|
+
|
15
|
+
searcher&.find do |spec|
|
16
|
+
file.start_with? spec.full_gem_path
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,11 +1,13 @@
|
|
1
|
-
require '
|
1
|
+
require 'facets/string/interpolate'
|
2
2
|
require 'key_value_parser'
|
3
|
+
require 'shellwords'
|
4
|
+
require_relative 'gem_support'
|
3
5
|
|
4
6
|
# Base class for all types of Jekyll plugin helpers
|
5
7
|
class JekyllPluginHelper # rubocop:disable Metrics/ClassLength
|
6
8
|
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
|
9
|
+
attr_reader :argv, :attribution, :keys_values, :logger, :markup, :no_arg_parsing, :params, :tag_name,
|
10
|
+
:argv_original, :excerpt_caller, :keys_values_original, :params_original, :jpsh_subclass_caller
|
9
11
|
|
10
12
|
# Expand an environment variable reference
|
11
13
|
def self.expand_env(str, die_if_undefined: false)
|
@@ -26,7 +28,7 @@ class JekyllPluginHelper # rubocop:disable Metrics/ClassLength
|
|
26
28
|
|
27
29
|
abort("Error: The #{name} plugin is not an instance of JekyllSupport::JekyllBlock or JekyllSupport::JekyllTag") \
|
28
30
|
unless klass.instance_of?(Class) &&
|
29
|
-
(klass.ancestors.include?(JekyllSupport::JekyllBlock) ||
|
31
|
+
(klass.ancestors.include?(JekyllSupport::JekyllBlock) ||
|
30
32
|
klass.ancestors.include?(JekyllSupport::JekyllTag))
|
31
33
|
|
32
34
|
Liquid::Template.register_tag(name, klass)
|
@@ -52,17 +54,52 @@ class JekyllPluginHelper # rubocop:disable Metrics/ClassLength
|
|
52
54
|
@logger = logger
|
53
55
|
@no_arg_parsing = no_arg_parsing
|
54
56
|
reinitialize(markup.strip)
|
57
|
+
|
58
|
+
@attribution = parameter_specified?('attribution') || false unless no_arg_parsing
|
55
59
|
@logger.debug { "@keys_values='#{@keys_values}'" }
|
60
|
+
rescue StandardError => e
|
61
|
+
@logger.error { "#{self.class} died with a #{e.full_message}" }
|
62
|
+
end
|
63
|
+
|
64
|
+
def attribute
|
65
|
+
return unless @current_gem
|
66
|
+
|
67
|
+
<<~END_OUTPUT
|
68
|
+
<div id="jps_attribute_#{rand(999_999)}" class="jps_attribute">
|
69
|
+
<div>
|
70
|
+
<a href="#{@homepage}" target="_blank" rel="nofollow">
|
71
|
+
#{attribution_string}
|
72
|
+
</a>
|
73
|
+
</div>
|
74
|
+
</div>
|
75
|
+
END_OUTPUT
|
76
|
+
end
|
77
|
+
|
78
|
+
def default_attribution
|
79
|
+
authors = @authors&.join(', ')
|
80
|
+
result = "Generated by the \#{@name} v\#{@version} Jekyll plugin"
|
81
|
+
result << ", written by #{authors}" if authors
|
82
|
+
result << " \#{@published_date}" if @published_date
|
83
|
+
result << '.'
|
84
|
+
result
|
85
|
+
end
|
86
|
+
|
87
|
+
# Sets @current_gem if file points at a uniquely named file within a gem.
|
88
|
+
# @param file must be a fully qualified file name in a gem, for example: __FILE__
|
89
|
+
def gem_file(file)
|
90
|
+
@current_gem = GemSupport.current_spec file
|
91
|
+
@logger.debug "No gem found for '#{file} was found." unless @current_gem
|
92
|
+
annotate_globals if @attribution && @current_gem
|
56
93
|
end
|
57
94
|
|
58
|
-
# @return if parameter was specified, removes it from the available tokens and returns value
|
59
|
-
def parameter_specified?(name)
|
60
|
-
return
|
95
|
+
# @return undefined if parameter was specified, removes it from the available tokens and returns value
|
96
|
+
def parameter_specified?(name, delete_param: true)
|
97
|
+
return if @keys_values.empty?
|
61
98
|
|
62
99
|
key = name
|
63
100
|
key = name.to_sym if @keys_values.first.first.instance_of?(Symbol)
|
64
101
|
value = @keys_values[key]
|
65
|
-
delete_parameter(name)
|
102
|
+
delete_parameter(name) if delete_param
|
66
103
|
value
|
67
104
|
end
|
68
105
|
|
@@ -99,6 +136,26 @@ class JekyllPluginHelper # rubocop:disable Metrics/ClassLength
|
|
99
136
|
|
100
137
|
private
|
101
138
|
|
139
|
+
def attribution_string
|
140
|
+
string = if @attribution == true
|
141
|
+
default_attribution
|
142
|
+
else
|
143
|
+
@attribution
|
144
|
+
end
|
145
|
+
puts { "Interpolationg #{string}" }
|
146
|
+
String.interpolate { string }
|
147
|
+
end
|
148
|
+
|
149
|
+
def annotate_globals
|
150
|
+
return unless @current_gem
|
151
|
+
|
152
|
+
@name = @current_gem.name
|
153
|
+
@authors = @current_gem.authors
|
154
|
+
@homepage = @current_gem.homepage
|
155
|
+
@published_date = @current_gem.date.to_date.to_s
|
156
|
+
@version = @current_gem.version
|
157
|
+
end
|
158
|
+
|
102
159
|
def delete_parameter(key)
|
103
160
|
return if @keys_values.empty? || @params.nil?
|
104
161
|
|
@@ -145,17 +202,24 @@ class JekyllPluginHelper # rubocop:disable Metrics/ClassLength
|
|
145
202
|
@liquid_context.registers[:page]
|
146
203
|
end
|
147
204
|
|
205
|
+
# rubocop:disable Style/IfUnlessModifier
|
148
206
|
def parse(markup)
|
149
207
|
@argv_original = Shellwords.split(markup)
|
150
|
-
@keys_values_original = KeyValueParser
|
151
|
-
.new({}, { array_values: false, normalize_keys: false, separator: /=/ })
|
208
|
+
@keys_values_original = KeyValueParser
|
209
|
+
.new({}, { array_values: false, normalize_keys: false, separator: /=/ })
|
152
210
|
.parse(@argv_original)
|
153
|
-
|
211
|
+
unless respond_to?(:no_arg_parsing) && no_arg_parsing
|
212
|
+
@params_original = @keys_values_original.map { |k, _v| lookup_variable(k) }
|
213
|
+
end
|
154
214
|
|
155
215
|
@argv = Shellwords.split(self.class.expand_env(markup))
|
156
|
-
@keys_values = KeyValueParser
|
157
|
-
.new({}, { array_values: false, normalize_keys: false, separator: /=/ })
|
216
|
+
@keys_values = KeyValueParser
|
217
|
+
.new({}, { array_values: false, normalize_keys: false, separator: /=/ })
|
158
218
|
.parse(@argv)
|
159
|
-
|
219
|
+
|
220
|
+
return if respond_to?(:no_arg_parsing) && no_arg_parsing
|
221
|
+
|
222
|
+
@params = @keys_values.map { |k, _v| lookup_variable(k) }
|
160
223
|
end
|
224
|
+
# rubocop:enable Style/IfUnlessModifier
|
161
225
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'jekyll'
|
2
2
|
require 'jekyll_plugin_logger'
|
3
|
-
require_relative '
|
3
|
+
require_relative 'jekyll_plugin_helper'
|
4
4
|
require_relative 'jekyll_plugin_support/version'
|
5
5
|
|
6
6
|
# @author Copyright 2022 Michael Slinn
|
@@ -31,7 +31,7 @@ module JekyllSupport
|
|
31
31
|
@argument_string = argument_string
|
32
32
|
@logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
33
33
|
@logger.debug { "#{self.class}: respond_to?(:no_arg_parsing) #{respond_to?(:no_arg_parsing) ? 'yes' : 'no'}." }
|
34
|
-
@helper = JekyllPluginHelper.new
|
34
|
+
@helper = JekyllPluginHelper.new tag_name, argument_string, @logger, respond_to?(:no_arg_parsing)
|
35
35
|
end
|
36
36
|
|
37
37
|
# Method prescribed by the Jekyll plugin lifecycle.
|
@@ -47,6 +47,11 @@ module JekyllSupport
|
|
47
47
|
@mode = @config['env']['JEKYLL_ENV'] || 'development'
|
48
48
|
|
49
49
|
render_impl text
|
50
|
+
rescue StandardError => e
|
51
|
+
@logger.error { "#{self.class} died with a #{e.full_message}" }
|
52
|
+
# raise SystemExit, 3, []
|
53
|
+
e.set_backtrace []
|
54
|
+
raise e
|
50
55
|
end
|
51
56
|
|
52
57
|
# Jekyll plugins should override this method, not render, so their plugin can be tested more easily
|
@@ -65,6 +70,9 @@ module JekyllSupport
|
|
65
70
|
|
66
71
|
super
|
67
72
|
@logger.debug { "#{self.class}: respond_to?(:o_arg_parsing) #{respond_to?(:no_arg_parsing) ? 'yes' : 'no'}." }
|
73
|
+
rescue StandardError => e
|
74
|
+
@logger.error { "#{self.class} died with a #{e.full_message}" }
|
75
|
+
exit 2
|
68
76
|
end
|
69
77
|
end
|
70
78
|
|
@@ -92,6 +100,8 @@ module JekyllSupport
|
|
92
100
|
|
93
101
|
# Method prescribed by the Jekyll plugin lifecycle.
|
94
102
|
def render(liquid_context)
|
103
|
+
return if @helper.excerpt_caller
|
104
|
+
|
95
105
|
@helper.liquid_context = liquid_context
|
96
106
|
|
97
107
|
@envs = liquid_context.environments.first
|
@@ -107,6 +117,9 @@ module JekyllSupport
|
|
107
117
|
@mode = @config['env']['JEKYLL_ENV'] || 'development'
|
108
118
|
|
109
119
|
render_impl
|
120
|
+
rescue StandardError => e
|
121
|
+
@logger.error { "#{self.class} died with a #{e.full_message}" }
|
122
|
+
exit 3
|
110
123
|
end
|
111
124
|
|
112
125
|
# Jekyll plugins must override this method, not render, so their plugin can be tested more easily
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'jekyll_plugin_logger'
|
2
|
+
require 'rspec/match_ignoring_whitespace'
|
3
|
+
require_relative '../lib/jekyll_plugin_support'
|
4
|
+
require_relative '../lib/jekyll_plugin_support_spec_support'
|
5
|
+
|
6
|
+
class JekyllPluginHelperCallTest
|
7
|
+
RSpec.describe JekyllPluginHelper do
|
8
|
+
it 'might not return jpsh_subclass_caller value' do
|
9
|
+
jpsh_subclass_caller = CallChain.jpsh_subclass_caller
|
10
|
+
expect(jpsh_subclass_caller).to be_nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'asf' do
|
14
|
+
logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
15
|
+
jph = described_class.new('my_tag', 'attribution', logger, false)
|
16
|
+
actual = jph.jpsh_subclass_caller
|
17
|
+
expected = [__FILE__, 15, 'new'] # The 2nd element value depends on the line # of two lines up
|
18
|
+
expect(actual).to match_array(expected)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -3,7 +3,7 @@ require 'rspec/match_ignoring_whitespace'
|
|
3
3
|
require_relative '../lib/jekyll_plugin_support'
|
4
4
|
require_relative '../lib/jekyll_plugin_support_spec_support'
|
5
5
|
|
6
|
-
class
|
6
|
+
class JekyllPluginHelperOptionsTest
|
7
7
|
RSpec.describe JekyllPluginHelper do
|
8
8
|
logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
9
9
|
|
data/spec/status_persistence.txt
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
example_id
|
2
|
-
|
3
|
-
/mnt/_/work/jekyll/my_plugins/jekyll_plugin_support/spec/
|
4
|
-
/mnt/_/work/jekyll/my_plugins/jekyll_plugin_support/spec/
|
5
|
-
/mnt/_/work/jekyll/my_plugins/jekyll_plugin_support/spec/jekyll_block_plugin_support_spec.rb[1:3] | passed | 0.00337 seconds |
|
6
|
-
/mnt/_/work/jekyll/my_plugins/jekyll_plugin_support/spec/jekyll_block_plugin_support_spec.rb[1:4] | passed | 0.00026 seconds |
|
1
|
+
example_id | status | run_time |
|
2
|
+
----------------------------------------------------------------------------------------------- | ------ | --------------- |
|
3
|
+
/mnt/_/work/jekyll/my_plugins/jekyll_plugin_support/spec/jekyll_plugin_helper_call_spec.rb[1:1] | passed | 0.00436 seconds |
|
4
|
+
/mnt/_/work/jekyll/my_plugins/jekyll_plugin_support/spec/jekyll_plugin_helper_call_spec.rb[1:2] | passed | 0.00476 seconds |
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll_plugin_support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.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-
|
11
|
+
date: 2023-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: facets
|
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
|
@@ -60,26 +74,30 @@ extensions: []
|
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
62
76
|
- ".rubocop.yml"
|
77
|
+
- ATTIBUTION_NOTES.md
|
63
78
|
- CHANGELOG.md
|
64
79
|
- LICENSE.txt
|
65
80
|
- README.md
|
66
81
|
- Rakefile
|
67
82
|
- jekyll_plugin_support.gemspec
|
83
|
+
- lib/call_chain.rb
|
84
|
+
- lib/gem_support.rb
|
85
|
+
- lib/jekyll_plugin_helper.rb
|
68
86
|
- lib/jekyll_plugin_support.rb
|
69
87
|
- lib/jekyll_plugin_support/version.rb
|
70
|
-
- lib/jekyll_plugin_support_helper.rb
|
71
88
|
- lib/jekyll_plugin_support_spec_support.rb
|
72
|
-
- spec/
|
89
|
+
- spec/jekyll_plugin_helper_call_spec.rb
|
90
|
+
- spec/jekyll_plugin_helper_options_spec.rb
|
73
91
|
- spec/spec_helper.rb
|
74
92
|
- spec/status_persistence.txt
|
75
|
-
homepage: https://www.mslinn.com/
|
93
|
+
homepage: https://www.mslinn.com/jekyll/10200-jekyll-plugin-support.html
|
76
94
|
licenses:
|
77
95
|
- MIT
|
78
96
|
metadata:
|
79
97
|
allowed_push_host: https://rubygems.org
|
80
98
|
bug_tracker_uri: https://github.com/mslinn/jekyll_plugin_support/issues
|
81
99
|
changelog_uri: https://github.com/mslinn/jekyll_plugin_support/CHANGELOG.md
|
82
|
-
homepage_uri: https://www.mslinn.com/
|
100
|
+
homepage_uri: https://www.mslinn.com/jekyll/10200-jekyll-plugin-support.html
|
83
101
|
source_code_uri: https://github.com/mslinn/jekyll_plugin_support
|
84
102
|
post_install_message: |2+
|
85
103
|
|
@@ -104,7 +122,8 @@ signing_key:
|
|
104
122
|
specification_version: 4
|
105
123
|
summary: Provides support for writing Jekyll plugins.
|
106
124
|
test_files:
|
107
|
-
- spec/
|
125
|
+
- spec/jekyll_plugin_helper_call_spec.rb
|
126
|
+
- spec/jekyll_plugin_helper_options_spec.rb
|
108
127
|
- spec/spec_helper.rb
|
109
128
|
- spec/status_persistence.txt
|
110
129
|
...
|