jekyll_pre 1.1.4 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +55 -5
- data/CHANGELOG.md +8 -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 +47 -88
- data/spec/pre_spec.rb +11 -13
- data/spec/spec_helper.rb +7 -9
- data/spec/status_persistence.txt +3 -3
- metadata +12 -68
- data/lib/jekyll_tag_helper.rb +0 -90
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 342dc6a4bc2860320f78fa197b5c8543ce387f6a4ab848133bdedae1cb3b12a9
|
4
|
+
data.tar.gz: 06bb60d730294296d468e0191e77fb0679427f35ec635121fa0c45d112ced8c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c0b0e9cd0a3d24e8f33834554e9ad5c306e8a679c230b0d2419fef758d329b17fed575bd02d68b8a146caf43b1709797252d123b9778deb7546d098a078d43b
|
7
|
+
data.tar.gz: 5e3bdd70cbe31a57330cf8e820965f2f13382e378cbd612a890a08c67cf3ea2222fe01630caf58ec9bc6612e5421b7e03483d9417a56655bb2cf815477a6dff1
|
data/.rubocop.yml
CHANGED
@@ -1,13 +1,63 @@
|
|
1
|
-
require:
|
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,11 @@
|
|
1
|
+
## 1.1.6
|
2
|
+
* Added `jekyll_plugin_support` as a dependency.
|
3
|
+
|
4
|
+
|
5
|
+
## 1.1.5
|
6
|
+
* Added `class` and `style` options to allow for specifying additional CSS classes and inline CSS
|
7
|
+
* Added `clear` option to ensure no images overlap the pre output
|
8
|
+
|
1
9
|
## 1.1.4
|
2
10
|
* Added `highlight` regex option
|
3
11
|
* Now using `lib/jekyll_tag_helper.rb` to parse markup
|
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,63 +1,52 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
|
5
|
-
require 'key_value_parser'
|
6
|
-
require "shellwords"
|
7
|
-
require_relative "jekyll_pre/version"
|
8
|
-
require_relative "jekyll_tag_helper"
|
1
|
+
require 'liquid'
|
2
|
+
require 'jekyll_plugin_logger'
|
3
|
+
require 'jekyll_plugin_support'
|
4
|
+
require_relative 'jekyll_pre/version'
|
9
5
|
|
10
6
|
module JekyllPluginPreName
|
11
|
-
PLUGIN_NAME =
|
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>"
|
38
14
|
|
39
15
|
def self.highlight(content, pattern)
|
40
|
-
content.gsub(Regexp
|
16
|
+
content.gsub(Regexp.new(pattern), "<span class='bg_yellow'>\\0</span>")
|
41
17
|
end
|
42
18
|
|
43
19
|
def self.make_copy_button(pre_id)
|
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, content) # rubocop:disable Metrics/ParameterLists
|
48
|
-
|
23
|
+
def self.make_pre(make_copy_button, number_lines, label, dark, highlight_pattern, css_class, style, clear, content) # rubocop:disable Metrics/ParameterLists
|
24
|
+
pre_clear = label_clear = ''
|
25
|
+
if clear
|
26
|
+
if label.to_s.empty?
|
27
|
+
pre_clear = ' clear'
|
28
|
+
else
|
29
|
+
label_clear = ' clear'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
css_class = css_class ? " #{css_class}" : ''
|
33
|
+
style = style ? " style='#{style}'" : ''
|
34
|
+
dark_label = ' darkLabel' if dark
|
49
35
|
label = if label.to_s.empty?
|
50
|
-
|
51
|
-
elsif label.to_s.downcase.strip ==
|
52
|
-
"<div class='codeLabel unselectable#{dark_label}' data-lt-active='false'>Shell</div>"
|
36
|
+
''
|
37
|
+
elsif label.to_s.downcase.strip == 'shell'
|
38
|
+
"<div class='codeLabel unselectable#{dark_label}#{label_clear}' data-lt-active='false'>Shell</div>"
|
53
39
|
else
|
54
|
-
"<div class='codeLabel unselectable#{dark_label}' data-lt-active='false'>#{label}</div>"
|
40
|
+
"<div class='codeLabel unselectable#{dark_label}#{label_clear}' data-lt-active='false'>#{label}</div>"
|
55
41
|
end
|
56
42
|
pre_id = "id#{SecureRandom.hex(6)}"
|
57
|
-
copy_button = make_copy_button ? PreTagBlock.make_copy_button(pre_id) :
|
43
|
+
copy_button = make_copy_button ? PreTagBlock.make_copy_button(pre_id) : ''
|
58
44
|
content = PreTagBlock.highlight(content, highlight_pattern) if highlight_pattern
|
59
45
|
content = PreTagBlock.number_content(content) if number_lines
|
60
|
-
|
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>"
|
61
50
|
end
|
62
51
|
|
63
52
|
def self.number_content(content)
|
@@ -66,7 +55,7 @@ class PreTagBlock < Liquid::Block
|
|
66
55
|
i = 0
|
67
56
|
numbered_content = lines.map do |line|
|
68
57
|
i += 1
|
69
|
-
number = i.to_s.rjust(digits,
|
58
|
+
number = i.to_s.rjust(digits, ' ')
|
70
59
|
"<span class='unselectable numbered_line'> #{number}: </span>#{line}"
|
71
60
|
end
|
72
61
|
result = numbered_content.join("\n")
|
@@ -74,65 +63,35 @@ class PreTagBlock < Liquid::Block
|
|
74
63
|
result
|
75
64
|
end
|
76
65
|
|
77
|
-
|
78
|
-
|
79
|
-
# @param _tokens [Liquid::ParseContext] tokenized command line
|
80
|
-
# By default it has two keys: :locale and :line_numbers, the first is a Liquid::I18n object, and the second,
|
81
|
-
# a boolean parameter that determines if error messages should display the line number the error occurred.
|
82
|
-
# This argument is used mostly to display localized error messages on Liquid built-in Tags and Filters.
|
83
|
-
# See https://github.com/Shopify/liquid/wiki/Liquid-for-Programmers#create-your-own-tags
|
84
|
-
# @return [void]
|
85
|
-
def initialize(_tag_name, markup, _tokens)
|
86
|
-
super
|
87
|
-
markup = "" if markup.nil?
|
88
|
-
markup.strip!
|
89
|
-
|
90
|
-
@logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
91
|
-
@helper = JekyllTagHelper.new(tag_name, markup, @logger)
|
92
|
-
end
|
66
|
+
def render_impl(text)
|
67
|
+
text.strip!
|
93
68
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
@helper.
|
100
|
-
|
101
|
-
@
|
102
|
-
@make_copy_button = @helper.parameter_specified? "copyButton"
|
103
|
-
@number_lines = @helper.parameter_specified? "number"
|
104
|
-
@dark = " dark" if @helper.parameter_specified? "dark"
|
105
|
-
@label = @helper.parameter_specified? "label"
|
69
|
+
@clear = @helper.parameter_specified? 'clear'
|
70
|
+
@class = @helper.parameter_specified? 'class'
|
71
|
+
@highlight = @helper.parameter_specified? 'highlight'
|
72
|
+
@make_copy_button = @helper.parameter_specified? 'copyButton'
|
73
|
+
@number_lines = @helper.parameter_specified? 'number'
|
74
|
+
@dark = ' dark' if @helper.parameter_specified? 'dark'
|
75
|
+
@style = @helper.parameter_specified? 'style'
|
76
|
+
@label = @helper.parameter_specified? 'label'
|
106
77
|
|
107
78
|
# If a label was specified, use it, otherwise concatenate any dangling parameters and use that as the label
|
108
|
-
@label ||= @helper.
|
79
|
+
@label ||= @helper.argv.join(' ')
|
109
80
|
|
110
81
|
@logger.debug { "@make_copy_button = '#{@make_copy_button}'; @label = '#{@label}'" }
|
111
|
-
|
82
|
+
self.class.make_pre(@make_copy_button, @number_lines, @label, @dark, @highlight, @class, @style, @clear, text)
|
112
83
|
end
|
113
84
|
end
|
114
85
|
|
115
86
|
# """\\{% noselect %} or \\{% noselect this all gets copied.
|
116
87
|
# Also, space before the closing percent is signficant %}"""
|
117
|
-
class UnselectableTag <
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
# @return [void]
|
122
|
-
def initialize(_tag_name, markup, _tokens)
|
123
|
-
super
|
124
|
-
@logger = PluginMetaLogger.instance.new_logger(self)
|
125
|
-
|
126
|
-
@markup = markup
|
127
|
-
@markup = "$ " if @markup.nil? || @markup.empty?
|
128
|
-
@logger.debug { "UnselectableTag: markup= '#{@markup}'" }
|
129
|
-
end
|
130
|
-
|
131
|
-
def render(_)
|
132
|
-
"<span class='unselectable'>#{@markup}</span>"
|
88
|
+
class UnselectableTag < JekyllSupport::JekyllTag
|
89
|
+
def render_impl
|
90
|
+
text = @helper.argv.join(' ').strip
|
91
|
+
"<span class='unselectable'>#{text}</span>"
|
133
92
|
end
|
134
93
|
end
|
135
94
|
|
136
95
|
PluginMetaLogger.instance.info { "Loaded #{JekyllPluginPreName::PLUGIN_NAME} v#{JekyllPreVersion::VERSION} plugin." }
|
137
|
-
Liquid::Template.register_tag(
|
138
|
-
Liquid::Template.register_tag(
|
96
|
+
Liquid::Template.register_tag('pre', PreTagBlock)
|
97
|
+
Liquid::Template.register_tag('noselect', UnselectableTag)
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Slinn
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -25,79 +25,23 @@ 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
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
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
|
-
- - ">="
|
31
|
+
- - "~>"
|
60
32
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
33
|
+
version: 0.4.0
|
62
34
|
type: :runtime
|
63
35
|
prerelease: false
|
64
36
|
version_requirements: !ruby/object:Gem::Requirement
|
65
37
|
requirements:
|
66
|
-
- - "
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: debase
|
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: ruby-debug-ide
|
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
|
-
- - ">="
|
38
|
+
- - "~>"
|
95
39
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
40
|
+
version: 0.4.0
|
97
41
|
description: 'Jekyll tags pre and noselect, for HTML <pre/> tag, prompts and unselectable
|
98
42
|
text. Can number lines.
|
99
43
|
|
100
|
-
'
|
44
|
+
'
|
101
45
|
email:
|
102
46
|
- mslinn@mslinn.com
|
103
47
|
executables: []
|
@@ -112,7 +56,6 @@ files:
|
|
112
56
|
- jekyll_pre.gemspec
|
113
57
|
- lib/jekyll_pre.rb
|
114
58
|
- lib/jekyll_pre/version.rb
|
115
|
-
- lib/jekyll_tag_helper.rb
|
116
59
|
- spec/pre_spec.rb
|
117
60
|
- spec/spec_helper.rb
|
118
61
|
- spec/status_persistence.txt
|
@@ -143,8 +86,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
86
|
- !ruby/object:Gem::Version
|
144
87
|
version: '0'
|
145
88
|
requirements: []
|
146
|
-
rubygems_version: 3.
|
147
|
-
signing_key:
|
89
|
+
rubygems_version: 3.3.3
|
90
|
+
signing_key:
|
148
91
|
specification_version: 4
|
149
92
|
summary: Jekyll tags pre and noselect, for HTML <pre/> tag, prompts and unselectable
|
150
93
|
text. Can number lines.
|
@@ -152,3 +95,4 @@ test_files:
|
|
152
95
|
- spec/pre_spec.rb
|
153
96
|
- spec/spec_helper.rb
|
154
97
|
- spec/status_persistence.txt
|
98
|
+
...
|
data/lib/jekyll_tag_helper.rb
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "shellwords"
|
4
|
-
require 'key_value_parser'
|
5
|
-
|
6
|
-
class JekyllTagHelper
|
7
|
-
attr_reader :argv, :liquid_context, :logger, :params, :tag_name
|
8
|
-
|
9
|
-
def self.escape_html(string)
|
10
|
-
string.gsub("&", "&")
|
11
|
-
.gsub("{", "{")
|
12
|
-
.gsub("}", "}")
|
13
|
-
.gsub("<", "<")
|
14
|
-
end
|
15
|
-
|
16
|
-
# Expand a environment variable reference
|
17
|
-
def self.expand_env(str, die_if_undefined=false)
|
18
|
-
str.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/) do
|
19
|
-
envar = Regexp.last_match(1)
|
20
|
-
raise FlexibleError, "flexible_include error: #{envar} is undefined".red, [] if !ENV.key?(envar) && die_if_undefined # Suppress stack trace
|
21
|
-
ENV[envar]
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# strip leading and trailing quotes if present
|
26
|
-
def self.remove_quotes(string)
|
27
|
-
string.strip.gsub(/\A'|\A"|'\Z|"\Z/, '').strip if string
|
28
|
-
end
|
29
|
-
|
30
|
-
def initialize(tag_name, markup, logger)
|
31
|
-
@tag_name = tag_name
|
32
|
-
@argv = Shellwords.split(markup)
|
33
|
-
@keys_values = KeyValueParser.new.parse(@argv) # Hash[Symbol, String|Boolean]
|
34
|
-
@logger = logger
|
35
|
-
@logger.debug { "@keys_values='#{@keys_values}'" }
|
36
|
-
end
|
37
|
-
|
38
|
-
def delete_parameter(name)
|
39
|
-
@params.delete(name)
|
40
|
-
@argv.delete_if { |x| x.start_with? name }
|
41
|
-
@keys_values.delete(name.to_sym)
|
42
|
-
end
|
43
|
-
|
44
|
-
# @return if parameter was specified, returns value and removes it from the available tokens
|
45
|
-
def parameter_specified?(name)
|
46
|
-
value = @keys_values[name.to_sym]
|
47
|
-
delete_parameter(name)
|
48
|
-
value
|
49
|
-
end
|
50
|
-
|
51
|
-
PREDEFINED_SCOPE_KEYS = [:include, :page].freeze
|
52
|
-
|
53
|
-
# Finds variables defined in an invoking include, or maybe somewhere else
|
54
|
-
# @return variable value or nil
|
55
|
-
def dereference_include_variable(name)
|
56
|
-
@liquid_context.scopes.each do |scope|
|
57
|
-
next if PREDEFINED_SCOPE_KEYS.include? scope.keys.first
|
58
|
-
|
59
|
-
value = scope[name]
|
60
|
-
return value if value
|
61
|
-
end
|
62
|
-
nil
|
63
|
-
end
|
64
|
-
|
65
|
-
# @return value of variable, or the empty string
|
66
|
-
def dereference_variable(name)
|
67
|
-
value = @liquid_context[name] # Finds variables named like 'include.my_variable', found in @liquid_context.scopes.first
|
68
|
-
value ||= @page[name] if @page # Finds variables named like 'page.my_variable'
|
69
|
-
value ||= dereference_include_variable(name)
|
70
|
-
value ||= ""
|
71
|
-
value
|
72
|
-
end
|
73
|
-
|
74
|
-
# Sets @params by replacing any Liquid variable names with their values
|
75
|
-
def liquid_context=(context)
|
76
|
-
@liquid_context = context
|
77
|
-
@params = @keys_values.map { |k, _v| lookup_variable(k) }
|
78
|
-
end
|
79
|
-
|
80
|
-
def lookup_variable(symbol)
|
81
|
-
string = symbol.to_s
|
82
|
-
return string unless string.start_with?("{{") && string.end_with?("}}")
|
83
|
-
|
84
|
-
dereference_variable(string.delete_prefix("{{").delete_suffix("}}"))
|
85
|
-
end
|
86
|
-
|
87
|
-
def page
|
88
|
-
@liquid_context.registers[:page]
|
89
|
-
end
|
90
|
-
end
|