jekyll_plugin_support 3.1.2 → 3.1.6

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: a63b7533f8a3f533d8dc786921c5792b7517ac60c5fbb21f93b19e7a6a579f93
4
- data.tar.gz: ad1d4c07e39743b8fd057f0235ab6ae6c1f89fa130026d7f7012d8a855cf5fc3
3
+ metadata.gz: 0e9e668968a611289735fbb49845ac930d027015d4c385295e78722f85cf40cf
4
+ data.tar.gz: b2cc67846dd969875cf3fa62cba74adfbe10ed86b9607077054e63c07ac890e8
5
5
  SHA512:
6
- metadata.gz: db14aae8119f378a9032c6aefa6d9a0065e735c2dbf5965b136a1bf393782f573ed178645db5c50c420eb4b8767c046f7802be690628d3cc0efb57849e85ac00
7
- data.tar.gz: 54ab6a67d6fecc4b587d00eda923868a0780555fa52af2ebe092fb080aa5537b01da7f99140cb0ab13c0ab9f3fc891b7f127f93d873c6b8c9eb478f90ba8c3fd
6
+ metadata.gz: 831f38b469c65ef2e2332f18b1624ce06626322643939e3bc497f513c24092070b7ac96664f0a6a63f323f8058141f7c6159966ed23fb76741f807d53d5ffef5
7
+ data.tar.gz: fe06519f62fb7a42cdbba80752cd12a85ad2f1458fa18a2318bb758d75d6c02a65739f62096f6bda3077947588da88398aa6b7cb644346438b35c905b963ee43
data/.rubocop.yml CHANGED
@@ -107,6 +107,9 @@ Style/GlobalVars:
107
107
  Exclude:
108
108
  - spec/mslinn_binary_search_spec.rb
109
109
 
110
+ Style/OneClassPerFile:
111
+ Enabled: false
112
+
110
113
  Style/RedundantParentheses:
111
114
  Exclude:
112
115
  - README.md
data/CHANGELOG.md CHANGED
@@ -1,19 +1,30 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.1.6
4
+
5
+ Several little fixes and tweaks.
6
+
7
+
8
+ ## 3.1.5
9
+
10
+ * Added install subcommand to bundle invocations
11
+ * Replaced `wslvar` which is no longer maintained
12
+
13
+
14
+ ## 3.1.4
15
+
16
+ * Added `@jekyll_version` instance variable exposing raw HTML content of the page being processed
17
+ * Added `@raw_content` instance variable exposing raw HTML content of the page being processed
18
+
19
+
3
20
  ## 3.1.3 / 2025-01-02
4
21
 
5
- * **BREAKING CHANGE**: Modified `JekyllPluginHelper.expand_env` to only expand Bash environment
6
- variables (`$VAR` or `${VAR}`), not Windows environment variables (`%VAR%`). This prevents false
7
- expansions in web content where text strings contain pairs of percent signs that are not
8
- environment variables.
9
- * Removed the `use_wslvar` parameter from `JekyllPluginHelper.expand_env` method signature.
10
- * `JekyllPluginHelper.env_var_expand_windows` is still available for plugins that specifically
11
- need Windows environment variable expansion.
12
- * `jekyll_flexible_include_plugin` now explicitly calls both `env_var_expand_bash` and
13
- `env_var_expand_windows` for file paths to maintain its ability to handle both Bash and
14
- Windows environment variables.
15
- * Updated `JekyllPluginHelper.find_windows_envar` to properly fall back to environment variable
16
- search when `wslvar` is not available or doesn't find the variable.
22
+ * Modified `JekyllPluginHelper.expand_env` to only expand Bash environment
23
+ variables (`$VAR` or `${VAR}`), not Windows environment variables (`%VAR%`)
24
+ * Removed the `use_wslvar` parameter from `JekyllPluginHelper.expand_env` method
25
+ signature
26
+ * `env_var_expand_windows` remains available for plugins that specifically need
27
+ Windows environment variable expansion
17
28
 
18
29
 
19
30
  ## 3.1.2 / 2025-11-17
@@ -69,12 +80,7 @@
69
80
  * Added the `bin/release_port` script that kills hung processes being debugged
70
81
  * Added the `cleanDemo` task for the **Debug Demo production** and **Debug Demo development** tasks
71
82
  * Many minor improvements to the demo.
72
- * `JekyllSupport::JekyllPluginHelper::register` now accepts a `quiet` option, to suppress the signon message.
73
- Use it like this:
74
-
75
- ```ruby
76
- JekyllPluginHelper.register(self, 'tag_name', quiet: true)
77
- ```
83
+ * `JekyllPluginHelper.register` now accepts a `quiet` option to suppress the signon message
78
84
 
79
85
 
80
86
  ## 1.0.3 / 2024-08-19
@@ -86,19 +92,7 @@
86
92
 
87
93
  * Computes line_number and path properly
88
94
  * Refactored demo CSS
89
- * Improved custom plugin error handling and sample code.
90
- The following seems to be optimal for custom plugins; it suppresses the ridiculously long stack trace that used to be generated:
91
-
92
- ```ruby
93
- begin
94
- # ...
95
- rescue DemoInlineTagError => e # jekyll_plugin_support handles StandardError
96
- @logger.error { e.logger_message }
97
- exit! 1 if @die_on_demo_tag_error
98
-
99
- e.html_message
100
- end
101
- ```
95
+ * Improved custom plugin error handling and sample code
102
96
 
103
97
 
104
98
  ## 1.0.1 / 2024-07-27
@@ -161,10 +155,8 @@
161
155
  * Demo site now shows how to define and handle custom errors.
162
156
  * Added `@tag_config` variable, which can be inspected to determine whether to die on various types of exceptions.
163
157
  * Added `format_error_message`, `maybe_reraise_error`, and `raise_error` to `JekyllBlock` and `JekyllTag`
164
- * Adds a method called `shorten_backtrace` to `StandardError` and all custom error
165
- classes defined by `JekyllSupport.define_error`.
166
- See the `demo/` directory for examples of how to use this optional feature.
167
- * The `plugin-vars` section in `_config.yml` was renamed to `liquid_vars`.
158
+ * Added `shorten_backtrace` to StandardError and all custom error classes defined by `JekyllSupport.define_error`
159
+ * The `plugin-vars` section in `_config.yml` was renamed to `liquid_vars`
168
160
 
169
161
 
170
162
  ## 0.7.2 / 2023-08-14
@@ -176,10 +168,8 @@
176
168
 
177
169
  * Suppressed stack trace from issue [#4](../../issues/4).
178
170
  * Now using Shopify `ruby-lsp` instead of `rebornix.Ruby` by Peng Lv
179
- * Debug configurations changed to `rdbg` instead of `ruby`, so the `debase` development dependency was changed to
180
- [`debug`](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg),
181
- which provides the `rdgb` command.
182
- The `ruby-debug-ide` development dependency is also no longer required.
171
+ * Debug configurations changed to `rdbg` instead of `ruby`, so the `debase` development dependency was changed to [`debug`](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg)
172
+ * The `ruby-debug-ide` development dependency is no longer required
183
173
 
184
174
 
185
175
  ## 0.7.0 / 2023-05-22
data/FIXME.md ADDED
@@ -0,0 +1,49 @@
1
+ # Code Smells in `jekyll_plugin_support`
2
+
3
+ A review of the codebase turned up the issues below. They are ordered by
4
+ severity. Line numbers refer to the state of the repo at the time of review and
5
+ may drift.
6
+
7
+ ## Medium severity
8
+
9
+ ### 6. Duplication between `JekyllTag` and `JekyllBlock`
10
+
11
+ `render`, `initialize`, and `set_error_context` are ~90% identical across
12
+ `lib/tag/jekyll_plugin_support_tag.rb` and
13
+ `lib/block/jekyll_plugin_support_block.rb`. The block version even logs
14
+ `e.full_message` **twice** (lines 89 and 93). Extract a shared
15
+ `JekyllPluginBase` module.
16
+
17
+
18
+ ### 12. `parse` has a leftover TODO and dead branch
19
+
20
+ ```ruby
21
+ @params_original = @keys_values_original unless respond_to?(:no_arg_parsing) && no_arg_parsing
22
+ ...
23
+ @params = @keys_values # TODO: @keys_values should be deleted
24
+ ```
25
+
26
+ The conditional on `@params_original` is moot because `reinitialize` only calls
27
+ `parse` when `!@no_arg_parsing`. And the TODO has lingered.
28
+ (`lib/helper/jekyll_plugin_helper.rb:91-106`)
29
+
30
+ ## Lower severity
31
+
32
+ ### 17. Comment typos / placeholder text in docs
33
+
34
+ `@ptions` appears in the parse_context doc block of *both* tag and block files
35
+ (should be `@options`). Comments like `# Are error and logger.error defined?`
36
+ (`lib/jekyll_plugin_support/jekyll_plugin_support_class.rb:18`) read like
37
+ unanswered questions left in production.
38
+
39
+ ### 20. `_` prefixed unused param but still required
40
+
41
+ `dump_vars(_logger, liquid_context)` — the `_` prefix says "unused," but callers
42
+ must still pass it. Either drop the parameter or use it.
43
+ (`lib/jekyll_plugin_support/jekyll_plugin_support_class.rb:30`)
44
+
45
+
46
+ ## Suggested order to tackle
47
+
48
+ 1. **Extract shared base for `JekyllTag`/`JekyllBlock` (#6)** — biggest maintainability win.
49
+ 3. Remove dead/commented code (#4).
data/README.md CHANGED
@@ -35,6 +35,9 @@ Public plugins that use `jekyll_plugin_support` include:
35
35
  <li>
36
36
  <a href='https://www.mslinn.com/jekyll_plugins/jekyll_img.html'><code>jekyll_img</code></a>
37
37
  </li>
38
+ <li>
39
+ <a href='https://www.mslinn.com/jekyll_plugins/jekyll_kramdown.html'><code>jekyll_kramdown</code></a>
40
+ </li>
38
41
  <li>
39
42
  <a href='https://www.mslinn.com/jekyll_plugins/jekyll_outline.html'><code>jekyll_outline</code></a>
40
43
  </li>
@@ -54,7 +57,8 @@ Public plugins that use `jekyll_plugin_support` include:
54
57
 
55
58
  Jekyll plugin tags created from `jekyll_plugin_support` framework automatically have the following features:
56
59
 
57
- 0. Claude LLM support is provided
60
+ 0. Generic LLM support is provided; tested and works with Claude and mini-agent from MiniMax.
61
+ Gemini is not recommended since it can only handle one project at a time, and this component is a project.
58
62
  1. Boilerplate is removed, so you can focus on the required logic and output.
59
63
  2. Arguments are parsed for keywords and name/value parameters.
60
64
  3. Single or double quotes can be used for arguments and parameters.
@@ -154,7 +158,7 @@ end
154
158
  Install the `jekyll_plugin_support` gem into your plugin project in the usual manner:
155
159
 
156
160
  ```shell
157
- $ bundle
161
+ $ bundle install
158
162
  ```
159
163
 
160
164
  Copy the CSS classes from
@@ -456,9 +460,21 @@ Included spaces are ignored:
456
460
  * [`@config`](https://docs.github.com/en/pages/setting-up-a-github-pages-site-with-jekyll/about-github-pages-and-jekyll#configuring-jekyll-in-your-github-pages-site)
457
461
  The [YAML](https://yaml.org/) Jekyll site configuration file
458
462
 
463
+ - `@jekyll_version` version of Jekyll, the returned string might have a value like "4.4.1".
464
+
459
465
  * [`@helper`](https://github.com/mslinn/jekyll_plugin_support/blob/master/lib/jekyll_plugin_helper.rb)
460
466
  `JekyllPluginHelper` instance for your plugin.
461
467
 
468
+ * `@highlighter_prefix` Syntax highlighter prefix, as it exists
469
+ during the [layout rendering stage](https://jekyllrb.com/docs/plugins/hooks/)
470
+ occurring between `:documents, :post_convert` and `:documents, :post_render`.
471
+ All pages, posts and documents go through this phase.
472
+
473
+ * `@highlighter_suffix` Syntax highlighter suffix, as it exists
474
+ during the [layout rendering stage](https://jekyllrb.com/docs/plugins/hooks/)
475
+ occurring between `:documents, :post_convert` and `:documents, :post_render`.
476
+ All pages, posts and documents go through this phase.
477
+
462
478
  * [`@layout`](https://jekyllrb.com/docs/variables/#global-variables) Layout information
463
479
 
464
480
  * `@logger` [`jekyll_plugin_logger`](https://github.com/mslinn/jekyll_plugin_logger) instance for your Jekyll plugin.
@@ -470,6 +486,11 @@ Included spaces are ignored:
470
486
 
471
487
  * [`@paginator`](https://jekyllrb.com/docs/variables/#page-variables) Pagination variables
472
488
 
489
+ - `@raw_content` The raw HTML/Markdown content of the current page, as it exists
490
+ during the [layout rendering stage](https://jekyllrb.com/docs/plugins/hooks/)
491
+ occurring between `:documents, :post_convert` and `:documents, :post_render`.
492
+ All pages, posts and documents go through this phase.
493
+
473
494
  * [`@scopes`](https://jekyllrb.com/docs/variables/)
474
495
  See the [`jekyll_plugin_support` demo project](demo/variables.html)
475
496
 
@@ -643,16 +664,20 @@ They are can be used like any other Liquid variable.
643
664
  ## Variable Expansion
644
665
 
645
666
  Jekyll expands Liquid variable references during the page rendering process.
646
- Jekyll does not expand Liquid variable references passes as parameters to tag and block plugins, however.
667
+ Jekyll does not expand Liquid variable references passed as parameters to tag and block plugins, however.
647
668
  However, plugins made from `jekyll_plugin_support` automatically
648
669
  expand all types of variable references passed as parameters and in block tag bodies.
649
670
 
650
- `Jekyll_plugin_support` tag and block plugins expand the following types of variables:
671
+ `jekyll_plugin_support` tag and block plugins expand the following types of variables:
651
672
 
652
- * Jekyll_plugin_support configuration variables, discussed above.
673
+ * jekyll_plugin_support configuration variables, discussed above.
653
674
  * Jekyll [page](https://jekyllrb.com/docs/variables/#page-variables) and
654
675
  [layout](https://jekyllrb.com/docs/layouts/#variables) variables.
676
+ * Jekyll global variables such as `jekyll.version` and `jekyll.environment`.
655
677
  * Inline Liquid variables (defined in [assign](https://shopify.dev/docs/api/liquid/tags/assign) and [capture](https://shopify.dev/docs/api/liquid/tags/capture) statements).
678
+ * Include variables (when plugins are invoked from within Jekyll include files with parameters).
679
+ * Theme variables (provided by the active theme).
680
+ * Paginator variables (for sites with pagination).
656
681
 
657
682
  In the following example web page, Jekyll expands the `var1` reference within the `<p></p>` tag,
658
683
  but not the `var1` or `var2` references passed to `my_plugin`.
@@ -674,8 +699,14 @@ Thus, the above is interpreted as follows when `my_plugin` is evaluated during t
674
699
  {% my_plugin param1="value1" param2="value 2" %}
675
700
  ```
676
701
 
702
+ **Note on Variable Resolution Order**: Variables are processed in Jekyll's actual priority order to ensure expected behavior:
703
+ 1. Page variables (e.g., `{{page.title}}`)
704
+ 2. Layout variables (e.g., `{{layout.name}}`)
705
+ 3. Jekyll global variables (e.g., `{{jekyll.version}}`)
706
+ 4. Include variables (e.g., `{{include.my_var}}`)
707
+ 5. Liquid variables (e.g., `{{my_var}}` from `assign`/`capture`)
677
708
 
678
- `Jekyll_plugin_support` expands most of the [plugin variables described above](#predefined-variables),
709
+ `jekyll_plugin_support` expands most of the [plugin variables described above](#predefined-variables),
679
710
  replacing Liquid variable references with their values.
680
711
  The exception is `@argument_string`, which is not expanded.
681
712
 
@@ -34,6 +34,5 @@ Gem::Specification.new do |spec|
34
34
  spec.add_dependency 'jekyll', '>= 4.4.1'
35
35
  spec.add_dependency 'jekyll_plugin_logger'
36
36
  spec.add_dependency 'key-value-parser'
37
- spec.add_dependency 'pry'
38
37
  spec.add_dependency 'sorted_set'
39
38
  end
@@ -1,7 +1,8 @@
1
1
  module JekyllSupport
2
2
  # Base class for Jekyll block tags
3
3
  class JekyllBlock < Liquid::Block
4
- attr_reader :argument_string, :helper, :line_number, :logger, :page, :site, :text
4
+ attr_reader :argument_string, :helper, :highlighter_prefix, :highlighter_suffix, :jekyll_version, :line_number, :logger, :page, :raw_content,
5
+ :site, :text
5
6
 
6
7
  # See https://github.com/Shopify/liquid/wiki/Liquid-for-Programmers#create-your-own-tags
7
8
  # @param tag_name [String] the name of the tag, which we usually know.
@@ -62,9 +63,13 @@ module JekyllSupport
62
63
  set_error_context
63
64
 
64
65
  # @envs.keys are :content, :highlighter_prefix, :highlighter_suffix, :jekyll, :layout, :page, :paginator, :site, :theme
65
- @layout = @envs[:layout]
66
- @paginator = @envs[:paginator]
67
- @theme = @envs[:theme]
66
+ @highlighter_prefix = @envs[:highlighter_prefix]
67
+ @highlighter_suffix = @envs[:highlighter_suffix]
68
+ @jekyll_version = @envs[:jekyll]['version']
69
+ @layout = @envs[:layout]
70
+ @paginator = @envs[:paginator]
71
+ @raw_content = @envs[:content]
72
+ @theme = @envs[:theme]
68
73
 
69
74
  env = @config['env']
70
75
  @mode = env&.key?('JEKYLL_ENV') ? env['JEKYLL_ENV'] : 'development'
@@ -75,10 +80,6 @@ module JekyllSupport
75
80
  @attribution = @helper.parameter_specified?('attribution') || false unless @no_arg_parsing
76
81
  @logger.debug { "@keys_values='#{@keys_values}'" }
77
82
 
78
- # @argument_string = JekyllSupport.lookup_liquid_variables @logger, liquid_context, @argument_string # Is this redundant?
79
- # @argument_string.strip! # Is this redundant?
80
- # @helper.reinitialize @argument_string # Is this redundant?
81
-
82
83
  render_impl(text)
83
84
  rescue StandardError => e
84
85
  e.shorten_backtrace
@@ -87,7 +88,7 @@ module JekyllSupport
87
88
  in_file_name = "in '#{file_name}' " if file_name
88
89
  of_page = "of '#{@page['path']}'" if @page
89
90
  @logger.error { "While processing line #{@line_number} #{of_page} for #{tag_name} #{in_file_name}- #{e.message}" }
90
- binding.pry if @pry_on_standard_error # rubocop:disable Lint/Debugger
91
+ binding.pry if @pry_on_standard_error && defined?(Pry) # rubocop:disable Lint/Debugger
91
92
  raise e if @die_on_standard_error
92
93
 
93
94
  <<~END_MSG
@@ -100,7 +101,7 @@ module JekyllSupport
100
101
  # Jekyll plugins should override this method, not render,
101
102
  # so they can be tested more easily.
102
103
  # The following variables are predefined:
103
- # @argument_string, @config, @envs, @helper, @layout, @logger, @mode, @page, @paginator, @site, @tag_name and @theme
104
+ # @argument_string, @config, @envs, @helper, @highlighter_prefix, @highlighter_suffix, @layout, @logger, @mode, @page, @paginator, @raw_content, @site, @tag_name and @theme
104
105
  # @return [String] The result to be rendered to the invoking page
105
106
  def render_impl(text)
106
107
  text
@@ -1,7 +1,5 @@
1
1
  module JekyllSupport
2
2
  class JekyllBlockNoArgParsing < JekyllBlock
3
- attr_reader :argument_string, :helper, :line_number, :logger, :page, :site
4
-
5
3
  def initialize(tag_name, argument_string, parse_context)
6
4
  class << self
7
5
  include NoArgParsing
@@ -42,12 +42,8 @@ module JekyllSupport
42
42
  END_MSG
43
43
  end
44
44
 
45
- def shorten_backtrace(backtrace_element_count = 6)
46
- set_backtrace backtrace[0..backtrace_element_count]
47
- # b = backtrace[0..backtrace_element_count - 1].map do |x|
48
- # x.gsub(Dir.pwd + '/', './')
49
- # end
50
- # set_backtrace b
45
+ def shorten_backtrace(backtrace_element_count = 5)
46
+ set_backtrace backtrace.first(backtrace_element_count)
51
47
  end
52
48
  end
53
49
  end
@@ -27,7 +27,7 @@ module JekyllSupport
27
27
 
28
28
  # @return undefined if parameter was specified, removes it from the available tokens and returns value
29
29
  def parameter_specified?(name, delete_param: true)
30
- return false if @keys_values.to_s.empty?
30
+ return false if @keys_values.empty?
31
31
 
32
32
  key = name
33
33
  key = name.to_sym if @keys_values&.first&.first.instance_of?(Symbol)
@@ -68,15 +68,9 @@ module JekyllSupport
68
68
  #
69
69
  def self.find_windows_envar(envar, use_wslvar: true)
70
70
  if use_wslvar
71
- wslvar_path = `which wslvar 2> /dev/null`.chomp
72
- if wslvar_path.empty?
73
- warn "jekyll_plugin_support warning: wslvar not found in PATH; will attempt to find $#{envar} in the bash environment variables."
74
- return env_var_case_insensitive(envar)
75
- end
76
-
77
- result = `wslvar #{envar} &2> /dev/null`.chomp
71
+ result = self.wslvar envar
78
72
  if result.empty?
79
- warn "jekyll_plugin_support warning: wslvar did not find $#{envar}; will attempt to find it in the bash environment variables."
73
+ error "jekyll_plugin_support warning: wslvar did not find $#{envar}; will attempt to find it in the bash environment variables."
80
74
  return env_var_case_insensitive(envar)
81
75
  end
82
76
 
@@ -85,6 +79,10 @@ module JekyllSupport
85
79
  env_var_case_insensitive(envar)
86
80
  end
87
81
 
82
+ def self.wslvar(envar)
83
+ result = `powershell.exe -NoProfile -Command "Write-Output \\$env:#{envar}" 2> /dev/null`.chomp("\r\n")
84
+ end
85
+
88
86
  # Detect if Jekyll is running under WSL
89
87
  def self.wsl_detected? = File.read('/proc/version').include?('-WSL')
90
88
 
@@ -1,12 +1,7 @@
1
- # Monkey patch StandardError so a new method called shorten_backtrace is added.
2
1
  class StandardError
3
2
  def shorten_backtrace(backtrace_element_count = 5)
4
- set_backtrace backtrace[0..backtrace_element_count]
5
- # self.backtrace = backtrace[0..backtrace_element_count].map do |x|
6
- # raise JekyllPluginSupportError, "backtrace contains a #{x.class} with value '#{x}'." unless x.instance_of? String
7
-
8
- # x.gsub(Dir.pwd + '/', './')
9
- # end
3
+ limit = [backtrace.size - 1, backtrace_element_count].min
4
+ set_backtrace(backtrace[0..limit])
10
5
  end
11
6
  end
12
7
 
@@ -51,17 +46,22 @@ module JekyllSupport
51
46
 
52
47
  scope = liquid_context.scopes.last
53
48
 
49
+ # Support multiple environment variable keys and fall back to Jekyll's environment
54
50
  env = site.config['env']
55
- @mode = env&.key?('JEKYLL_ENV') ? env['JEKYLL_ENV'] : 'development'
51
+ @mode = env&.[]('JEKYLL_ENV') ||
52
+ env&.[]('JEKYLL_ENVIRONMENT') ||
53
+ site.config['JEKYLL_ENV'] ||
54
+ site.config['JEKYLL_ENVIRONMENT'] ||
55
+ 'development'
56
56
 
57
- # Set default values
57
+ # Set default values (support multiple data types)
58
58
  plugin_variables&.each do |name, value|
59
- scope[name] = value if value.instance_of? String
59
+ scope[name] = value
60
60
  end
61
61
 
62
62
  # Override with environment-specific values
63
63
  plugin_variables&.[](@mode)&.each do |name, value|
64
- scope[name] = value if value.instance_of? String
64
+ scope[name] = value
65
65
  end
66
66
 
67
67
  liquid_context
@@ -87,9 +87,17 @@ module JekyllSupport
87
87
  page = liquid_context.registers[:page]
88
88
  envs = liquid_context.environments.first
89
89
  layout = envs[:layout]
90
-
91
- markup = process_layout_variables logger, layout, markup
90
+ jekyll = envs[:jekyll]
91
+
92
+ # Process variables in Jekyll's actual priority order:
93
+ # 1. Page variables (registers[:page])
94
+ # 2. Layout variables (environments.first[:layout])
95
+ # 3. Jekyll global variables (environments.first[:jekyll])
96
+ # 4. Include variables (scopes)
97
+ # 5. Liquid variables (scopes)
92
98
  markup = process_page_variables logger, page, markup
99
+ markup = process_layout_variables logger, layout, markup
100
+ markup = process_jekyll_variables logger, jekyll, markup
93
101
  liquid_context.scopes&.each do |scope|
94
102
  markup = process_included_variables logger, scope, markup
95
103
  markup = process_liquid_variables logger, scope, markup
@@ -105,19 +113,20 @@ module JekyllSupport
105
113
  raise JekyllPluginSupportError, "include.#{name} is a #{name.class}, not a String." unless name.instance_of?(String)
106
114
  raise JekyllPluginSupportError, "include.#{name} has an undefined value." if value.nil?
107
115
 
108
- markup.gsub!("{{include.#{name}}}", value.to_s)
116
+ # Sanitize variable name to prevent regex injection
117
+ sanitized_name = sanitize_variable_name(name)
118
+ markup.gsub!("{{include.#{sanitized_name}}}", value.to_s)
109
119
  end
110
120
  markup
111
121
  rescue StandardError => e
112
122
  logger.error { e.full_message }
113
- exit! 1
114
123
  end
115
124
 
116
125
  def self.process_layout_variables(logger, layout, markup)
117
126
  layout&.each do |name, value|
118
127
  if value.nil?
119
128
  value = ''
120
- logger.warn { "layout.#{value} is undefined." }
129
+ logger.warn { 'layout.value is undefined.' }
121
130
  end
122
131
  markup.gsub!("{{layout.#{name}}}", value.to_s)
123
132
  end
@@ -154,6 +163,28 @@ module JekyllSupport
154
163
  logger.error { e.full_message }
155
164
  end
156
165
 
166
+ def self.process_jekyll_variables(logger, jekyll, markup)
167
+ return markup unless jekyll
168
+
169
+ # JekyllDrop provides access to version and environment
170
+ # Handle known JekyllDrop attributes
171
+ markup.gsub!('{{jekyll.version}}', jekyll.version.to_s) if jekyll.respond_to?(:version)
172
+
173
+ markup.gsub!('{{jekyll.environment}}', jekyll.environment.to_s) if jekyll.respond_to?(:environment)
174
+
175
+ markup
176
+ rescue StandardError => e
177
+ logger.error { e.full_message }
178
+ end
179
+
180
+ # Sanitizes variable names to prevent regex injection attacks
181
+ # @param name [String] the variable name to sanitize
182
+ # @return [String] sanitized variable name
183
+ def self.sanitize_variable_name(name)
184
+ # Allow only alphanumeric characters, underscores, and hyphens
185
+ name.to_s.gsub(/[^a-zA-Z0-9_-]/, '')
186
+ end
187
+
157
188
  def self.warn_short_trace(logger, error)
158
189
  remaining = error.backtrace.length - DISPLAYED_CALLS
159
190
  logger.warn do
@@ -1,3 +1,3 @@
1
1
  module JekyllPluginSupportVersion
2
- VERSION = '3.1.2'.freeze unless defined?(VERSION)
2
+ VERSION = '3.1.6'.freeze unless defined?(VERSION)
3
3
  end
@@ -1,5 +1,5 @@
1
1
  def require_directory(dir)
2
- Dir[File.join(dir, '*.rb')]&.sort&.each do |file|
2
+ Dir[File.join(dir, '*.rb')].each do |file|
3
3
  require file unless file == __FILE__
4
4
  end
5
5
  end
@@ -7,7 +7,6 @@ end
7
7
  require 'colorator'
8
8
  require 'jekyll'
9
9
  require 'jekyll_plugin_logger'
10
- require 'pry'
11
10
  require 'sorted_set'
12
11
 
13
12
  # require_directory __dir__
@@ -21,16 +20,9 @@ require_directory "#{__dir__}/tag"
21
20
  require_directory "#{__dir__}/jekyll_all_collections"
22
21
  require_directory "#{__dir__}/hooks"
23
22
 
24
- module JekyllSupport
25
- def self.redef_without_warning(const, value)
26
- send(:remove_const, const) if const_defined?(const)
27
- const_set const, value
28
- end
29
- end
30
-
31
23
  module ToString
32
24
  def to_s
33
- "#{self}.class.name"
25
+ self.class.name
34
26
  end
35
27
  end
36
28
 
@@ -41,6 +33,11 @@ module NoArgParsing
41
33
  end
42
34
 
43
35
  module JekyllSupport
36
+ def self.redef_without_warning(const, value)
37
+ send(:remove_const, const) if const_defined?(const)
38
+ const_set const, value
39
+ end
40
+
44
41
  class JekyllTag
45
42
  include JekyllSupportError
46
43
  include ToString
@@ -1,7 +1,8 @@
1
1
  module JekyllSupport
2
2
  # Base class for Jekyll tags
3
3
  class JekyllTag < Liquid::Tag
4
- attr_reader :argument_string, :helper, :line_number, :logger, :page, :site
4
+ attr_reader :argument_string, :helper, :highlighter_prefix, :highlighter_suffix, :jekyll_version, :line_number,
5
+ :logger, :page, :raw_content, :site
5
6
 
6
7
  # See https://github.com/Shopify/liquid/wiki/Liquid-for-Programmers#create-your-own-tags
7
8
  # @param tag_name [String] the name of the tag, which we usually know.
@@ -55,9 +56,13 @@ module JekyllSupport
55
56
  set_error_context
56
57
 
57
58
  # @envs.keys are :content, :highlighter_prefix, :highlighter_suffix, :jekyll, :layout, :page, :paginator, :site, :theme
58
- @layout = @envs[:layout]
59
- @paginator = @envs[:paginator]
60
- @theme = @envs[:theme]
59
+ @highlighter_prefix = @envs[:highlighter_prefix]
60
+ @highlighter_suffix = @envs[:highlighter_suffix]
61
+ @jekyll_version = @envs[:jekyll]['version']
62
+ @layout = @envs[:layout]
63
+ @paginator = @envs[:paginator]
64
+ @raw_content = @envs[:content]
65
+ @theme = @envs[:theme]
61
66
 
62
67
  env = @config['env']
63
68
  @mode = env&.key?('JEKYLL_ENV') ? env['JEKYLL_ENV'] : 'development'
@@ -65,10 +70,6 @@ module JekyllSupport
65
70
  @argument_string = JekyllSupport.lookup_liquid_variables @logger, @helper.liquid_context, @argument_string.to_s.strip
66
71
  @helper.reinitialize @argument_string.to_s.strip
67
72
 
68
- # @argument_string = JekyllSupport.lookup_liquid_variables @logger, liquid_context, @argument_string # Is this redundant?
69
- # @argument_string.strip! # Is this redundant?
70
- # @helper.reinitialize @argument_string # Is this redundant?
71
-
72
73
  render_impl
73
74
  rescue StandardError => e
74
75
  e.shorten_backtrace
@@ -76,7 +77,7 @@ module JekyllSupport
76
77
  in_file_name = "in '#{file_name}' " if file_name
77
78
  of_page = "of '#{@page['path']}'" if @page
78
79
  @logger.error { "#{e.class} on line #{@line_number} #{of_page} while processing #{tag_name} #{in_file_name}- #{e.message}" }
79
- binding.pry if @pry_on_standard_error # rubocop:disable Lint/Debugger
80
+ binding.pry if @pry_on_standard_error && defined?(Pry) # rubocop:disable Lint/Debugger
80
81
  raise e if @die_on_standard_error
81
82
 
82
83
  <<~END_MSG
@@ -88,7 +89,7 @@ module JekyllSupport
88
89
 
89
90
  # Jekyll plugins must override this method, not render, so their plugin can be tested more easily
90
91
  # The following variables are predefined:
91
- # @argument_string, @config, @envs, @helper, @layout, @logger, @mode, @page, @paginator, @site, @tag_name and @theme
92
+ # @argument_string, @config, @envs, @helper, @highlighter_prefix, @highlighter_suffix, @layout, @logger, @mode, @page, @paginator, @raw_content, @site, @tag_name and @theme
92
93
  def render_impl
93
94
  abort "#{self.class}.render_impl for tag #{@tag_name} must be overridden, but it was not."
94
95
  end
@@ -1,7 +1,5 @@
1
1
  module JekyllSupport
2
2
  class JekyllTagNoArgParsing < JekyllTag
3
- attr_reader :argument_string, :helper, :line_number, :logger, :page, :site
4
-
5
3
  def initialize(tag_name, argument_string, parse_context)
6
4
  class << self
7
5
  include NoArgParsing
@@ -1,52 +1,53 @@
1
1
  example_id | status | run_time |
2
2
  ----------------------------------------------------------------- | ------- | --------------- |
3
- ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:1] | passed | 0.00367 seconds |
4
- ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:2] | passed | 0.00321 seconds |
5
- ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:3] | passed | 0.004 seconds |
6
- ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:4] | passed | 0.00724 seconds |
7
- ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:5] | passed | 0.00321 seconds |
8
- ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:6] | passed | 0.00501 seconds |
9
- ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:7] | passed | 0.00573 seconds |
10
- ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:8] | passed | 0.00661 seconds |
11
- ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:9] | passed | 0.00674 seconds |
12
- ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:10] | passed | 0.00399 seconds |
13
- ./spec/bsearch_spec.rb[1:1] | pending | 0.00029 seconds |
14
- ./spec/bsearch_spec.rb[1:2] | pending | 0.00009 seconds |
15
- ./spec/custom_error_spec.rb[1:1] | passed | 0.0022 seconds |
16
- ./spec/custom_error_spec.rb[2:1] | passed | 0.0016 seconds |
17
- ./spec/date_sort_spec.rb[1:1] | passed | 0.00043 seconds |
18
- ./spec/date_sort_spec.rb[1:2] | passed | 0.00125 seconds |
19
- ./spec/date_sort_spec.rb[1:3] | passed | 0.00004 seconds |
20
- ./spec/date_sort_spec.rb[1:4] | passed | 0.00004 seconds |
21
- ./spec/date_sort_spec.rb[1:5] | passed | 0.00022 seconds |
22
- ./spec/date_sort_spec.rb[1:6] | passed | 0.00004 seconds |
23
- ./spec/date_sort_spec.rb[1:7] | passed | 0.00016 seconds |
24
- ./spec/date_sort_spec.rb[1:8] | passed | 0.00019 seconds |
25
- ./spec/date_sort_spec.rb[1:9] | passed | 0.00004 seconds |
26
- ./spec/date_sort_spec.rb[1:10] | passed | 0.00004 seconds |
27
- ./spec/expand_env_spec.rb[1:1] | passed | 0.0004 seconds |
28
- ./spec/expand_env_spec.rb[1:2] | passed | 2.09 seconds |
29
- ./spec/expand_env_spec.rb[1:3] | passed | 0.00015 seconds |
30
- ./spec/jekyll_plugin_helper_options_spec.rb[1:1] | passed | 0.00032 seconds |
31
- ./spec/jekyll_plugin_helper_options_spec.rb[1:2] | passed | 0.00013 seconds |
32
- ./spec/jekyll_plugin_helper_options_spec.rb[1:3] | passed | 0.00414 seconds |
33
- ./spec/jekyll_plugin_helper_options_spec.rb[1:4] | passed | 0.00074 seconds |
34
- ./spec/liquid_variable_parsing_spec.rb[1:1] | passed | 0.00186 seconds |
35
- ./spec/mslinn_binary_search_spec.rb[1:1] | passed | 0.00343 seconds |
36
- ./spec/mslinn_binary_search_spec.rb[1:2] | passed | 0.00018 seconds |
37
- ./spec/mslinn_binary_search_spec.rb[1:3] | passed | 0.00013 seconds |
38
- ./spec/send_chain_spec.rb[1:1] | passed | 0.00011 seconds |
39
- ./spec/send_chain_spec.rb[1:2] | passed | 0.00003 seconds |
40
- ./spec/send_chain_spec.rb[1:3] | passed | 0.00002 seconds |
41
- ./spec/send_chain_spec.rb[1:4] | passed | 0.00002 seconds |
42
- ./spec/send_chain_spec.rb[1:5] | passed | 0.00002 seconds |
43
- ./spec/send_chain_spec.rb[1:6] | passed | 0.00002 seconds |
44
- ./spec/send_chain_spec.rb[1:7] | passed | 0.00034 seconds |
45
- ./spec/send_spec.rb[1:1] | passed | 0.00011 seconds |
46
- ./spec/send_spec.rb[1:2] | passed | 0.00003 seconds |
47
- ./spec/sorted_lru_files_spec.rb[1:1] | passed | 0.00078 seconds |
48
- ./spec/sorted_lru_files_spec.rb[1:2] | passed | 0.00031 seconds |
3
+ ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:1] | passed | 0.00227 seconds |
4
+ ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:2] | passed | 0.00075 seconds |
5
+ ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:3] | passed | 0.00059 seconds |
6
+ ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:4] | passed | 0.00367 seconds |
7
+ ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:5] | passed | 0.0008 seconds |
8
+ ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:6] | passed | 0.00104 seconds |
9
+ ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:7] | passed | 0.00067 seconds |
10
+ ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:8] | passed | 0.00079 seconds |
11
+ ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:9] | passed | 0.00065 seconds |
12
+ ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:10] | passed | 0.00245 seconds |
13
+ ./spec/bsearch_spec.rb[1:1] | pending | 0.00005 seconds |
14
+ ./spec/bsearch_spec.rb[1:2] | pending | 0.00038 seconds |
15
+ ./spec/custom_error_spec.rb[1:1] | passed | 0.00211 seconds |
16
+ ./spec/custom_error_spec.rb[2:1] | passed | 0.00182 seconds |
17
+ ./spec/date_sort_spec.rb[1:1] | passed | 0.00019 seconds |
18
+ ./spec/date_sort_spec.rb[1:2] | passed | 0.00069 seconds |
19
+ ./spec/date_sort_spec.rb[1:3] | passed | 0.00051 seconds |
20
+ ./spec/date_sort_spec.rb[1:4] | passed | 0.00006 seconds |
21
+ ./spec/date_sort_spec.rb[1:5] | passed | 0.00067 seconds |
22
+ ./spec/date_sort_spec.rb[1:6] | passed | 0.00007 seconds |
23
+ ./spec/date_sort_spec.rb[1:7] | passed | 0.00062 seconds |
24
+ ./spec/date_sort_spec.rb[1:8] | passed | 0.00007 seconds |
25
+ ./spec/date_sort_spec.rb[1:9] | passed | 0.0005 seconds |
26
+ ./spec/date_sort_spec.rb[1:10] | passed | 0.00008 seconds |
27
+ ./spec/expand_env_spec.rb[1:1] | passed | 0.00007 seconds |
28
+ ./spec/expand_env_spec.rb[1:2] | passed | 0.00003 seconds |
29
+ ./spec/expand_env_spec.rb[1:3] | passed | 1.66 seconds |
30
+ ./spec/expand_env_spec.rb[1:4] | passed | 0.00131 seconds |
31
+ ./spec/jekyll_plugin_helper_options_spec.rb[1:1] | passed | 0.00014 seconds |
32
+ ./spec/jekyll_plugin_helper_options_spec.rb[1:2] | passed | 0.00058 seconds |
33
+ ./spec/jekyll_plugin_helper_options_spec.rb[1:3] | passed | 0.00169 seconds |
34
+ ./spec/jekyll_plugin_helper_options_spec.rb[1:4] | passed | 0.00091 seconds |
35
+ ./spec/liquid_variable_parsing_spec.rb[1:1] | passed | 0.00126 seconds |
36
+ ./spec/mslinn_binary_search_spec.rb[1:1] | passed | 0.0027 seconds |
37
+ ./spec/mslinn_binary_search_spec.rb[1:2] | passed | 0.00006 seconds |
38
+ ./spec/mslinn_binary_search_spec.rb[1:3] | passed | 0.00004 seconds |
39
+ ./spec/send_chain_spec.rb[1:1] | passed | 0.00003 seconds |
40
+ ./spec/send_chain_spec.rb[1:2] | passed | 0.00004 seconds |
41
+ ./spec/send_chain_spec.rb[1:3] | passed | 0.00003 seconds |
42
+ ./spec/send_chain_spec.rb[1:4] | passed | 0.00003 seconds |
43
+ ./spec/send_chain_spec.rb[1:5] | passed | 0.00003 seconds |
44
+ ./spec/send_chain_spec.rb[1:6] | passed | 0.00003 seconds |
45
+ ./spec/send_chain_spec.rb[1:7] | passed | 0.00003 seconds |
46
+ ./spec/send_spec.rb[1:1] | passed | 0.00022 seconds |
47
+ ./spec/send_spec.rb[1:2] | passed | 0.00004 seconds |
48
+ ./spec/sorted_lru_files_spec.rb[1:1] | passed | 0.00009 seconds |
49
+ ./spec/sorted_lru_files_spec.rb[1:2] | passed | 0.00007 seconds |
49
50
  ./spec/sorted_lru_files_spec.rb[1:3] | passed | 0.00003 seconds |
50
- ./spec/sorted_lru_files_spec.rb[1:4] | passed | 0.00068 seconds |
51
+ ./spec/sorted_lru_files_spec.rb[1:4] | passed | 0.00005 seconds |
51
52
  ./spec/testable_spec.rb[1:1] | passed | 0.00003 seconds |
52
53
  ./spec/testable_spec.rb[2:1] | passed | 0.00003 seconds |
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_plugin_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.2
4
+ version: 3.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
@@ -79,20 +79,6 @@ dependencies:
79
79
  - - ">="
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
- - !ruby/object:Gem::Dependency
83
- name: pry
84
- requirement: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- version: '0'
89
- type: :runtime
90
- prerelease: false
91
- version_requirements: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- version: '0'
96
82
  - !ruby/object:Gem::Dependency
97
83
  name: sorted_set
98
84
  requirement: !ruby/object:Gem::Requirement
@@ -116,6 +102,7 @@ files:
116
102
  - ".rubocop.yml"
117
103
  - ATTIBUTION_NOTES.md
118
104
  - CHANGELOG.md
105
+ - FIXME.md
119
106
  - LICENSE.txt
120
107
  - README.md
121
108
  - Rakefile
@@ -182,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
169
  - !ruby/object:Gem::Version
183
170
  version: '0'
184
171
  requirements: []
185
- rubygems_version: 3.7.2
172
+ rubygems_version: 4.0.19
186
173
  specification_version: 4
187
174
  summary: Provides a framework for writing and testing Jekyll plugins
188
175
  test_files: