jekyll_plugin_support 0.4.1 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53975ba14d38fdc37e99ed9363b3d30885a301541c254584ae70d18157fc0e3f
4
- data.tar.gz: ccd9fc245d26fce6fa24bbc8edcda670faa017df3e08c75ec08effa760fa44ae
3
+ metadata.gz: d0856ddeea29e8a1e24f0a4997aecb7f6b6b22eae587ca8466142686b65557b7
4
+ data.tar.gz: ac8a8a047666f89b055b6ab90d6535b59e7f34441405852f5905ed6a517cbc27
5
5
  SHA512:
6
- metadata.gz: f78badf8195aebeb9401a974aebd589b1f9af69e9d6c83a3dd7d7340f2edc93ad418ef6806915dc130cb4deab5c0beb80eca15cd27189cdca999bd15d1434081
7
- data.tar.gz: dde45223b684b140e3c5e7d2633d96f39e974c148094243a979cebe60c33af5383e761c3e9aa6a60d34cdd71b90a550c39964f7e6e63c692660d536990074b39
6
+ metadata.gz: 8122412d70d1c99a6195834a51faa25f0d7beb59a23c18db0beba2883c83f5625920a63495b7ff21abf891faf97ae2ffe085c764c2be9d178bfeb37a7ae4e2f5
7
+ data.tar.gz: abd34bf8420c7040e7015ce131a8ae3ea01158a552637a4e8d63c51095c138bdf87fd11bff1c3fb3f35fbd3e8b728a09934c4aefe0bbe29817703bdb032a8114
data/.rubocop.yml CHANGED
@@ -1,10 +1,17 @@
1
1
  AllCops:
2
2
  Exclude:
3
- - vendor/**/*
4
- - Gemfile*
3
+ - exe/**/*
4
+ - vendor/**/*
5
+ - Gemfile*
5
6
  NewCops: enable
6
7
  TargetRubyVersion: 2.6
7
8
 
9
+ Gemspec/DeprecatedAttributeAssignment:
10
+ Enabled: false
11
+
12
+ Gemspec/RequireMFA:
13
+ Enabled: false
14
+
8
15
  Layout/HashAlignment:
9
16
  Enabled: false
10
17
 
@@ -14,5 +21,21 @@ Layout/LineLength:
14
21
  Layout/MultilineMethodCallIndentation:
15
22
  Enabled: false
16
23
 
24
+ Metrics/AbcSize:
25
+ Max: 20
26
+
27
+ Metrics/BlockLength:
28
+ Exclude:
29
+ - jekyll_plugin_support.gemspec
30
+
31
+ Metrics/MethodLength:
32
+ Max: 25
33
+
17
34
  Style/FrozenStringLiteralComment:
18
35
  Enabled: false
36
+
37
+ Style/Documentation:
38
+ Enabled: false
39
+
40
+ Style/TrailingCommaInHashLiteral:
41
+ EnforcedStyleForMultiline: comma
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.5.1 / 2023-02-17
2
+ * `no_arg_parsing` optimization added.
3
+
4
+ ## 0.5.0 / 2023-02-15
5
+ * Plugins now register themselves
6
+ * Plugins now report their name and version
7
+ * `@layout`, `@paginator`, and `@theme` have values if supported by the version of Jekyll, and they are active. (See [Jekyll docs](https://jekyllrb.com/docs/variables/).)
8
+
1
9
  ## 0.4.1 / 2023-02-14
2
10
  * Fixed several problems
3
11
  * Added demo site
data/README.md CHANGED
@@ -19,7 +19,7 @@ And then execute:
19
19
 
20
20
  $ bundle install
21
21
 
22
- ## Usage
22
+ ## General Usage
23
23
  `JekyllSupport::JekyllBlock` and `JekyllSupport::JekyllTag`
24
24
  provide support for Jekyll tag blocks and Jekyll tags, respectively.
25
25
  They are very similar in construction and usage.
@@ -47,32 +47,74 @@ For block tags, a single parameter is required, which contains any text enclosed
47
47
  Your implementation of `render_impl` can access `@page` and `@site`,
48
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
49
 
50
+ ### For a tag:
50
51
  ```ruby
51
- # For a tag:
52
+ require 'jekyll_plugin_support'
53
+
52
54
  module Jekyll
53
- class Quote < JekyllSupport::JekyllTag
55
+ class MyTag < JekyllSupport::JekyllTag
56
+ VERSION = '0.1.0'.freeze
57
+
54
58
  def render_impl
55
- site_data = @site.data
56
- @break = @helper.parameter_specified? 'break'
57
- # ...
59
+ # Your code here
60
+ end
61
+
62
+ JekyllPluginHelper.register(self, 'demo_tag')
63
+ end
64
+ end
65
+ ```
66
+
67
+ ### For a tag block:
68
+ ```ruby
69
+ require 'jekyll_plugin_support'
70
+
71
+ module Jekyll
72
+ class MyBlock < JekyllSupport::JekyllBlock
73
+ VERSION = '0.1.0'.freeze
74
+
75
+ def render_impl(text)
76
+ # Your code here
58
77
  end
78
+
79
+ JekyllPluginHelper.register(self, 'demo_block')
59
80
  end
60
81
  end
61
82
  ```
62
83
 
84
+ Note that each tag or tag block must define a constant called `VERSION`.
85
+ If your plugin is packaged as a gem, then you might need to include `version.rb` into the plugin class.
86
+ For example, if `lib/my_plugin/version.rb` looks like this:
87
+
88
+ ```ruby
89
+ module MyPluginVersion
90
+ VERSION = '0.5.1'.freeze
91
+ end
92
+ ```
93
+
94
+ Then your plugin can incorporate the `VERSION` constant into your plugin like this:
63
95
  ```ruby
64
- # For a tag block:
96
+ require 'jekyll_plugin_support'
97
+ require_relative 'my_block/version'
98
+
65
99
  module Jekyll
66
- class Quote < JekyllSupport::JekyllBlock
100
+ class MyBlock < JekyllSupport::JekyllBlock
101
+ include MyPluginVersion
102
+
67
103
  def render_impl(text)
68
- site_url = @site.url
69
- @break = @helper.parameter_specified? 'break'
70
- # ...
104
+ # Your code here
71
105
  end
106
+
107
+ JekyllPluginHelper.register(self, 'demo_tag')
72
108
  end
73
109
  end
74
110
  ```
75
111
 
112
+ ### `no_arg_parsing` Optimization
113
+ If your tag or block plugin only needs access to the raw arguments passed from the web page,
114
+ without tokenization, and you expect that the plugin might be invoked with large amounts of text,
115
+ derive your plugin from `JekyllBlockNoArgParsing` or `JekyllTagNoArgParsing`.
116
+
117
+
76
118
  ## Additional Information
77
119
  More information is available on
78
120
  [Mike Slinn&rsquo;s website](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html).
data/Rakefile CHANGED
@@ -2,4 +2,4 @@ require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
- task :default => :spec
5
+ task default: :spec
@@ -21,26 +21,14 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  Thanks for installing #{spec.name}!
23
23
 
24
- END_MESSAGE
25
- spec.post_install_message = <<~END_MESSAGE
26
-
27
- Thanks for installing #{spec.name}!
28
-
29
24
  END_MESSAGE
30
25
  spec.require_paths = ['lib']
31
26
  spec.required_ruby_version = '>= 2.6.0'
32
27
  spec.summary = 'Provides support for writing Jekyll plugins.'
33
28
  spec.test_files = spec.files.grep %r{^(test|spec|features)/}
34
- spec.version = JekyllQuoteVersion::VERSION
29
+ spec.version = JekyllPluginSupportVersion::VERSION
35
30
 
36
31
  spec.add_dependency 'jekyll', '>= 3.5.0'
37
32
  spec.add_dependency 'jekyll_plugin_logger'
38
33
  spec.add_dependency 'key-value-parser'
39
-
40
- spec.add_development_dependency 'debase'
41
- spec.add_development_dependency 'rspec-match_ignoring_whitespace'
42
- # spec.add_development_dependency 'rubocop-jekyll'
43
- spec.add_development_dependency 'rubocop-rake'
44
- spec.add_development_dependency 'rubocop-rspec'
45
- spec.add_development_dependency 'ruby-debug-ide'
46
34
  end
@@ -1,3 +1,3 @@
1
- module JekyllQuoteVersion
2
- VERSION = '0.4.1'.freeze
1
+ module JekyllPluginSupportVersion
2
+ VERSION = '0.5.1'.freeze
3
3
  end
@@ -5,6 +5,12 @@ require_relative 'jekyll_plugin_support/version'
5
5
 
6
6
  # @author Copyright 2022 Michael Slinn
7
7
  # @license SPDX-License-Identifier: Apache-2.0``
8
+ module NoArgParsing
9
+ attr_accessor :no_arg_parsing
10
+
11
+ @no_arg_parsing = true
12
+ end
13
+
8
14
  module JekyllSupport
9
15
  # Base class for Jekyll block tags
10
16
  class JekyllBlock < Liquid::Block
@@ -22,9 +28,10 @@ module JekyllSupport
22
28
  def initialize(tag_name, argument_string, parse_context)
23
29
  super
24
30
  @tag_name = tag_name
25
- @logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
26
- @helper = JekyllPluginHelper.new(tag_name, argument_string, @logger)
27
31
  @argument_string = argument_string
32
+ @logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
33
+ @logger.debug { "#{self.class}: respond_to?(:no_arg_parsing) #{respond_to?(:no_arg_parsing) ? 'yes' : 'no'}." }
34
+ @helper = JekyllPluginHelper.new(tag_name, argument_string, @logger, respond_to?(:no_arg_parsing))
28
35
  end
29
36
 
30
37
  # Method prescribed by the Jekyll plugin lifecycle.
@@ -33,8 +40,7 @@ module JekyllSupport
33
40
  text = super
34
41
  @helper.liquid_context = liquid_context
35
42
 
36
- # The names of front matter variables are hash keys for @page
37
- @page = liquid_context.registers[:page] # Jekyll::Drops::DocumentDrop
43
+ @page = liquid_context.registers[:page] # Type Jekyll::Drops::DocumentDrop
38
44
  @site = liquid_context.registers[:site]
39
45
  @config = @site.config
40
46
  @envs = liquid_context.environments.first
@@ -51,6 +57,17 @@ module JekyllSupport
51
57
  end
52
58
  end
53
59
 
60
+ class JekyllBlockNoArgParsing < JekyllBlock
61
+ def initialize(tag_name, argument_string, parse_context)
62
+ class << self
63
+ include NoArgParsing
64
+ end
65
+
66
+ super
67
+ @logger.debug { "#{self.class}: respond_to?(:o_arg_parsing) #{respond_to?(:no_arg_parsing) ? 'yes' : 'no'}." }
68
+ end
69
+ end
70
+
54
71
  # Base class for Jekyll tags
55
72
  class JekyllTag < Liquid::Tag
56
73
  attr_reader :argument_string, :helper, :line_number, :logger, :page, :site
@@ -67,26 +84,46 @@ module JekyllSupport
67
84
  def initialize(tag_name, argument_string, parse_context)
68
85
  super
69
86
  @tag_name = tag_name
70
- @logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
71
- @helper = JekyllPluginHelper.new(tag_name, argument_string, @logger)
72
87
  @argument_string = argument_string
88
+ @logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
89
+ @logger.debug { "#{self.class}: respond_to?(:no_arg_parsing) #{respond_to?(:no_arg_parsing) ? 'yes' : 'no'}." }
90
+ @helper = JekyllPluginHelper.new(tag_name, argument_string, @logger, respond_to?(:no_arg_parsing))
73
91
  end
74
92
 
75
93
  # Method prescribed by the Jekyll plugin lifecycle.
76
94
  def render(liquid_context)
77
95
  @helper.liquid_context = liquid_context
78
- @page = liquid_context.registers[:page]
79
- @site = liquid_context.registers[:site]
96
+
97
+ @envs = liquid_context.environments.first
98
+
99
+ @layout = @envs[:layout]
100
+ @paginator = @envs[:paginator]
101
+ @theme = @envs[:theme]
102
+
103
+ @page = liquid_context.registers[:page]
104
+ @site = liquid_context.registers[:site]
105
+
80
106
  @config = @site.config
81
- @envs = liquid_context.environments.first
82
107
  @mode = @config['env']['JEKYLL_ENV'] || 'development'
108
+
83
109
  render_impl
84
110
  end
85
111
 
86
112
  # Jekyll plugins must override this method, not render, so their plugin can be tested more easily
87
113
  # @page and @site are available
88
114
  def render_impl
89
- abort "JekyllTag render_impl for tag #{@tag_name} must be overridden, but it was not."
115
+ abort "#{self.class}.render_impl for tag #{@tag_name} must be overridden, but it was not."
116
+ end
117
+ end
118
+
119
+ class JekyllTagNoArgParsing < JekyllTag
120
+ def initialize(tag_name, argument_string, parse_context)
121
+ class << self
122
+ include NoArgParsing
123
+ end
124
+
125
+ super
126
+ @logger.debug { "#{self.class}: respond_to?(:no_arg_parsing) #{respond_to?(:no_arg_parsing) ? 'yes' : 'no'}." }
90
127
  end
91
128
  end
92
129
  end
@@ -1,13 +1,11 @@
1
- # frozen_string_literal: true
2
-
3
1
  require 'shellwords'
4
2
  require 'key_value_parser'
5
3
 
6
4
  # Base class for all types of Jekyll plugin helpers
7
5
  class JekyllPluginHelper
8
- attr_reader :argv, :keys_values, :liquid_context, :logger, :markup, :params, :tag_name
6
+ attr_reader :argv, :keys_values, :liquid_context, :logger, :markup, :no_arg_parsing, :params, :tag_name
9
7
 
10
- # Expand a environment variable reference
8
+ # Expand an environment variable reference
11
9
  def self.expand_env(str, die_if_undefined: false)
12
10
  str.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/) do
13
11
  envar = Regexp.last_match(1)
@@ -18,6 +16,21 @@ class JekyllPluginHelper
18
16
  end
19
17
  end
20
18
 
19
+ def self.register(klass, name)
20
+ abort("Error: The #{name} plugin does not define VERSION") \
21
+ unless klass.const_defined?(:VERSION)
22
+
23
+ version = klass.const_get(:VERSION)
24
+
25
+ abort("Error: The #{name} plugin is not an instance of JekyllSupport::JekyllBlock or JekyllSupport::JekyllTag") \
26
+ unless klass.instance_of?(Class) &&
27
+ (klass.ancestors.include?(JekyllSupport::JekyllBlock) || \
28
+ klass.ancestors.include?(JekyllSupport::JekyllTag))
29
+
30
+ Liquid::Template.register_tag(name, klass)
31
+ PluginMetaLogger.instance.info { "Loaded #{name} v#{version} plugin." }
32
+ end
33
+
21
34
  # strip leading and trailing quotes if present
22
35
  def self.remove_quotes(string)
23
36
  string.strip.gsub(/\A'|\A"|'\Z|"\Z/, '').strip if string
@@ -32,20 +45,37 @@ class JekyllPluginHelper
32
45
  # This argument is used mostly to display localized error messages on Liquid built-in Tags and Filters.
33
46
  # See https://github.com/Shopify/liquid/wiki/Liquid-for-Programmers#create-your-own-tags
34
47
  # @return [void]
35
- def initialize(tag_name, markup, logger)
48
+ def initialize(tag_name, markup, logger, no_arg_parsing)
36
49
  @tag_name = tag_name
37
50
  @logger = logger
38
- @logger.debug { "@keys_values='#{@keys_values}'" }
51
+ @no_arg_parsing = no_arg_parsing
39
52
  reinitialize(markup.strip)
53
+ @logger.debug { "@keys_values='#{@keys_values}'" }
54
+ end
55
+
56
+ def warn_fetch(variable)
57
+ abort "Error: Argument parsing was suppressed, but an attempt to obtain the value of #{variable} was made"
58
+ end
59
+
60
+ def warn_parse(meth)
61
+ abort "Error: Argument parsing was suppressed, but an attempt to invoke #{meth} was made"
40
62
  end
41
63
 
42
64
  def reinitialize(markup)
43
65
  # @keys_values was a Hash[Symbol, String|Boolean] but now it is Hash[String, String|Boolean]
44
- @markup = markup # Useful for debugging
45
- @argv = Shellwords.split(JekyllPluginHelper.expand_env(markup))
46
- @keys_values = KeyValueParser \
47
- .new({}, { array_values: false, normalize_keys: false, separator: /=/ }) \
48
- .parse(@argv)
66
+ @markup = markup
67
+ if @no_arg_parsing
68
+ define_singleton_method(:argv) { warn_fetch :argv }
69
+ define_singleton_method(:keys_values) { warn_fetch :keys_values }
70
+ define_singleton_method(:params) { warn_fetch :params }
71
+ define_singleton_method(:parameter_specified?) { |_name| warn_parse(:parameter_specified?) }
72
+ define_singleton_method(:delete_parameter) { |_name| warn_parse(:delete_parameter) }
73
+ else
74
+ @argv = Shellwords.split(self.class.expand_env(markup))
75
+ @keys_values = KeyValueParser \
76
+ .new({}, { array_values: false, normalize_keys: false, separator: /=/ }) \
77
+ .parse(@argv)
78
+ end
49
79
  end
50
80
 
51
81
  def delete_parameter(key)
@@ -93,7 +123,7 @@ class JekyllPluginHelper
93
123
  # Sets @params by replacing any Liquid variable names with their values
94
124
  def liquid_context=(context)
95
125
  @liquid_context = context
96
- @params = @keys_values.map { |k, _v| lookup_variable(k) }
126
+ @params = @keys_values.map { |k, _v| lookup_variable(k) } unless respond_to?(:no_arg_parsing) && no_arg_parsing
97
127
  end
98
128
 
99
129
  def lookup_variable(symbol)
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.4.1
4
+ version: 0.5.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-02-14 00:00:00.000000000 Z
11
+ date: 2023-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -52,76 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: debase
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rspec-match_ignoring_whitespace
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: rubocop-rake
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: rubocop-rspec
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: ruby-debug-ide
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
55
  description:
126
56
  email:
127
57
  - mslinn@mslinn.com
@@ -142,6 +72,7 @@ files:
142
72
  - spec/jekyll_block_plugin_support_spec.rb
143
73
  - spec/jekyll_tag_plugin_support_spec.rb
144
74
  - spec/spec_helper.rb
75
+ - spec/status_persistence.txt
145
76
  homepage: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#quote
146
77
  licenses:
147
78
  - MIT
@@ -177,4 +108,5 @@ test_files:
177
108
  - spec/jekyll_block_plugin_support_spec.rb
178
109
  - spec/jekyll_tag_plugin_support_spec.rb
179
110
  - spec/spec_helper.rb
111
+ - spec/status_persistence.txt
180
112
  ...