jekyll_plugin_support 0.2.0 → 0.3.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 +3 -0
- data/CHANGELOG.md +8 -2
- data/README.md +58 -3
- data/Rakefile +0 -2
- data/jekyll_plugin_support.gemspec +0 -4
- data/lib/jekyll_plugin_support/version.rb +1 -3
- data/lib/jekyll_plugin_support.rb +40 -3
- data/lib/jekyll_plugin_support_spec_support.rb +0 -2
- data/spec/{jekyll_plugin_support_spec.rb → jekyll_block_plugin_support_spec.rb} +0 -2
- data/spec/jekyll_tag_plugin_support_spec.rb +41 -0
- data/spec/spec_helper.rb +0 -2
- metadata +6 -6
- data/spec/status_persistence.txt +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 978c34638bfb0bae5b74952bb29d48dd15a8afe491406239fb05050efc78e5c2
|
4
|
+
data.tar.gz: fc570654d04aa4abdd8ed28fc551314fe36c0fb35ee1a14ce3ba98682298b084
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1d27d2008c53695c6c2a2fa85b6519bf4f95a6106a84e7ff9ffd45b3f68187159d1a88cff4c4a3c9911b8c16f28c87f33696d41b75ddbf03c07ca6f7121ee0e
|
7
|
+
data.tar.gz: a4729e61ca106f2f5ee8ead49771dde0a08bd55ea96e254c4fe5efd1f49a8fe82f964eb68322cedadf7061f94a982626c686ef3d5ce22914a6761a03453e1f1a
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
-
## 0.1
|
2
|
-
*
|
1
|
+
## 0.3.1 / 2023-02-07
|
2
|
+
* `JekyllBlock.render_impl` and `JekyllTag.render_impl` now define `@page` and `@site`.
|
3
|
+
|
4
|
+
## 0.3.0 / 2023-01-14
|
5
|
+
* Added support for tags, which should subclass JekyllSupport::JekyllTag
|
3
6
|
|
4
7
|
## 0.2.0 / 2023-01-12
|
5
8
|
* Refactored
|
9
|
+
|
10
|
+
## 0.1.0 / 2023-01-10
|
11
|
+
* Initial version; only supports Jekyll block tags
|
data/README.md
CHANGED
@@ -2,21 +2,76 @@
|
|
2
2
|
[](https://badge.fury.io/rb/jekyll_plugin_support)
|
3
3
|
===========
|
4
4
|
|
5
|
-
`
|
6
|
-
At present only Jekyll
|
5
|
+
`Jekyll_plugin_support` is a Ruby gem that facilitates writing and testing Jekyll plugins.
|
6
|
+
At present, only Jekyll tags and blocks are supported.
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
10
10
|
Add this line to your Jekyll plugin's Gemfile:
|
11
11
|
|
12
12
|
```ruby
|
13
|
-
|
13
|
+
group :jekyll_plugins do
|
14
|
+
gem 'jekyll_plugin_support'
|
15
|
+
end
|
14
16
|
```
|
15
17
|
|
16
18
|
And then execute:
|
17
19
|
|
18
20
|
$ bundle install
|
19
21
|
|
22
|
+
## Usage
|
23
|
+
`JekyllSupport::JekyllBlock` and `JekyllSupport::JekyllTag`
|
24
|
+
provide support for Jekyll tag blocks and Jekyll tags, respectively.
|
25
|
+
They are very similar in construction and usage.
|
26
|
+
|
27
|
+
Instead of subclassing your Jekyll block tag class from `Liquid::Block`,
|
28
|
+
subclass from `JekyllSupport::JekyllBlock` instead.
|
29
|
+
Similarly, instead of subclassing your Jekyll tag class from `Liquid::Tag`,
|
30
|
+
subclass from `JekyllSupport::JekyllTag` instead.
|
31
|
+
|
32
|
+
Both `JekyllSupport` classes instantiate new instances of
|
33
|
+
[`PluginMetaLogger`](https://github.com/mslinn/jekyll_plugin_logger) (called `@logger`) and
|
34
|
+
[`JekyllPluginHelper`](lib/jekyll_plugin_support_helper.rb) (called `@helper`).
|
35
|
+
|
36
|
+
`JekyllPluginHelper` defines a generic `initialize` method,
|
37
|
+
and your tag or block tag class should not override it.
|
38
|
+
Also, your tag or block tag class should not define a method called `render`,
|
39
|
+
because `JekyllBlock.initialize` defines one, which creates variables called
|
40
|
+
[`@page`](https://jekyllrb.com/docs/variables/#page-variables) and
|
41
|
+
[`@site`](https://jekyllrb.com/docs/variables/#site-variables).
|
42
|
+
|
43
|
+
Instead, define a method called `render_impl`.
|
44
|
+
For tags, `render_impl` does not accept any parameters.
|
45
|
+
For block tags, a single parameter is required, which contains any text enclosed within your block.
|
46
|
+
|
47
|
+
Your implementation of `render_impl` can access `@page` and `@site`,
|
48
|
+
and can parse parameters passed to the tag / block tag, [as described here](https://mslinn.com/jekyll/10100-jekyll-plugin-background.html#params):
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
# For a tag:
|
52
|
+
module Jekyll
|
53
|
+
class Quote < JekyllSupport::JekyllTag
|
54
|
+
def render_impl
|
55
|
+
site_data = @site.data
|
56
|
+
@break = @helper.parameter_specified? 'break'
|
57
|
+
# ...
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
# For a tag block:
|
65
|
+
module Jekyll
|
66
|
+
class Quote < JekyllSupport::JekyllBlock
|
67
|
+
def render_impl(text)
|
68
|
+
site_url = @site.url
|
69
|
+
@break = @helper.parameter_specified? 'break'
|
70
|
+
# ...
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
```
|
20
75
|
|
21
76
|
## Additional Information
|
22
77
|
More information is available on
|
data/Rakefile
CHANGED
@@ -1,8 +1,5 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require_relative 'lib/jekyll_plugin_support/version'
|
4
2
|
|
5
|
-
# rubocop:disable Metrics/BlockLength
|
6
3
|
Gem::Specification.new do |spec|
|
7
4
|
github = 'https://github.com/mslinn/jekyll_plugin_support'
|
8
5
|
|
@@ -47,4 +44,3 @@ Gem::Specification.new do |spec|
|
|
47
44
|
spec.add_development_dependency 'rubocop-rspec'
|
48
45
|
spec.add_development_dependency 'ruby-debug-ide'
|
49
46
|
end
|
50
|
-
# rubocop:enable Metrics/BlockLength
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require 'jekyll'
|
4
2
|
require 'jekyll_plugin_logger'
|
5
3
|
require_relative 'jekyll_plugin_support_helper'
|
@@ -23,6 +21,7 @@ module JekyllSupport
|
|
23
21
|
# @return [void]
|
24
22
|
def initialize(tag_name, argument_string, parse_context)
|
25
23
|
super
|
24
|
+
@tag_name = tag_name
|
26
25
|
@logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
27
26
|
@helper = JekyllPluginHelper.new(tag_name, argument_string, @logger)
|
28
27
|
@argument_string = argument_string
|
@@ -30,15 +29,53 @@ module JekyllSupport
|
|
30
29
|
|
31
30
|
# Method prescribed by the Jekyll plugin lifecycle.
|
32
31
|
# @return [String]
|
33
|
-
def render(
|
32
|
+
def render(liquid_context)
|
34
33
|
text = super
|
34
|
+
@page = liquid_context.registers[:page]
|
35
|
+
@site = liquid_context.registers[:site]
|
35
36
|
render_impl text
|
36
37
|
end
|
37
38
|
|
38
39
|
# Jekyll plugins should override this method, not render, so their plugin can be tested more easily
|
40
|
+
# @page and @site are available
|
39
41
|
# @return [String]
|
40
42
|
def render_impl(text)
|
41
43
|
text
|
42
44
|
end
|
43
45
|
end
|
46
|
+
|
47
|
+
# Base class for Jekyll tags
|
48
|
+
class JekyllTag < Liquid::Tag
|
49
|
+
attr_reader :argument_string, :helper, :line_number, :logger, :page, :site
|
50
|
+
|
51
|
+
# See https://github.com/Shopify/liquid/wiki/Liquid-for-Programmers#create-your-own-tags
|
52
|
+
# @param tag_name [String] the name of the tag, which we usually know.
|
53
|
+
# @param argument_string [String] the arguments passed to the tag, as a single string.
|
54
|
+
# @param parse_context [Liquid::ParseContext] hash that stores Liquid options.
|
55
|
+
# By default it has two keys: :locale and :line_numbers, the first is a Liquid::I18n object, and the second,
|
56
|
+
# a boolean parameter that determines if error messages should display the line number the error occurred.
|
57
|
+
# This argument is used mostly to display localized error messages on Liquid built-in Tags and Filters.
|
58
|
+
# See https://github.com/Shopify/liquid/wiki/Liquid-for-Programmers#create-your-own-tags
|
59
|
+
# @return [void]
|
60
|
+
def initialize(tag_name, argument_string, parse_context)
|
61
|
+
super
|
62
|
+
@tag_name = tag_name
|
63
|
+
@logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
64
|
+
@helper = JekyllPluginHelper.new(tag_name, argument_string, @logger)
|
65
|
+
@argument_string = argument_string
|
66
|
+
end
|
67
|
+
|
68
|
+
# Method prescribed by the Jekyll plugin lifecycle.
|
69
|
+
def render(liquid_context)
|
70
|
+
@page = liquid_context.registers[:page]
|
71
|
+
@site = liquid_context.registers[:site]
|
72
|
+
render_impl
|
73
|
+
end
|
74
|
+
|
75
|
+
# Jekyll plugins must override this method, not render, so their plugin can be tested more easily
|
76
|
+
# @page and @site are available
|
77
|
+
def render_impl
|
78
|
+
abort "JekyllTag render_impl for tag #{@tag_name} must be overridden, but it was not."
|
79
|
+
end
|
80
|
+
end
|
44
81
|
end
|
@@ -0,0 +1,41 @@
|
|
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
|
+
# Lets get this party started
|
7
|
+
class MyTest
|
8
|
+
RSpec.describe JekyllSupport::JekyllTag do
|
9
|
+
let(:logger) do
|
10
|
+
PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:parse_context) { TestParseContext.new }
|
14
|
+
|
15
|
+
# Example for plugin authors to refer to:
|
16
|
+
#
|
17
|
+
# let(:helper) do
|
18
|
+
# JekyllTagHelper.new(
|
19
|
+
# 'quote',
|
20
|
+
# "cite='This is a citation' url='https://blah.com' This is the quoted text.",
|
21
|
+
# logger
|
22
|
+
# )
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# fit 'is created properly' do
|
26
|
+
# command_line = "cite='This is a citation' url='https://blah.com' This is the quoted text.".dup
|
27
|
+
# quote = Jekyll::Quote.send(
|
28
|
+
# :new,
|
29
|
+
# 'quote',
|
30
|
+
# command_line,
|
31
|
+
# parse_context
|
32
|
+
# )
|
33
|
+
# result = quote.send(:render_impl, command_line)
|
34
|
+
# expect(result).to match_ignoring_whitespace <<-END_RESULT
|
35
|
+
# <div class='quote'>
|
36
|
+
# This is the quoted text.
|
37
|
+
# </div>
|
38
|
+
# END_RESULT
|
39
|
+
# end
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 0.3.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-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -139,9 +139,9 @@ files:
|
|
139
139
|
- lib/jekyll_plugin_support/version.rb
|
140
140
|
- lib/jekyll_plugin_support_helper.rb
|
141
141
|
- lib/jekyll_plugin_support_spec_support.rb
|
142
|
-
- spec/
|
142
|
+
- spec/jekyll_block_plugin_support_spec.rb
|
143
|
+
- spec/jekyll_tag_plugin_support_spec.rb
|
143
144
|
- spec/spec_helper.rb
|
144
|
-
- spec/status_persistence.txt
|
145
145
|
homepage: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#quote
|
146
146
|
licenses:
|
147
147
|
- MIT
|
@@ -174,7 +174,7 @@ signing_key:
|
|
174
174
|
specification_version: 4
|
175
175
|
summary: Provides support for writing Jekyll plugins.
|
176
176
|
test_files:
|
177
|
-
- spec/
|
177
|
+
- spec/jekyll_block_plugin_support_spec.rb
|
178
|
+
- spec/jekyll_tag_plugin_support_spec.rb
|
178
179
|
- spec/spec_helper.rb
|
179
|
-
- spec/status_persistence.txt
|
180
180
|
...
|
data/spec/status_persistence.txt
DELETED
File without changes
|