jekyll_href 1.1.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +68 -13
- data/CHANGELOG.md +9 -0
- data/README.md +63 -11
- data/Rakefile +2 -1
- data/jekyll_href.gemspec +2 -5
- data/lib/jekyll_href/version.rb +1 -1
- data/lib/jekyll_href.rb +24 -33
- data/spec/href_spec.rb +29 -30
- data/spec/status_persistence.txt +13 -13
- metadata +8 -45
- data/lib/jekyll_tag_helper2.rb +0 -94
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22db125f99912c6bd0a7cbbaa15ca8311cc7914a80ecbe6a828535ad5844fa96
|
4
|
+
data.tar.gz: 3ce4d813af1541bdae8269fa370233ffe21c890de48da1e8e400eba67be59823
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f4a20b4e784614fb2e21a29c274fe5a1d69f522ae728772860c8933d27305c16aa03cd4b4d2a15b49c0d65da8ce5bf5e3ca61171c6d27a073a783046b0f6c89
|
7
|
+
data.tar.gz: b5eceadcf6aabfa9f80459f79848af9176cd81dd17e073de61b8e21dc4f6ba3a09ed197d029773411a0a9ca22bf1df74119729675f6c1d4736cbeba173038529
|
data/.rubocop.yml
CHANGED
@@ -1,19 +1,36 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
|
1
|
+
require:
|
2
|
+
# - rubocop-jekyll
|
3
|
+
- rubocop-md
|
4
|
+
- rubocop-performance
|
5
|
+
- rubocop-rake
|
6
|
+
- rubocop-rspec
|
7
|
+
|
8
|
+
# inherit_gem:
|
9
|
+
# rubocop-jekyll: .rubocop.yml
|
4
10
|
|
5
11
|
AllCops:
|
6
12
|
Exclude:
|
7
|
-
|
8
|
-
|
13
|
+
- demo/_site/**/*
|
14
|
+
- exe/**/*
|
15
|
+
- vendor/**/*
|
16
|
+
- Gemfile*
|
9
17
|
NewCops: enable
|
10
18
|
TargetRubyVersion: 2.6
|
11
19
|
|
12
|
-
|
13
|
-
|
20
|
+
Gemspec/DeprecatedAttributeAssignment:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Gemspec/RequireMFA:
|
24
|
+
Enabled: false
|
14
25
|
|
15
26
|
Layout/HashAlignment:
|
16
|
-
|
27
|
+
EnforcedColonStyle: table
|
28
|
+
Exclude:
|
29
|
+
- jekyll_href.gemspec
|
30
|
+
|
31
|
+
Layout/InitialIndentation:
|
32
|
+
Exclude:
|
33
|
+
- README.md
|
17
34
|
|
18
35
|
Layout/LineLength:
|
19
36
|
Max: 150
|
@@ -21,17 +38,51 @@ Layout/LineLength:
|
|
21
38
|
Layout/MultilineMethodCallIndentation:
|
22
39
|
Enabled: false
|
23
40
|
|
41
|
+
Lint/RedundantCopDisableDirective:
|
42
|
+
Exclude:
|
43
|
+
- jekyll_href.gemspec
|
44
|
+
|
24
45
|
Metrics/AbcSize:
|
25
|
-
Max:
|
46
|
+
Max: 45
|
47
|
+
|
48
|
+
Metrics/BlockLength:
|
49
|
+
Exclude:
|
50
|
+
- jekyll_href.gemspec
|
51
|
+
- spec/**/*
|
52
|
+
Max: 40
|
53
|
+
|
54
|
+
Metrics/ClassLength:
|
55
|
+
Exclude:
|
56
|
+
- spec/**/*
|
57
|
+
Max: 40
|
26
58
|
|
27
59
|
Metrics/CyclomaticComplexity:
|
28
|
-
Max:
|
60
|
+
Max: 20
|
29
61
|
|
30
62
|
Metrics/MethodLength:
|
31
|
-
Max:
|
63
|
+
Max: 40
|
32
64
|
|
33
65
|
Metrics/PerceivedComplexity:
|
34
|
-
Max:
|
66
|
+
Max: 15
|
67
|
+
|
68
|
+
Naming/FileName:
|
69
|
+
Exclude:
|
70
|
+
- Rakefile
|
71
|
+
|
72
|
+
RSpec/ExampleLength:
|
73
|
+
Max: 20
|
74
|
+
|
75
|
+
RSpec/MultipleExpectations:
|
76
|
+
Max: 15
|
77
|
+
|
78
|
+
Style/CommandLiteral:
|
79
|
+
Enabled: false
|
80
|
+
|
81
|
+
Style/CommentedKeyword:
|
82
|
+
Enabled: false
|
83
|
+
|
84
|
+
Style/Documentation:
|
85
|
+
Enabled: false
|
35
86
|
|
36
87
|
Style/FrozenStringLiteralComment:
|
37
88
|
Enabled: false
|
@@ -42,6 +93,10 @@ Style/PercentLiteralDelimiters:
|
|
42
93
|
Style/RegexpLiteral:
|
43
94
|
Enabled: false
|
44
95
|
|
96
|
+
Style/StringConcatenation:
|
97
|
+
Exclude:
|
98
|
+
- spec/**/*
|
99
|
+
|
45
100
|
Style/StringLiterals:
|
46
101
|
Enabled: false
|
47
102
|
|
@@ -49,4 +104,4 @@ Style/StringLiteralsInInterpolation:
|
|
49
104
|
Enabled: false
|
50
105
|
|
51
106
|
Style/TrailingCommaInHashLiteral:
|
52
|
-
|
107
|
+
EnforcedStyleForMultiline: comma
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 1.2.1 / 2023-03-21
|
2
|
+
* Added `shy` and `wbr` options.
|
3
|
+
|
4
|
+
## 1.2.0 / 2023-02-16
|
5
|
+
* Updated to `jekyll_plugin_support` v1.5.0
|
6
|
+
|
7
|
+
## 1.1.1 / 2023-02-14
|
8
|
+
* Now dependent on `jekyll_plugin_support`
|
9
|
+
|
1
10
|
## 1.1.0 / 2023-02-03
|
2
11
|
* Updated to `jekyll_all_collections` plugin v0.2.0.
|
3
12
|
* Fixed insidious bug where a valid link was not used properly.
|
data/README.md
CHANGED
@@ -5,27 +5,35 @@
|
|
5
5
|
`Jekyll_href` is a Jekyll plugin that provides a new Liquid tag: `href`.
|
6
6
|
It provides a convenient way to generate formatted and clickable URIs.
|
7
7
|
The Liquid tag generates an `a href` HTML tag,
|
8
|
-
which by default contains `target="_blank"` and `rel=nofollow`.
|
8
|
+
which by default contains `target="_blank"` and `rel="nofollow"`.
|
9
9
|
|
10
10
|
If the url starts with `http`, or the `match` keyword is specified:
|
11
11
|
- The url will open in a new tab or window.
|
12
|
-
- The url will include `rel=nofollow` for SEO purposes.
|
12
|
+
- The url will include `rel="nofollow"` for SEO purposes.
|
13
13
|
|
14
14
|
CAUTION: if linked text contains a single or double quote,
|
15
15
|
you will see the error message: `Liquid Exception: Unmatched quote`.
|
16
|
-
Instead, use
|
17
|
-
’ (`’`), “ (`“`), and ” (`”`)
|
16
|
+
Instead, use:
|
18
17
|
|
18
|
+
- `'` (')
|
19
|
+
- `"` (")
|
20
|
+
- `‘` (‘)
|
21
|
+
- `’` (’)
|
22
|
+
- `“` (“)
|
23
|
+
- `”` (”)
|
24
|
+
|
25
|
+
|
26
|
+
## Configuration
|
19
27
|
In `_config.yml`, if a section called `plugin-vars` exists,
|
20
28
|
then its name/value pairs are available for substitution.
|
21
29
|
```yaml
|
22
|
-
|
23
|
-
|
24
|
-
|
30
|
+
plugin-vars:
|
31
|
+
django-github: 'https://github.com/django/django/blob/3.1.7'
|
32
|
+
django-oscar-github: 'https://github.com/django-oscar/django-oscar/blob/3.0.2'
|
25
33
|
```
|
26
34
|
|
27
35
|
|
28
|
-
## Syntax 1 (requires `url` does not have embedded spaces)
|
36
|
+
## Syntax 1 (requires `url` does not have embedded spaces)
|
29
37
|
```
|
30
38
|
{% href [match | [follow] [blank|notarget]] url text to display %}
|
31
39
|
```
|
@@ -34,7 +42,7 @@ then its name/value pairs are available for substitution.
|
|
34
42
|
3. The square brackets denote optional keyword parameters, and should not be typed.
|
35
43
|
|
36
44
|
|
37
|
-
## Syntax 2 (always works)
|
45
|
+
## Syntax 2 (always works)
|
38
46
|
This syntax is recommended when the URL contains a colon (:).
|
39
47
|
```
|
40
48
|
{% href [match | [follow] [blank|notarget]]
|
@@ -48,9 +56,9 @@ This syntax is recommended when the URL contains a colon (:).
|
|
48
56
|
3. The square brackets denote optional keyword parameters, and should not be typed.
|
49
57
|
|
50
58
|
|
51
|
-
## Syntax 3 (implicit URL)
|
59
|
+
## Syntax 3 (implicit URL)
|
52
60
|
```
|
53
|
-
{% href [match | [follow] [blank|notarget]] www.domain.com %}
|
61
|
+
{% href [match | [follow] [blank|notarget]] [shy|wbr] www.domain.com %}
|
54
62
|
```
|
55
63
|
The URI provided, for example `www.domain.com`,
|
56
64
|
is used to form the URL by prepending `https://`,
|
@@ -94,6 +102,50 @@ The `match` option looks through the pages collection for a URL with containing
|
|
94
102
|
`Match` implies `follow` and `notarget`.
|
95
103
|
|
96
104
|
|
105
|
+
### `shy`
|
106
|
+
`shy` is only applicable for syntax 3 (implicit URL).
|
107
|
+
This option causes displayed urls to have an ­ inserted after each slash (/).
|
108
|
+
If both `shy` and `wbr` are specified, `wbr` prevails.
|
109
|
+
|
110
|
+
For example:
|
111
|
+
```
|
112
|
+
{% href shy mslinn.com/path/to/page.html %}
|
113
|
+
```
|
114
|
+
Expands to:
|
115
|
+
```
|
116
|
+
<a href="https://mslinn.com/path/to/page.html">mslinn.com/­path/­to/­page.html</a>
|
117
|
+
```
|
118
|
+
|
119
|
+
### `shy`
|
120
|
+
`shy` is only applicable for syntax 3 (implicit URL).
|
121
|
+
This option causes displayed urls to have an [`&shy;`](https://developer.mozilla.org/en-US/docs/Web/CSS/hyphens) inserted after each slash (/).
|
122
|
+
If both `shy` and `wbr` are specified, `wbr` prevails.
|
123
|
+
|
124
|
+
For example:
|
125
|
+
```
|
126
|
+
{% href shy mslinn.com/path/to/page.html %}
|
127
|
+
```
|
128
|
+
Expands to:
|
129
|
+
```
|
130
|
+
<a href="https://mslinn.com/path/to/page.html" rel="nofollow" target="_blank">mslinn.com/­path/­to/­page.html</a>
|
131
|
+
```
|
132
|
+
|
133
|
+
### `wbr`
|
134
|
+
`wbr` is only applicable for syntax 3 (implicit URL).
|
135
|
+
It add [line break opportunites](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/wbr).
|
136
|
+
This option causes displayed urls to have an `<wbr>` inserted after each slash (/).
|
137
|
+
If both `shy` and `wbr` are specified, `wbr` prevails.
|
138
|
+
|
139
|
+
For example:
|
140
|
+
```
|
141
|
+
{% href wbr mslinn.com/path/to/page.html %}
|
142
|
+
```
|
143
|
+
Expands to:
|
144
|
+
```
|
145
|
+
<a href="https://mslinn.com/path/to/page.html" rel="nofollow" target="_blank">mslinn.com/<wbr>path/<wbr>to/<wbr>page.html</a>
|
146
|
+
```
|
147
|
+
|
148
|
+
|
97
149
|
## Examples
|
98
150
|
1. Generates `nofollow` and `target` attributes:
|
99
151
|
```
|
data/Rakefile
CHANGED
data/jekyll_href.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative 'lib/jekyll_href/version'
|
2
2
|
|
3
|
-
Gem::Specification.new do |spec|
|
3
|
+
Gem::Specification.new do |spec|
|
4
4
|
github = 'https://github.com/mslinn/jekyll_href'
|
5
5
|
|
6
6
|
spec.authors = ['Mike Slinn']
|
@@ -32,8 +32,5 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
|
32
32
|
spec.version = JekyllHrefVersion::VERSION
|
33
33
|
|
34
34
|
spec.add_dependency 'jekyll', '>= 3.5.0'
|
35
|
-
spec.add_dependency 'jekyll_all_collections', '
|
36
|
-
spec.add_dependency 'jekyll_plugin_logger'
|
37
|
-
spec.add_dependency 'key-value-parser'
|
38
|
-
spec.add_dependency 'shellwords'
|
35
|
+
spec.add_dependency 'jekyll_all_collections', '~> 0.3.0', '>= 0.3.1'
|
39
36
|
end
|
data/lib/jekyll_href/version.rb
CHANGED
data/lib/jekyll_href.rb
CHANGED
@@ -1,47 +1,32 @@
|
|
1
1
|
require 'jekyll_all_collections'
|
2
2
|
require 'jekyll_plugin_logger'
|
3
|
+
require 'jekyll_plugin_support'
|
3
4
|
require 'liquid'
|
4
5
|
require_relative 'jekyll_href/version'
|
5
|
-
require_relative './jekyll_tag_helper2'
|
6
6
|
|
7
7
|
# @author Copyright 2020 Michael Slinn
|
8
8
|
# @license SPDX-License-Identifier: Apache-2.0
|
9
9
|
# Generates an href.
|
10
10
|
|
11
11
|
# Implements href Jekyll tag
|
12
|
-
class ExternalHref <
|
12
|
+
class ExternalHref < JekyllSupport::JekyllTag # rubocop:disable Metrics/ClassLength
|
13
13
|
attr_reader :follow, :helper, :line_number, :match, :page, :path, :site, :text, :target, :url
|
14
14
|
attr_accessor :link
|
15
15
|
|
16
|
-
|
17
|
-
# @param markup [String] the arguments from the web page.
|
18
|
-
# @param _tokens [Liquid::ParseContext] tokenized command line
|
19
|
-
# By default it has two keys: :locale and :line_numbers, the first is a Liquid::I18n object, and the second,
|
20
|
-
# a boolean parameter that determines if error messages should display the line number the error occurred.
|
21
|
-
# This argument is used mostly to display localized error messages on Liquid built-in Tags and Filters.
|
22
|
-
# See https://github.com/Shopify/liquid/wiki/Liquid-for-Programmers#create-your-own-tags
|
23
|
-
# @return [void]
|
24
|
-
def initialize(tag_name, markup, _tokens)
|
25
|
-
super
|
26
|
-
markup = '' if markup.nil?
|
27
|
-
markup.strip!
|
28
|
-
|
29
|
-
@logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
30
|
-
@helper = JekyllTagHelper2.new(tag_name, markup, @logger)
|
31
|
-
end
|
16
|
+
include JekyllHrefVersion
|
32
17
|
|
33
18
|
# Method prescribed by the Jekyll plugin lifecycle.
|
34
19
|
# @param liquid_context [Liquid::Context]
|
35
20
|
# @return [String]
|
36
|
-
def
|
37
|
-
|
38
|
-
globals_initial(liquid_context)
|
21
|
+
def render_impl
|
22
|
+
globals_initial
|
39
23
|
linkk = compute_linkk
|
40
24
|
linkk = replace_vars(linkk)
|
41
25
|
@link_save = linkk
|
42
26
|
@helper_save = @helper.clone
|
43
27
|
globals_update(@helper.argv, linkk) # Sets @link and @text, might clear @follow and @target
|
44
28
|
handle_match if @match
|
29
|
+
|
45
30
|
"<a href='#{@link}'#{@target}#{@follow}>#{@text}</a>"
|
46
31
|
end
|
47
32
|
|
@@ -77,21 +62,19 @@ class ExternalHref < Liquid::Tag # rubocop:disable Metrics/ClassLength
|
|
77
62
|
abort msg.red
|
78
63
|
end
|
79
64
|
|
80
|
-
|
81
|
-
|
82
|
-
@helper.liquid_context = liquid_context
|
83
|
-
|
84
|
-
@page = liquid_context.registers[:page]
|
65
|
+
# Sets @follow, @helper, @match, @path, @shy, @target, @url, @wbr
|
66
|
+
def globals_initial
|
85
67
|
@path = @page['path']
|
86
|
-
@site = liquid_context.registers[:site]
|
87
68
|
AllCollectionsHooks.compute(@site)
|
88
69
|
|
89
70
|
@follow = @helper.parameter_specified?('follow') ? '' : " rel='nofollow'"
|
90
71
|
@match = @helper.parameter_specified?('match')
|
91
72
|
@blank = @helper.parameter_specified?('blank')
|
73
|
+
@shy = @helper.parameter_specified?('shy')
|
92
74
|
@target = @blank ? " target='_blank'" : nil
|
93
75
|
@target ||= @helper.parameter_specified?('notarget') ? '' : " target='_blank'"
|
94
76
|
@url = @helper.parameter_specified?('url')
|
77
|
+
@wbr = @helper.parameter_specified?('wbr')
|
95
78
|
end
|
96
79
|
|
97
80
|
# Might set @follow, @linkk, @target, and @text
|
@@ -108,10 +91,19 @@ class ExternalHref < Liquid::Tag # rubocop:disable Metrics/ClassLength
|
|
108
91
|
else
|
109
92
|
@text = tokens.join(' ').strip
|
110
93
|
if @text.to_s.empty?
|
111
|
-
|
94
|
+
text = linkk
|
95
|
+
text = linkk.gsub('/', '/­') if @shy
|
96
|
+
text = linkk.gsub('/', '/<wbr>') if @wbr
|
97
|
+
@text = "<code>#{text}</code>"
|
112
98
|
@link = "https://#{linkk}"
|
113
99
|
else
|
114
|
-
@link =
|
100
|
+
@link = if @shy
|
101
|
+
linkk.gsub('/', '/­')
|
102
|
+
elsif @wbr
|
103
|
+
linkk.gsub('/', '/<wbr>')
|
104
|
+
else
|
105
|
+
linkk
|
106
|
+
end
|
115
107
|
end
|
116
108
|
end
|
117
109
|
|
@@ -154,7 +146,7 @@ class ExternalHref < Liquid::Tag # rubocop:disable Metrics/ClassLength
|
|
154
146
|
@text = "<i>#{@link} is not available</i>"
|
155
147
|
when 1
|
156
148
|
@link = url_matches.first
|
157
|
-
@link = "#{@link}
|
149
|
+
@link = "#{@link}##{@fragment}" if @fragment
|
158
150
|
else
|
159
151
|
abort "Error: More than one url matched '#{@path}': #{url_matches.join(', ')}"
|
160
152
|
end
|
@@ -171,7 +163,6 @@ class ExternalHref < Liquid::Tag # rubocop:disable Metrics/ClassLength
|
|
171
163
|
@logger.debug { "@link=#{@link}" }
|
172
164
|
text
|
173
165
|
end
|
174
|
-
end
|
175
166
|
|
176
|
-
|
177
|
-
|
167
|
+
JekyllPluginHelper.register(self, 'href')
|
168
|
+
end
|
data/spec/href_spec.rb
CHANGED
@@ -40,8 +40,7 @@ class TestParseContext < Liquid::ParseContext
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
|
-
class MyTest # rubocop:disable Metrics/ClassLength
|
43
|
+
class MyTest
|
45
44
|
Dir.chdir 'demo'
|
46
45
|
|
47
46
|
RSpec.describe ExternalHref do
|
@@ -60,14 +59,14 @@ class MyTest # rubocop:disable Metrics/ClassLength
|
|
60
59
|
end
|
61
60
|
|
62
61
|
it "Obtains internal link with blank" do
|
63
|
-
href =
|
62
|
+
href = described_class.send(
|
64
63
|
:new,
|
65
64
|
'href',
|
66
|
-
'blank ./path/page.html internal link text'
|
65
|
+
+ 'blank ./path/page.html internal link text',
|
67
66
|
parse_context
|
68
67
|
)
|
69
|
-
href.send
|
70
|
-
linkk = href.send
|
68
|
+
href.send :globals_initial
|
69
|
+
linkk = href.send :compute_linkk
|
71
70
|
href.send(:globals_update, href.helper.argv, linkk)
|
72
71
|
expect(href.follow).to eq('')
|
73
72
|
expect(href.link).to eq('./path/page.html')
|
@@ -76,10 +75,10 @@ class MyTest # rubocop:disable Metrics/ClassLength
|
|
76
75
|
end
|
77
76
|
|
78
77
|
it "Obtains external link with text" do
|
79
|
-
href =
|
78
|
+
href = described_class.send(
|
80
79
|
:new,
|
81
80
|
'href',
|
82
|
-
'https://feeds.soundcloud.com/users/soundcloud:users:7143896/sounds.rss SoundCloud RSS Feed'
|
81
|
+
+ 'https://feeds.soundcloud.com/users/soundcloud:users:7143896/sounds.rss SoundCloud RSS Feed',
|
83
82
|
parse_context
|
84
83
|
)
|
85
84
|
href.send(:globals_initial, parse_context)
|
@@ -92,10 +91,10 @@ class MyTest # rubocop:disable Metrics/ClassLength
|
|
92
91
|
end
|
93
92
|
|
94
93
|
it "Obtains external link using url parameter with text" do
|
95
|
-
href =
|
94
|
+
href = described_class.send(
|
96
95
|
:new,
|
97
96
|
'href',
|
98
|
-
'url="https://feeds.soundcloud.com/users/soundcloud:users:7143896/sounds.rss" SoundCloud RSS Feed'
|
97
|
+
+ 'url="https://feeds.soundcloud.com/users/soundcloud:users:7143896/sounds.rss" SoundCloud RSS Feed',
|
99
98
|
parse_context
|
100
99
|
)
|
101
100
|
href.send(:globals_initial, parse_context)
|
@@ -108,10 +107,10 @@ class MyTest # rubocop:disable Metrics/ClassLength
|
|
108
107
|
end
|
109
108
|
|
110
109
|
it "Obtains external link without scheme or text" do
|
111
|
-
href =
|
110
|
+
href = described_class.send(
|
112
111
|
:new,
|
113
112
|
'href',
|
114
|
-
'super-fake-merger.com'
|
113
|
+
+ 'super-fake-merger.com',
|
115
114
|
parse_context
|
116
115
|
)
|
117
116
|
href.send(:globals_initial, parse_context)
|
@@ -124,10 +123,10 @@ class MyTest # rubocop:disable Metrics/ClassLength
|
|
124
123
|
end
|
125
124
|
|
126
125
|
it "Expands YAML hash with link text" do
|
127
|
-
href =
|
126
|
+
href = described_class.send(
|
128
127
|
:new,
|
129
128
|
'href',
|
130
|
-
'{{github}}/diasks2/confidential_info_redactor <code>confidential_info_redactor</code>'
|
129
|
+
+ '{{github}}/diasks2/confidential_info_redactor <code>confidential_info_redactor</code>',
|
131
130
|
parse_context
|
132
131
|
)
|
133
132
|
href.send(:globals_initial, parse_context)
|
@@ -141,10 +140,10 @@ class MyTest # rubocop:disable Metrics/ClassLength
|
|
141
140
|
end
|
142
141
|
|
143
142
|
it "Obtains external link with follow" do
|
144
|
-
href =
|
143
|
+
href = described_class.send(
|
145
144
|
:new,
|
146
145
|
'href',
|
147
|
-
'follow https://www.mslinn.com Awesome'
|
146
|
+
+ 'follow https://www.mslinn.com Awesome',
|
148
147
|
parse_context
|
149
148
|
)
|
150
149
|
href.send(:globals_initial, parse_context)
|
@@ -157,10 +156,10 @@ class MyTest # rubocop:disable Metrics/ClassLength
|
|
157
156
|
end
|
158
157
|
|
159
158
|
it "Obtains external link with follow and notarget" do
|
160
|
-
href =
|
159
|
+
href = described_class.send(
|
161
160
|
:new,
|
162
161
|
'href',
|
163
|
-
'follow notarget https://www.mslinn.com Awesome'
|
162
|
+
+ 'follow notarget https://www.mslinn.com Awesome',
|
164
163
|
parse_context
|
165
164
|
)
|
166
165
|
href.send(:globals_initial, parse_context)
|
@@ -173,10 +172,10 @@ class MyTest # rubocop:disable Metrics/ClassLength
|
|
173
172
|
end
|
174
173
|
|
175
174
|
it "Obtains external link with blank" do
|
176
|
-
href =
|
175
|
+
href = described_class.send(
|
177
176
|
:new,
|
178
177
|
'href',
|
179
|
-
'blank https://www.mslinn.com Awesome'
|
178
|
+
+ 'blank https://www.mslinn.com Awesome',
|
180
179
|
parse_context
|
181
180
|
)
|
182
181
|
href.send(:globals_initial, parse_context)
|
@@ -189,10 +188,10 @@ class MyTest # rubocop:disable Metrics/ClassLength
|
|
189
188
|
end
|
190
189
|
|
191
190
|
it "Implicitly computes external link from text" do
|
192
|
-
href =
|
191
|
+
href = described_class.send(
|
193
192
|
:new,
|
194
193
|
'href',
|
195
|
-
'www.mslinn.com'
|
194
|
+
+ 'www.mslinn.com',
|
196
195
|
parse_context
|
197
196
|
)
|
198
197
|
href.send(:globals_initial, parse_context)
|
@@ -205,10 +204,10 @@ class MyTest # rubocop:disable Metrics/ClassLength
|
|
205
204
|
end
|
206
205
|
|
207
206
|
it "Implicitly computes external link from text with follow and notarget" do
|
208
|
-
href =
|
207
|
+
href = described_class.send(
|
209
208
|
:new,
|
210
209
|
'href',
|
211
|
-
'follow notarget www.mslinn.com'
|
210
|
+
+ 'follow notarget www.mslinn.com',
|
212
211
|
parse_context
|
213
212
|
)
|
214
213
|
href.send(:globals_initial, parse_context)
|
@@ -221,10 +220,10 @@ class MyTest # rubocop:disable Metrics/ClassLength
|
|
221
220
|
end
|
222
221
|
|
223
222
|
it "Implicitly computes external link from text with blank" do
|
224
|
-
href =
|
223
|
+
href = described_class.send(
|
225
224
|
:new,
|
226
225
|
'href',
|
227
|
-
'follow blank www.mslinn.com'
|
226
|
+
+ 'follow blank www.mslinn.com',
|
228
227
|
parse_context
|
229
228
|
)
|
230
229
|
href.send(:globals_initial, parse_context)
|
@@ -237,10 +236,10 @@ class MyTest # rubocop:disable Metrics/ClassLength
|
|
237
236
|
end
|
238
237
|
|
239
238
|
it "Obtains mailto without text" do
|
240
|
-
href =
|
239
|
+
href = described_class.send(
|
241
240
|
:new,
|
242
241
|
'href',
|
243
|
-
'mailto:mslinn@mslinn.com'
|
242
|
+
+ 'mailto:mslinn@mslinn.com',
|
244
243
|
parse_context
|
245
244
|
)
|
246
245
|
href.send(:globals_initial, parse_context)
|
@@ -253,10 +252,10 @@ class MyTest # rubocop:disable Metrics/ClassLength
|
|
253
252
|
end
|
254
253
|
|
255
254
|
it "Obtains mailto with text" do
|
256
|
-
href =
|
255
|
+
href = described_class.send(
|
257
256
|
:new,
|
258
257
|
'href',
|
259
|
-
'mailto:mslinn@mslinn.com Mike Slinn'
|
258
|
+
+ 'mailto:mslinn@mslinn.com Mike Slinn',
|
260
259
|
parse_context
|
261
260
|
)
|
262
261
|
href.send(:globals_initial, parse_context)
|
data/spec/status_persistence.txt
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
example_id | status | run_time |
|
2
2
|
----------------------------------------------------------------- | ------ | --------------- |
|
3
|
-
/mnt/
|
4
|
-
/mnt/
|
5
|
-
/mnt/
|
6
|
-
/mnt/
|
7
|
-
/mnt/
|
8
|
-
/mnt/
|
9
|
-
/mnt/
|
10
|
-
/mnt/
|
11
|
-
/mnt/
|
12
|
-
/mnt/
|
13
|
-
/mnt/
|
14
|
-
/mnt/
|
15
|
-
/mnt/
|
3
|
+
/mnt/f/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:1] | passed | 0.00817 seconds |
|
4
|
+
/mnt/f/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:2] | passed | 0.00349 seconds |
|
5
|
+
/mnt/f/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:3] | passed | 0.0033 seconds |
|
6
|
+
/mnt/f/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:4] | passed | 0.00307 seconds |
|
7
|
+
/mnt/f/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:5] | passed | 0.00315 seconds |
|
8
|
+
/mnt/f/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:6] | passed | 0.0032 seconds |
|
9
|
+
/mnt/f/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:7] | passed | 0.0035 seconds |
|
10
|
+
/mnt/f/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:8] | passed | 0.00323 seconds |
|
11
|
+
/mnt/f/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:9] | passed | 0.0032 seconds |
|
12
|
+
/mnt/f/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:10] | passed | 0.00307 seconds |
|
13
|
+
/mnt/f/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:11] | passed | 0.00317 seconds |
|
14
|
+
/mnt/f/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:12] | passed | 0.00357 seconds |
|
15
|
+
/mnt/f/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:13] | passed | 0.0035 seconds |
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll_href
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
4
|
+
version: 1.2.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-
|
11
|
+
date: 2023-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -28,58 +28,22 @@ dependencies:
|
|
28
28
|
name: jekyll_all_collections
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.2.0
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
31
|
+
- - "~>"
|
39
32
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: jekyll_plugin_logger
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
33
|
+
version: 0.3.0
|
45
34
|
- - ">="
|
46
35
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
36
|
+
version: 0.3.1
|
48
37
|
type: :runtime
|
49
38
|
prerelease: false
|
50
39
|
version_requirements: !ruby/object:Gem::Requirement
|
51
40
|
requirements:
|
52
|
-
- - "
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: key-value-parser
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
41
|
+
- - "~>"
|
60
42
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
-
type: :runtime
|
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: shellwords
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
43
|
+
version: 0.3.0
|
80
44
|
- - ">="
|
81
45
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
46
|
+
version: 0.3.1
|
83
47
|
description: 'Generates an ''a href'' tag, possibly with target=''_blank'' and rel=''nofollow''.
|
84
48
|
|
85
49
|
'
|
@@ -97,7 +61,6 @@ files:
|
|
97
61
|
- jekyll_href.gemspec
|
98
62
|
- lib/jekyll_href.rb
|
99
63
|
- lib/jekyll_href/version.rb
|
100
|
-
- lib/jekyll_tag_helper2.rb
|
101
64
|
- spec/href_spec.rb
|
102
65
|
- spec/spec_helper.rb
|
103
66
|
- spec/status_persistence.txt
|
data/lib/jekyll_tag_helper2.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
require 'shellwords'
|
2
|
-
require 'key_value_parser'
|
3
|
-
|
4
|
-
# Parses arguments and options
|
5
|
-
class JekyllTagHelper2
|
6
|
-
attr_reader :argv, :keys_values, :liquid_context, :logger, :markup, :params, :tag_name
|
7
|
-
|
8
|
-
# Expand a environment variable reference
|
9
|
-
def self.expand_env(str, die_if_undefined: false)
|
10
|
-
str.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/) do
|
11
|
-
envar = Regexp.last_match(1)
|
12
|
-
raise HrefError, "jekyll_href error: #{envar} is undefined".red, [] \
|
13
|
-
if !ENV.key?(envar) && die_if_undefined # Suppress stack trace
|
14
|
-
|
15
|
-
ENV[envar]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# strip leading and trailing quotes if present
|
20
|
-
def self.remove_quotes(string)
|
21
|
-
string.strip.gsub(/\A'|\A"|'\Z|"\Z/, '').strip if string
|
22
|
-
end
|
23
|
-
|
24
|
-
def initialize(tag_name, markup, logger)
|
25
|
-
# @keys_values was a Hash[Symbol, String|Boolean] but now it is Hash[String, String|Boolean]
|
26
|
-
@tag_name = tag_name
|
27
|
-
@markup = markup # Useful for debugging
|
28
|
-
@argv = Shellwords.split(JekyllTagHelper2.expand_env(markup))
|
29
|
-
@keys_values = KeyValueParser \
|
30
|
-
.new({}, { array_values: false, normalize_keys: false, separator: /=/ }) \
|
31
|
-
.parse(@argv)
|
32
|
-
@logger = logger
|
33
|
-
@logger.debug { "@keys_values='#{@keys_values}'" }
|
34
|
-
end
|
35
|
-
|
36
|
-
def delete_parameter(key)
|
37
|
-
return if @keys_values.empty?
|
38
|
-
|
39
|
-
@params.delete(key)
|
40
|
-
@argv.delete_if { |x| x == key or x.start_with?("#{key}=") }
|
41
|
-
@keys_values.delete(key)
|
42
|
-
end
|
43
|
-
|
44
|
-
# @return if parameter was specified, removes it from the available tokens and returns value
|
45
|
-
def parameter_specified?(name)
|
46
|
-
return false if @keys_values.empty?
|
47
|
-
|
48
|
-
key = name
|
49
|
-
key = name.to_sym if @keys_values.first.first.instance_of?(Symbol)
|
50
|
-
value = @keys_values[key]
|
51
|
-
delete_parameter(name)
|
52
|
-
value
|
53
|
-
end
|
54
|
-
|
55
|
-
PREDEFINED_SCOPE_KEYS = %i[include page].freeze
|
56
|
-
|
57
|
-
# Finds variables defined in an invoking include, or maybe somewhere else
|
58
|
-
# @return variable value or nil
|
59
|
-
def dereference_include_variable(name)
|
60
|
-
@liquid_context.scopes.each do |scope|
|
61
|
-
next if PREDEFINED_SCOPE_KEYS.include? scope.keys.first
|
62
|
-
|
63
|
-
value = scope[name]
|
64
|
-
return value if value
|
65
|
-
end
|
66
|
-
nil
|
67
|
-
end
|
68
|
-
|
69
|
-
# @return value of variable, or the empty string
|
70
|
-
def dereference_variable(name)
|
71
|
-
value = @liquid_context[name] # Finds variables named like 'include.my_variable', found in @liquid_context.scopes.first
|
72
|
-
value ||= @page[name] if @page # Finds variables named like 'page.my_variable'
|
73
|
-
value ||= dereference_include_variable(name)
|
74
|
-
value ||= ''
|
75
|
-
value
|
76
|
-
end
|
77
|
-
|
78
|
-
# Sets @params by replacing any Liquid variable names with their values
|
79
|
-
def liquid_context=(context)
|
80
|
-
@liquid_context = context
|
81
|
-
@params = @keys_values.map { |k, _v| lookup_variable(k) }
|
82
|
-
end
|
83
|
-
|
84
|
-
def lookup_variable(symbol)
|
85
|
-
string = symbol.to_s
|
86
|
-
return string unless string.start_with?('{{') && string.end_with?('}}')
|
87
|
-
|
88
|
-
dereference_variable(string.delete_prefix('{{').delete_suffix('}}'))
|
89
|
-
end
|
90
|
-
|
91
|
-
def page
|
92
|
-
@liquid_context.registers[:page]
|
93
|
-
end
|
94
|
-
end
|