jekyll_pre 1.1.5 → 1.1.7
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 +55 -5
- data/CHANGELOG.md +6 -0
- data/README.md +27 -6
- data/Rakefile +3 -5
- data/jekyll_pre.gemspec +20 -32
- data/lib/jekyll_pre/version.rb +1 -3
- data/lib/jekyll_pre.rb +21 -74
- data/spec/pre_spec.rb +11 -13
- data/spec/spec_helper.rb +7 -9
- data/spec/status_persistence.txt +3 -3
- metadata +7 -36
- data/lib/jekyll_tag_helper.rb +0 -92
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97df025cc0565235360a3c42053ed994e5f33968145eef4008ae5b27a8df61fa
|
4
|
+
data.tar.gz: d8c1eba16949515b28e7696865307da8ba8e150d807f466f45e32322f1786576
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03bb017f63fe8cf7b780065f10e248727f4047c031c0c5d74f4a96721b95c3a4e30ba9288dc9ac176b5eeff4efb2a454e412da28a58a7489c246529fb2335ea4
|
7
|
+
data.tar.gz: 4fb5fd78dde215a9639438095fddae46c053f396edcd77cbd42662d9f3250c32928349effecc17688d377f2f09bab140f56c6af16cf061801d15667849ed2ebc
|
data/.rubocop.yml
CHANGED
@@ -1,13 +1,63 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require:
|
2
|
+
- rubocop-rspec
|
3
|
+
- rubocop-rake
|
4
4
|
|
5
5
|
AllCops:
|
6
6
|
Exclude:
|
7
|
-
|
8
|
-
|
7
|
+
- exe/**/*
|
8
|
+
- vendor/**/*
|
9
|
+
- Gemfile*
|
9
10
|
NewCops: enable
|
10
11
|
TargetRubyVersion: 2.6
|
11
12
|
|
13
|
+
Gemspec/DeprecatedAttributeAssignment:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Gemspec/RequireMFA:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Layout/HashAlignment:
|
20
|
+
Enabled: false
|
21
|
+
|
12
22
|
Layout/LineLength:
|
13
23
|
Max: 150
|
24
|
+
|
25
|
+
Metrics/AbcSize:
|
26
|
+
Max: 25
|
27
|
+
|
28
|
+
Metrics/BlockLength:
|
29
|
+
Exclude:
|
30
|
+
- jekyll_pre.gemspec
|
31
|
+
Max: 30
|
32
|
+
|
33
|
+
Metrics/CyclomaticComplexity:
|
34
|
+
Max: 15
|
35
|
+
|
36
|
+
Metrics/MethodLength:
|
37
|
+
Max: 30
|
38
|
+
|
39
|
+
Metrics/PerceivedComplexity:
|
40
|
+
Max: 15
|
41
|
+
|
42
|
+
Naming/FileName:
|
43
|
+
Exclude:
|
44
|
+
- Rakefile
|
45
|
+
|
46
|
+
Style/Documentation:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Style/FrozenStringLiteralComment:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
Style/TrailingCommaInHashLiteral:
|
53
|
+
EnforcedStyleForMultiline: comma
|
54
|
+
|
55
|
+
RSpec/FilePath:
|
56
|
+
IgnoreMethods: true
|
57
|
+
SpecSuffixOnly: true
|
58
|
+
|
59
|
+
RSpec/ExampleLength:
|
60
|
+
Max: 30
|
61
|
+
|
62
|
+
RSpec/MultipleExpectations:
|
63
|
+
Max: 15
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 1.1.7
|
2
|
+
* Fixed `noselect` tag content handling.
|
3
|
+
|
4
|
+
## 1.1.6
|
5
|
+
* Added `jekyll_plugin_support` as a dependency.
|
6
|
+
|
1
7
|
## 1.1.5
|
2
8
|
* Added `class` and `style` options to allow for specifying additional CSS classes and inline CSS
|
3
9
|
* Added `clear` option to ensure no images overlap the pre output
|
data/README.md
CHANGED
@@ -6,10 +6,20 @@ This Jekyll plugin provides 2 new Liquid tags that work together:
|
|
6
6
|
|
7
7
|
* A `pre` block tag that can optionally display a copy button.
|
8
8
|
```
|
9
|
-
{% pre [
|
9
|
+
{% pre [Options] [headline words] %}
|
10
10
|
Contents of pre tag
|
11
11
|
{% endpre %}
|
12
12
|
```
|
13
|
+
`Options` are:
|
14
|
+
- `clear` – Line break after floating HTML elements
|
15
|
+
- `class="class names"` – Apply CSS styles
|
16
|
+
- `copyButton` – Generate a copy button
|
17
|
+
- `dark` – Dark mode
|
18
|
+
- `label='This is a label'` – Apply text above pre tag
|
19
|
+
- `number` – Number the lines
|
20
|
+
- `shell` – Equivalent to `label='Shell'`
|
21
|
+
- `style` – Apply CSS styles
|
22
|
+
|
13
23
|
The generated <pre></pre> tag has an `data-lt-active="false"` attribute, so [LanguageTool](https://forum.languagetool.org/t/avoid-spell-check-on-certain-html-inputs-manually/3944) does not check the spelling or grammar of the contents.
|
14
24
|
* A `noselect` tag that can renders HTML content passed to it unselectable.
|
15
25
|
```
|
@@ -39,8 +49,9 @@ Below are the CSS declarations that I defined pertaining to the pre and noselect
|
|
39
49
|
}
|
40
50
|
```
|
41
51
|
|
52
|
+
|
42
53
|
## Additional Information
|
43
|
-
More information is available on [my
|
54
|
+
More information is available on [my website](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#jekyll_pre).
|
44
55
|
|
45
56
|
|
46
57
|
## Installation
|
@@ -57,10 +68,6 @@ And then execute:
|
|
57
68
|
|
58
69
|
$ bundle install
|
59
70
|
|
60
|
-
Or install it yourself as:
|
61
|
-
|
62
|
-
$ gem install jekyll_pre
|
63
|
-
|
64
71
|
|
65
72
|
## Usage
|
66
73
|
|
@@ -175,6 +182,20 @@ After checking out the repo, run `bin/setup` to install dependencies.
|
|
175
182
|
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
176
183
|
|
177
184
|
|
185
|
+
## Test
|
186
|
+
A test website is provided in the `demo` directory.
|
187
|
+
1. Set breakpoints.
|
188
|
+
|
189
|
+
2. Initiate a debug session from the command line:
|
190
|
+
```shell
|
191
|
+
$ bin/attach demo
|
192
|
+
```
|
193
|
+
|
194
|
+
3. Once the `Fast Debugger` signon appears, launch the Visual Studio Code launch configuration called `Attach rdebug-ide`.
|
195
|
+
|
196
|
+
4. View the generated website at [`http://localhost:4444`](http://localhost:4444)
|
197
|
+
|
198
|
+
|
178
199
|
### Build and Install Locally
|
179
200
|
To build and install this gem onto your local machine, run:
|
180
201
|
```shell
|
data/Rakefile
CHANGED
data/jekyll_pre.gemspec
CHANGED
@@ -1,48 +1,36 @@
|
|
1
|
-
|
1
|
+
require_relative 'lib/jekyll_pre/version'
|
2
2
|
|
3
|
-
require_relative "lib/jekyll_pre/version"
|
4
|
-
|
5
|
-
# rubocop:disable Metrics/BlockLength
|
6
3
|
Gem::Specification.new do |spec|
|
7
|
-
github =
|
4
|
+
github = 'https://github.com/mslinn/jekyll_pre'
|
8
5
|
|
9
|
-
spec.authors = [
|
10
|
-
spec.bindir =
|
6
|
+
spec.authors = ['Mike Slinn']
|
7
|
+
spec.bindir = 'exe'
|
11
8
|
spec.description = <<~END_OF_DESC
|
12
9
|
Jekyll tags pre and noselect, for HTML <pre/> tag, prompts and unselectable text. Can number lines.
|
13
10
|
END_OF_DESC
|
14
|
-
spec.email = [
|
15
|
-
spec.files = Dir[
|
16
|
-
spec.homepage =
|
17
|
-
spec.license =
|
11
|
+
spec.email = ['mslinn@mslinn.com']
|
12
|
+
spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
|
13
|
+
spec.homepage = 'https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#pre'
|
14
|
+
spec.license = 'MIT'
|
18
15
|
spec.metadata = {
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
'allowed_push_host' => 'https://rubygems.org',
|
17
|
+
'bug_tracker_uri' => "#{github}/issues",
|
18
|
+
'changelog_uri' => "#{github}/CHANGELOG.md",
|
19
|
+
'homepage_uri' => spec.homepage,
|
20
|
+
'source_code_uri' => github,
|
24
21
|
}
|
25
|
-
spec.name =
|
22
|
+
spec.name = 'jekyll_pre'
|
26
23
|
spec.post_install_message = <<~END_MESSAGE
|
27
24
|
|
28
25
|
Thanks for installing #{spec.name}!
|
29
26
|
|
30
27
|
END_MESSAGE
|
31
|
-
spec.require_paths = [
|
32
|
-
spec.required_ruby_version =
|
33
|
-
spec.summary =
|
34
|
-
spec.test_files = spec.files.grep(%r
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
spec.required_ruby_version = '>= 2.6.0'
|
30
|
+
spec.summary = 'Jekyll tags pre and noselect, for HTML <pre/> tag, prompts and unselectable text. Can number lines.'
|
31
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
35
32
|
spec.version = JekyllPreVersion::VERSION
|
36
33
|
|
37
|
-
spec.add_dependency
|
38
|
-
spec.add_dependency
|
39
|
-
spec.add_dependency "key-value-parser"
|
40
|
-
spec.add_dependency "shellwords"
|
41
|
-
|
42
|
-
# spec.add_development_dependency "debase"
|
43
|
-
# spec.add_development_dependency "rubocop-jekyll"
|
44
|
-
# spec.add_development_dependency "rubocop-rake"
|
45
|
-
# spec.add_development_dependency "rubocop-rspec"
|
46
|
-
# spec.add_development_dependency "ruby-debug-ide"
|
34
|
+
spec.add_dependency 'jekyll', '>= 3.5.0'
|
35
|
+
spec.add_dependency 'jekyll_plugin_support', '~> 0.4.0'
|
47
36
|
end
|
48
|
-
# rubocop:enable Metrics/BlockLength
|
data/lib/jekyll_pre/version.rb
CHANGED
data/lib/jekyll_pre.rb
CHANGED
@@ -1,37 +1,13 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require 'liquid'
|
4
2
|
require 'jekyll_plugin_logger'
|
5
|
-
require '
|
6
|
-
require 'shellwords'
|
3
|
+
require 'jekyll_plugin_support'
|
7
4
|
require_relative 'jekyll_pre/version'
|
8
|
-
require_relative 'jekyll_tag_helper'
|
9
5
|
|
10
6
|
module JekyllPluginPreName
|
11
|
-
PLUGIN_NAME = 'jekyll_pre'
|
7
|
+
PLUGIN_NAME = 'jekyll_pre'.freeze
|
12
8
|
end
|
13
9
|
|
14
|
-
|
15
|
-
# \\{% pre %}
|
16
|
-
# Content here
|
17
|
-
# \\{% endpre %}
|
18
|
-
#
|
19
|
-
# \\{% pre copyButton %}
|
20
|
-
# Content here
|
21
|
-
# \\{% endpre %}"""
|
22
|
-
#
|
23
|
-
# \\{% pre shell %}
|
24
|
-
# Content here
|
25
|
-
# \\{% endpre %}
|
26
|
-
#
|
27
|
-
# \\{% pre copyButton shell %}
|
28
|
-
# Content here
|
29
|
-
# \\{% endpre %}
|
30
|
-
#
|
31
|
-
# \\{% pre copyButton label %}
|
32
|
-
# Content here
|
33
|
-
# \\{% endpre %}"""
|
34
|
-
class PreTagBlock < Liquid::Block
|
10
|
+
class PreTagBlock < JekyllSupport::JekyllBlock
|
35
11
|
@@prefix = "<button class='copyBtn' data-clipboard-target="
|
36
12
|
@@suffix = " title='Copy to clipboard'><img src='/assets/images/clippy.svg' " \
|
37
13
|
"alt='Copy to clipboard' style='width: 13px'></button>"
|
@@ -44,7 +20,7 @@ class PreTagBlock < Liquid::Block
|
|
44
20
|
"#{@@prefix}'##{pre_id}'#{@@suffix}"
|
45
21
|
end
|
46
22
|
|
47
|
-
def self.make_pre(make_copy_button, number_lines, label, dark, highlight_pattern, css_class, style, clear, content) # rubocop:disable Metrics/ParameterLists
|
23
|
+
def self.make_pre(make_copy_button, number_lines, label, dark, highlight_pattern, css_class, style, clear, content) # rubocop:disable Metrics/ParameterLists
|
48
24
|
pre_clear = label_clear = ''
|
49
25
|
if clear
|
50
26
|
if label.to_s.empty?
|
@@ -67,10 +43,13 @@ class PreTagBlock < Liquid::Block
|
|
67
43
|
copy_button = make_copy_button ? PreTagBlock.make_copy_button(pre_id) : ''
|
68
44
|
content = PreTagBlock.highlight(content, highlight_pattern) if highlight_pattern
|
69
45
|
content = PreTagBlock.number_content(content) if number_lines
|
70
|
-
|
46
|
+
|
47
|
+
classes = "maxOneScreenHigh copyContainer#{dark}#{pre_clear}#{css_class}"
|
48
|
+
pre_content = "#{copy_button}#{content.strip}"
|
49
|
+
"#{label}<pre data-lt-active='false' class='#{classes}'#{style} id='#{pre_id}'>#{pre_content}</pre>"
|
71
50
|
end
|
72
51
|
|
73
|
-
def self.number_content(content)
|
52
|
+
def self.number_content(content)
|
74
53
|
lines = content.split("\n")
|
75
54
|
digits = lines.length.to_s.length
|
76
55
|
i = 0
|
@@ -84,65 +63,33 @@ class PreTagBlock < Liquid::Block
|
|
84
63
|
result
|
85
64
|
end
|
86
65
|
|
87
|
-
|
88
|
-
|
89
|
-
# @param _tokens [Liquid::ParseContext] tokenized command line
|
90
|
-
# By default it has two keys: :locale and :line_numbers, the first is a Liquid::I18n object, and the second,
|
91
|
-
# a boolean parameter that determines if error messages should display the line number the error occurred.
|
92
|
-
# This argument is used mostly to display localized error messages on Liquid built-in Tags and Filters.
|
93
|
-
# See https://github.com/Shopify/liquid/wiki/Liquid-for-Programmers#create-your-own-tags
|
94
|
-
# @return [void]
|
95
|
-
def initialize(_tag_name, markup, _tokens)
|
96
|
-
super
|
97
|
-
markup = '' if markup.nil?
|
98
|
-
markup.strip!
|
99
|
-
|
100
|
-
@logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
101
|
-
@helper = JekyllTagHelper.new(tag_name, markup, @logger)
|
102
|
-
end
|
103
|
-
|
104
|
-
# Method prescribed by the Jekyll plugin lifecycle.
|
105
|
-
# @param liquid_context [Liquid::Context]
|
106
|
-
# @return [String]
|
107
|
-
def render(liquid_context) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
108
|
-
content = super
|
109
|
-
@helper.liquid_context = liquid_context
|
66
|
+
def render_impl(text)
|
67
|
+
text.strip!
|
110
68
|
|
111
|
-
@clear = @helper.parameter_specified?
|
112
|
-
@class = @helper.parameter_specified?
|
69
|
+
@clear = @helper.parameter_specified? 'clear'
|
70
|
+
@class = @helper.parameter_specified? 'class'
|
113
71
|
@highlight = @helper.parameter_specified? 'highlight'
|
114
72
|
@make_copy_button = @helper.parameter_specified? 'copyButton'
|
115
73
|
@number_lines = @helper.parameter_specified? 'number'
|
116
74
|
@dark = ' dark' if @helper.parameter_specified? 'dark'
|
75
|
+
@style = @helper.parameter_specified? 'style'
|
117
76
|
@label = @helper.parameter_specified? 'label'
|
118
|
-
@style = @helper.parameter_specified?('style')
|
119
77
|
|
120
78
|
# If a label was specified, use it, otherwise concatenate any dangling parameters and use that as the label
|
121
|
-
@label ||= @helper.
|
79
|
+
@label ||= @helper.argv.join(' ')
|
122
80
|
|
123
81
|
@logger.debug { "@make_copy_button = '#{@make_copy_button}'; @label = '#{@label}'" }
|
124
|
-
|
82
|
+
self.class.make_pre(@make_copy_button, @number_lines, @label, @dark, @highlight, @class, @style, @clear, text)
|
125
83
|
end
|
126
84
|
end
|
127
85
|
|
128
86
|
# """\\{% noselect %} or \\{% noselect this all gets copied.
|
129
87
|
# Also, space before the closing percent is signficant %}"""
|
130
|
-
class UnselectableTag <
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
def initialize(_tag_name, markup, _tokens)
|
136
|
-
super
|
137
|
-
@logger = PluginMetaLogger.instance.new_logger(self)
|
138
|
-
|
139
|
-
@markup = markup
|
140
|
-
@markup = '$ ' if @markup.nil? || @markup.empty?
|
141
|
-
@logger.debug { "UnselectableTag: markup= '#{@markup}'" }
|
142
|
-
end
|
143
|
-
|
144
|
-
def render(_)
|
145
|
-
"<span class='unselectable'>#{@markup}</span>"
|
88
|
+
class UnselectableTag < JekyllSupport::JekyllTag
|
89
|
+
def render_impl
|
90
|
+
text = @argument_string
|
91
|
+
text = '$ ' if text.nil? || text.empty?
|
92
|
+
"<span class='unselectable'>#{text}</span>"
|
146
93
|
end
|
147
94
|
end
|
148
95
|
|
data/spec/pre_spec.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
6
|
-
require "shellwords"
|
7
|
-
require_relative "../lib/jekyll_pre"
|
1
|
+
require 'fileutils'
|
2
|
+
require 'jekyll'
|
3
|
+
require 'key_value_parser'
|
4
|
+
require 'shellwords'
|
5
|
+
require_relative '../lib/jekyll_pre'
|
8
6
|
|
9
7
|
RSpec.describe(PreTagBlock) do
|
10
|
-
it
|
11
|
-
argv = Shellwords.split
|
8
|
+
it 'parses arguments' do
|
9
|
+
argv = Shellwords.split 'number copyButton shell'
|
12
10
|
options = KeyValueParser.new.parse(argv)
|
13
11
|
# puts options.map { |k, v| "#{k} = #{v}" }.join("\n")
|
14
12
|
|
@@ -17,7 +15,7 @@ RSpec.describe(PreTagBlock) do
|
|
17
15
|
expect(options[:shell]).to be true
|
18
16
|
end
|
19
17
|
|
20
|
-
it
|
18
|
+
it 'numbers content lines' do
|
21
19
|
content = <<~END_CONTENT
|
22
20
|
Line 1
|
23
21
|
Line 2
|
@@ -30,7 +28,7 @@ RSpec.describe(PreTagBlock) do
|
|
30
28
|
Line 9
|
31
29
|
Line 10
|
32
30
|
END_CONTENT
|
33
|
-
numbered_content =
|
31
|
+
numbered_content = described_class.number_content(content)
|
34
32
|
expected_content = <<~END_CONTENT
|
35
33
|
<span class='unselectable numbered_line'> 1: </span>Line 1
|
36
34
|
<span class='unselectable numbered_line'> 2: </span> Line 2
|
@@ -46,7 +44,7 @@ RSpec.describe(PreTagBlock) do
|
|
46
44
|
expect(numbered_content).to eq(expected_content)
|
47
45
|
end
|
48
46
|
|
49
|
-
it
|
47
|
+
it 'highlights regex patterns' do
|
50
48
|
content = <<~END_CONTENT
|
51
49
|
Line 1
|
52
50
|
Line 2
|
@@ -59,7 +57,7 @@ RSpec.describe(PreTagBlock) do
|
|
59
57
|
Line 9
|
60
58
|
Line 10
|
61
59
|
END_CONTENT
|
62
|
-
highlighted =
|
60
|
+
highlighted = described_class.highlight(content, '.*2').split("\n")[1]
|
63
61
|
expect(highlighted).to eq("<span class='bg_yellow'> Line 2</span>")
|
64
62
|
end
|
65
63
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,19 +1,17 @@
|
|
1
|
-
|
1
|
+
require 'jekyll'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'key_value_parser'
|
4
|
+
require 'shellwords'
|
2
5
|
|
3
|
-
|
4
|
-
require "fileutils"
|
5
|
-
require "key_value_parser"
|
6
|
-
require "shellwords"
|
7
|
-
|
8
|
-
require_relative "../lib/jekyll_pre"
|
6
|
+
require_relative '../lib/jekyll_pre'
|
9
7
|
|
10
8
|
Jekyll.logger.log_level = :info
|
11
9
|
|
12
10
|
RSpec.configure do |config|
|
13
11
|
config.filter_run :focus
|
14
|
-
config.order =
|
12
|
+
# config.order = 'random'
|
15
13
|
config.run_all_when_everything_filtered = true
|
16
14
|
|
17
15
|
# See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
|
18
|
-
config.example_status_persistence_file_path =
|
16
|
+
config.example_status_persistence_file_path = 'spec/status_persistence.txt'
|
19
17
|
end
|
data/spec/status_persistence.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
example_id | status | run_time |
|
2
2
|
----------------------- | ------ | --------------- |
|
3
|
-
./spec/pre_spec.rb[1:1] | passed | 0.
|
4
|
-
./spec/pre_spec.rb[1:2] | passed | 0.
|
5
|
-
./spec/pre_spec.rb[1:3] | passed | 0.
|
3
|
+
./spec/pre_spec.rb[1:1] | passed | 0.00075 seconds |
|
4
|
+
./spec/pre_spec.rb[1:2] | passed | 0.00044 seconds |
|
5
|
+
./spec/pre_spec.rb[1:3] | passed | 0.00018 seconds |
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll_pre
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Slinn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -25,47 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.5.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: jekyll_plugin_support
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: key-value-parser
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
31
|
+
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
33
|
+
version: 0.4.0
|
48
34
|
type: :runtime
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
|
-
- - "
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: shellwords
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
38
|
+
- - "~>"
|
67
39
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
40
|
+
version: 0.4.0
|
69
41
|
description: 'Jekyll tags pre and noselect, for HTML <pre/> tag, prompts and unselectable
|
70
42
|
text. Can number lines.
|
71
43
|
|
@@ -84,7 +56,6 @@ files:
|
|
84
56
|
- jekyll_pre.gemspec
|
85
57
|
- lib/jekyll_pre.rb
|
86
58
|
- lib/jekyll_pre/version.rb
|
87
|
-
- lib/jekyll_tag_helper.rb
|
88
59
|
- spec/pre_spec.rb
|
89
60
|
- spec/spec_helper.rb
|
90
61
|
- spec/status_persistence.txt
|
data/lib/jekyll_tag_helper.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'shellwords'
|
4
|
-
require 'key_value_parser'
|
5
|
-
|
6
|
-
# Parses arguments and options
|
7
|
-
class JekyllTagHelper
|
8
|
-
attr_reader :argv, :liquid_context, :logger, :params, :tag_name
|
9
|
-
|
10
|
-
def self.escape_html(string)
|
11
|
-
string.gsub('&', '&')
|
12
|
-
.gsub('{', '{')
|
13
|
-
.gsub('}', '}')
|
14
|
-
.gsub('<', '<')
|
15
|
-
end
|
16
|
-
|
17
|
-
# Expand a environment variable reference
|
18
|
-
def self.expand_env(str, die_if_undefined: false)
|
19
|
-
str.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/) do
|
20
|
-
envar = Regexp.last_match(1)
|
21
|
-
raise FlexibleError, "flexible_include error: #{envar} is undefined".red, [] if !ENV.key?(envar) && die_if_undefined # Suppress stack trace
|
22
|
-
|
23
|
-
ENV[envar]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# strip leading and trailing quotes if present
|
28
|
-
def self.remove_quotes(string)
|
29
|
-
string.strip.gsub(/\A'|\A"|'\Z|"\Z/, '').strip if string
|
30
|
-
end
|
31
|
-
|
32
|
-
def initialize(tag_name, markup, logger)
|
33
|
-
@tag_name = tag_name
|
34
|
-
@argv = Shellwords.split(markup)
|
35
|
-
@keys_values = KeyValueParser.new.parse(@argv) # Hash[Symbol, String|Boolean]
|
36
|
-
@logger = logger
|
37
|
-
@logger.debug { "@keys_values='#{@keys_values}'" }
|
38
|
-
end
|
39
|
-
|
40
|
-
def delete_parameter(name)
|
41
|
-
@params.delete(name)
|
42
|
-
@argv.delete_if { |x| x.start_with? name }
|
43
|
-
@keys_values.delete(name.to_sym)
|
44
|
-
end
|
45
|
-
|
46
|
-
# @return if parameter was specified, returns value and removes it from the available tokens
|
47
|
-
def parameter_specified?(name)
|
48
|
-
value = @keys_values[name.to_sym]
|
49
|
-
delete_parameter(name)
|
50
|
-
value
|
51
|
-
end
|
52
|
-
|
53
|
-
PREDEFINED_SCOPE_KEYS = [:include, :page].freeze
|
54
|
-
|
55
|
-
# Finds variables defined in an invoking include, or maybe somewhere else
|
56
|
-
# @return variable value or nil
|
57
|
-
def dereference_include_variable(name)
|
58
|
-
@liquid_context.scopes.each do |scope|
|
59
|
-
next if PREDEFINED_SCOPE_KEYS.include? scope.keys.first
|
60
|
-
|
61
|
-
value = scope[name]
|
62
|
-
return value if value
|
63
|
-
end
|
64
|
-
nil
|
65
|
-
end
|
66
|
-
|
67
|
-
# @return value of variable, or the empty string
|
68
|
-
def dereference_variable(name)
|
69
|
-
value = @liquid_context[name] # Finds variables named like 'include.my_variable', found in @liquid_context.scopes.first
|
70
|
-
value ||= @page[name] if @page # Finds variables named like 'page.my_variable'
|
71
|
-
value ||= dereference_include_variable(name)
|
72
|
-
value ||= ''
|
73
|
-
value
|
74
|
-
end
|
75
|
-
|
76
|
-
# Sets @params by replacing any Liquid variable names with their values
|
77
|
-
def liquid_context=(context)
|
78
|
-
@liquid_context = context
|
79
|
-
@params = @keys_values.map { |k, _v| lookup_variable(k) }
|
80
|
-
end
|
81
|
-
|
82
|
-
def lookup_variable(symbol)
|
83
|
-
string = symbol.to_s
|
84
|
-
return string unless string.start_with?('{{') && string.end_with?('}}')
|
85
|
-
|
86
|
-
dereference_variable(string.delete_prefix('{{').delete_suffix('}}'))
|
87
|
-
end
|
88
|
-
|
89
|
-
def page
|
90
|
-
@liquid_context.registers[:page]
|
91
|
-
end
|
92
|
-
end
|