jekyll_plugin_support 0.3.0 → 0.4.0

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: 1a564d99fd3a1f1ec146bc48a9ad2afbb77c9d35b3af011930e36618c29e15b4
4
- data.tar.gz: 4888e9972bfad0307f2391079f5a815ea4ffc2588d570738362b310220be2a73
3
+ metadata.gz: 5704c55f7166173f403cb54d03524eec33e0180fdb1f1ef4e3fe7f3d928d1c42
4
+ data.tar.gz: bac72f2f2a1e579256482b6e9e2c5583c8de1fc9c570d95e862b4ca0620a69d2
5
5
  SHA512:
6
- metadata.gz: 485072f986cb15a89b0b70070b992b73e16e35bdea8003e82a770fed2918ab21f70470314beb65ca4b08343db5b41fd9237a99e686d06d1619d13502ed1e9f49
7
- data.tar.gz: '0780bed92c05b1351cb67a9859e7d25c0f96c57d9cd7a3ee1b5f9e6678dde11ef72f7e4b0623f1d5143d9905a357e252fa641e38fbea1d147e0399cf38051bae'
6
+ metadata.gz: 6023e3b8096284d039794a90be4669181f583a25fb3f5507b35cf8458ed84fd1ce17d538ce7c513b3729fa4eff06da8f5360a6c444d8678826cbbd35ab1cd0a4
7
+ data.tar.gz: 637ec49f7e0438c88acfc6ed042fd921a0cda96a986b99c3b9dfe8f9b520056af7235f8085ac1115fa092150bd6e8cd9641eb8beb50cdf00f114609306ef9a06
data/.rubocop.yml CHANGED
@@ -14,3 +14,6 @@ Layout/LineLength:
14
14
 
15
15
  Layout/MultilineMethodCallIndentation:
16
16
  Enabled: false
17
+
18
+ Style/FrozenStringLiteralComment:
19
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,8 +1,18 @@
1
- ## 0.1.0 / 2023-01-10
2
- * Initial version; only supports Jekyll block tags
1
+ ## 0.4.0 / 2023-02-12
2
+ * `render_impl` for tags and blocks now predefines more instance variables:
3
+ - `@liquid_context` – passed to `render`
4
+ - `@config` Jekyll configuration
5
+ - `@envs` Environment variables
6
+ - `@mode` ('development', 'test' or 'production')
3
7
 
4
- ## 0.2.0 / 2023-01-12
5
- * Refactored
8
+ ## 0.3.1 / 2023-02-07
9
+ * `JekyllBlock.render_impl` and `JekyllTag.render_impl` now define `@page` and `@site`.
6
10
 
7
11
  ## 0.3.0 / 2023-01-14
8
12
  * Added support for tags, which should subclass JekyllSupport::JekyllTag
13
+
14
+ ## 0.2.0 / 2023-01-12
15
+ * Refactored
16
+
17
+ ## 0.1.0 / 2023-01-10
18
+ * Initial version; only supports Jekyll block tags
data/README.md CHANGED
@@ -10,13 +10,68 @@ At present, only Jekyll tags and blocks are supported.
10
10
  Add this line to your Jekyll plugin's Gemfile:
11
11
 
12
12
  ```ruby
13
- gem 'jekyll_plugin_support'
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
@@ -1,3 +1,3 @@
1
1
  module JekyllQuoteVersion
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'.freeze
3
3
  end
@@ -29,19 +29,28 @@ module JekyllSupport
29
29
 
30
30
  # Method prescribed by the Jekyll plugin lifecycle.
31
31
  # @return [String]
32
- def render(context)
32
+ def render(liquid_context)
33
33
  text = super
34
+ @liquid_context = liquid_context
35
+
36
+ # The names of front matter variables are hash keys for @page
37
+ @page = liquid_context.registers[:page] # Jekyll::Drops::DocumentDrop
38
+ @site = liquid_context.registers[:site]
39
+ @config = @site.config
40
+ @envs = liquid_context.environments.first
41
+ @mode = @config['env']['JEKYLL_ENV'] || 'development'
42
+
34
43
  render_impl text
35
44
  end
36
45
 
37
46
  # Jekyll plugins should override this method, not render, so their plugin can be tested more easily
47
+ # @page and @site are available
38
48
  # @return [String]
39
49
  def render_impl(text)
40
50
  text
41
51
  end
42
52
  end
43
53
 
44
-
45
54
  # Base class for Jekyll tags
46
55
  class JekyllTag < Liquid::Tag
47
56
  attr_reader :argument_string, :helper, :line_number, :logger, :page, :site
@@ -64,11 +73,18 @@ module JekyllSupport
64
73
  end
65
74
 
66
75
  # Method prescribed by the Jekyll plugin lifecycle.
67
- def render(context)
76
+ def render(liquid_context)
77
+ @liquid_context = liquid_context
78
+ @page = liquid_context.registers[:page]
79
+ @site = liquid_context.registers[:site]
80
+ @config = @site.config
81
+ @envs = liquid_context.environments.first
82
+ @mode = @config['env']['JEKYLL_ENV'] || 'development'
68
83
  render_impl
69
84
  end
70
85
 
71
86
  # Jekyll plugins must override this method, not render, so their plugin can be tested more easily
87
+ # @page and @site are available
72
88
  def render_impl
73
89
  abort "JekyllTag render_impl for tag #{@tag_name} must be overridden, but it was not."
74
90
  end
File without changes
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.3.0
4
+ version: 0.4.0
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-01-16 00:00:00.000000000 Z
11
+ date: 2023-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -142,6 +142,7 @@ files:
142
142
  - spec/jekyll_block_plugin_support_spec.rb
143
143
  - spec/jekyll_tag_plugin_support_spec.rb
144
144
  - spec/spec_helper.rb
145
+ - spec/status_persistence.txt
145
146
  homepage: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#quote
146
147
  licenses:
147
148
  - MIT
@@ -177,4 +178,5 @@ test_files:
177
178
  - spec/jekyll_block_plugin_support_spec.rb
178
179
  - spec/jekyll_tag_plugin_support_spec.rb
179
180
  - spec/spec_helper.rb
181
+ - spec/status_persistence.txt
180
182
  ...