jekyll_href 1.1.0 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/spec/href_spec.rb CHANGED
@@ -1,50 +1,10 @@
1
- require 'jekyll'
2
- require 'jekyll_plugin_logger'
3
- require 'yaml'
4
1
  require_relative '../lib/jekyll_href'
5
2
 
6
- Registers = Struct.new(:page, :site)
7
-
8
- # Mock for Collections
9
- class Collections
10
- def values
11
- []
12
- end
13
- end
14
-
15
- # Mock for Site
16
- class SiteMock
17
- attr_reader :config
18
-
19
- def initialize
20
- @config = YAML.safe_load(File.read('_config.yml'))
21
- end
22
-
23
- def collections
24
- Collections.new
25
- end
26
- end
27
-
28
- # Mock for Liquid::ParseContent
29
- class TestParseContext < Liquid::ParseContext
30
- attr_reader :line_number, :registers
31
-
32
- def initialize
33
- super
34
- @line_number = 123
35
-
36
- @registers = Registers.new(
37
- { 'path' => 'https://feeds.soundcloud.com/users/soundcloud:users:7143896/sounds.rss' },
38
- SiteMock.new
39
- )
40
- end
41
- end
42
-
43
- # Lets get this party started
44
- class MyTest # rubocop:disable Metrics/ClassLength
3
+ class MyTest
45
4
  Dir.chdir 'demo'
5
+ HashArray.reset
46
6
 
47
- RSpec.describe ExternalHref do
7
+ RSpec.describe HrefTag::HrefTag do
48
8
  let(:logger) do
49
9
  PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
50
10
  end
@@ -59,209 +19,194 @@ class MyTest # rubocop:disable Metrics/ClassLength
59
19
  )
60
20
  end
61
21
 
62
- it "Obtains internal link with blank" do
63
- href = ExternalHref.send(
22
+ it 'obtains internal link with blank' do
23
+ href = described_class.send(
64
24
  :new,
65
25
  'href',
66
- 'blank ./path/page.html internal link text'.dup,
26
+ + 'blank path/page.html internal link text',
67
27
  parse_context
68
28
  )
69
- href.send(:globals_initial, parse_context)
70
- linkk = href.send(:compute_linkk)
71
- href.send(:globals_update, href.helper.argv, linkk)
29
+ href.render TestLiquidContext.new
72
30
  expect(href.follow).to eq('')
73
- expect(href.link).to eq('./path/page.html')
31
+ expect(href.link).to eq('path/page.html')
74
32
  expect(href.target).to eq(" target='_blank'")
75
33
  expect(href.text).to eq('internal link text')
76
34
  end
77
35
 
78
- it "Obtains external link with text" do
79
- href = ExternalHref.send(
36
+ it 'obtains external link with text' do
37
+ href = described_class.send(
80
38
  :new,
81
39
  'href',
82
- 'https://feeds.soundcloud.com/users/soundcloud:users:7143896/sounds.rss SoundCloud RSS Feed'.dup,
40
+ + 'summary_exclude https://feeds.soundcloud.com/users/soundcloud:users:7143896/sounds.rss SoundCloud RSS Feed',
83
41
  parse_context
84
42
  )
85
- href.send(:globals_initial, parse_context)
86
- linkk = href.send(:compute_linkk)
87
- href.send(:globals_update, href.helper.argv, linkk)
43
+ href.render TestLiquidContext.new
88
44
  expect(href.follow).to eq(" rel='nofollow'")
89
45
  expect(href.link).to eq('https://feeds.soundcloud.com/users/soundcloud:users:7143896/sounds.rss')
90
46
  expect(href.target).to eq(" target='_blank'")
91
47
  expect(href.text).to eq('SoundCloud RSS Feed')
92
48
  end
93
49
 
94
- it "Obtains external link using url parameter with text" do
95
- href = ExternalHref.send(
50
+ it 'obtains external link using url parameter with text' do
51
+ href = described_class.send(
96
52
  :new,
97
53
  'href',
98
- 'url="https://feeds.soundcloud.com/users/soundcloud:users:7143896/sounds.rss" SoundCloud RSS Feed'.dup,
54
+ + 'summary_exclude url="https://feeds.soundcloud.com/users/soundcloud:users:7143896/sounds.rss" SoundCloud RSS Feed',
99
55
  parse_context
100
56
  )
101
- href.send(:globals_initial, parse_context)
102
- linkk = href.send(:compute_linkk)
103
- href.send(:globals_update, href.helper.argv, linkk)
57
+ href.render TestLiquidContext.new
104
58
  expect(href.follow).to eq(" rel='nofollow'")
105
59
  expect(href.link).to eq('https://feeds.soundcloud.com/users/soundcloud:users:7143896/sounds.rss')
106
60
  expect(href.target).to eq(" target='_blank'")
107
61
  expect(href.text).to eq('SoundCloud RSS Feed')
108
62
  end
109
63
 
110
- it "Obtains external link without scheme or text" do
111
- href = ExternalHref.send(
64
+ it 'obtains external link without scheme or text' do
65
+ href = described_class.send(
112
66
  :new,
113
67
  'href',
114
- 'super-fake-merger.com'.dup,
68
+ + 'super-fake-merger.com',
115
69
  parse_context
116
70
  )
117
- href.send(:globals_initial, parse_context)
118
- linkk = href.send(:compute_linkk)
119
- href.send(:globals_update, href.helper.argv, linkk)
71
+ href.render TestLiquidContext.new
120
72
  expect(href.follow).to eq(" rel='nofollow'")
121
73
  expect(href.link).to eq('https://super-fake-merger.com')
122
74
  expect(href.target).to eq(" target='_blank'")
123
75
  expect(href.text).to eq('<code>super-fake-merger.com</code>')
124
76
  end
125
77
 
126
- it "Expands YAML hash with link text" do
127
- href = ExternalHref.send(
78
+ it 'expands YAML hash with link text' do
79
+ href = described_class.send(
128
80
  :new,
129
81
  'href',
130
- '{{github}}/diasks2/confidential_info_redactor <code>confidential_info_redactor</code>'.dup,
82
+ + '{{github}}/diasks2/confidential_info_redactor <code>confidential_info_redactor</code>',
131
83
  parse_context
132
84
  )
133
- href.send(:globals_initial, parse_context)
134
- linkk = href.send(:compute_linkk)
135
- linkk = href.send(:replace_vars, linkk)
136
- href.send(:globals_update, href.helper.argv, linkk)
85
+ href.render TestLiquidContext.new
137
86
  expect(href.follow).to eq(" rel='nofollow'")
138
87
  expect(href.link).to eq('https://github.com/diasks2/confidential_info_redactor')
139
88
  expect(href.target).to eq(" target='_blank'")
140
89
  expect(href.text).to eq('<code>confidential_info_redactor</code>')
141
90
  end
142
91
 
143
- it "Obtains external link with follow" do
144
- href = ExternalHref.send(
92
+ it 'obtains external link with follow' do
93
+ href = described_class.send(
145
94
  :new,
146
95
  'href',
147
- 'follow https://www.mslinn.com Awesome'.dup,
96
+ + 'follow https://www.mslinn.com Awesome',
148
97
  parse_context
149
98
  )
150
- href.send(:globals_initial, parse_context)
151
- linkk = href.send(:compute_linkk)
152
- href.send(:globals_update, href.helper.argv, linkk)
99
+ href.render TestLiquidContext.new
153
100
  expect(href.follow).to eq('')
154
101
  expect(href.link).to eq('https://www.mslinn.com')
155
102
  expect(href.target).to eq(" target='_blank'")
156
103
  expect(href.text).to eq('Awesome')
157
104
  end
158
105
 
159
- it "Obtains external link with follow and notarget" do
160
- href = ExternalHref.send(
106
+ it 'obtains external link with follow and notarget' do
107
+ href = described_class.send(
161
108
  :new,
162
109
  'href',
163
- 'follow notarget https://www.mslinn.com Awesome'.dup,
110
+ + 'follow notarget https://www.mslinn.com Awesome',
164
111
  parse_context
165
112
  )
166
- href.send(:globals_initial, parse_context)
167
- linkk = href.send(:compute_linkk)
168
- href.send(:globals_update, href.helper.argv, linkk)
113
+ href.render TestLiquidContext.new
169
114
  expect(href.follow).to eq('')
170
115
  expect(href.link).to eq('https://www.mslinn.com')
171
116
  expect(href.target).to eq('')
172
117
  expect(href.text).to eq('Awesome')
173
118
  end
174
119
 
175
- it "Obtains external link with blank" do
176
- href = ExternalHref.send(
120
+ it 'obtains external link with blank' do
121
+ href = described_class.send(
177
122
  :new,
178
123
  'href',
179
- 'blank https://www.mslinn.com Awesome'.dup,
124
+ + 'blank https://www.mslinn.com Awesome',
180
125
  parse_context
181
126
  )
182
- href.send(:globals_initial, parse_context)
183
- linkk = href.send(:compute_linkk)
184
- href.send(:globals_update, href.helper.argv, linkk)
127
+ href.render TestLiquidContext.new
185
128
  expect(href.follow).to eq(" rel='nofollow'")
186
129
  expect(href.link).to eq('https://www.mslinn.com')
187
130
  expect(href.target).to eq(" target='_blank'")
188
131
  expect(href.text).to eq('Awesome')
189
132
  end
190
133
 
191
- it "Implicitly computes external link from text" do
192
- href = ExternalHref.send(
134
+ it 'implicitly computes external link from text' do
135
+ href = described_class.send(
193
136
  :new,
194
137
  'href',
195
- 'www.mslinn.com'.dup,
138
+ + 'www.mslinn.com',
196
139
  parse_context
197
140
  )
198
- href.send(:globals_initial, parse_context)
199
- linkk = href.send(:compute_linkk)
200
- href.send(:globals_update, href.helper.argv, linkk)
141
+ href.render TestLiquidContext.new
201
142
  expect(href.follow).to eq(" rel='nofollow'")
202
143
  expect(href.link).to eq('https://www.mslinn.com')
203
144
  expect(href.target).to eq(" target='_blank'")
204
145
  expect(href.text).to eq('<code>www.mslinn.com</code>')
205
146
  end
206
147
 
207
- it "Implicitly computes external link from text with follow and notarget" do
208
- href = ExternalHref.send(
148
+ it 'implicitly computes external link from text with follow and notarget' do
149
+ href = described_class.send(
209
150
  :new,
210
151
  'href',
211
- 'follow notarget www.mslinn.com'.dup,
152
+ + 'follow notarget www.mslinn.com',
212
153
  parse_context
213
154
  )
214
- href.send(:globals_initial, parse_context)
215
- linkk = href.send(:compute_linkk)
216
- href.send(:globals_update, href.helper.argv, linkk)
155
+ href.render TestLiquidContext.new
217
156
  expect(href.follow).to eq('')
218
157
  expect(href.link).to eq('https://www.mslinn.com')
219
158
  expect(href.target).to eq('')
220
159
  expect(href.text).to eq('<code>www.mslinn.com</code>')
221
160
  end
222
161
 
223
- it "Implicitly computes external link from text with blank" do
224
- href = ExternalHref.send(
162
+ it 'implicitly computes external link from text with blank' do
163
+ href = described_class.send(
225
164
  :new,
226
165
  'href',
227
- 'follow blank www.mslinn.com'.dup,
166
+ + 'follow blank www.mslinn.com',
228
167
  parse_context
229
168
  )
230
- href.send(:globals_initial, parse_context)
231
- linkk = href.send(:compute_linkk)
232
- href.send(:globals_update, href.helper.argv, linkk)
169
+ href.render TestLiquidContext.new
233
170
  expect(href.follow).to eq('')
234
171
  expect(href.link).to eq('https://www.mslinn.com')
235
172
  expect(href.target).to eq(" target='_blank'")
236
173
  expect(href.text).to eq('<code>www.mslinn.com</code>')
174
+
175
+ # hrefs = HashArray.instance_variable_get(:@global_hrefs)
176
+ # expect(hrefs).to eq(
177
+ # {
178
+ # "index.html" => [
179
+ # "<a href='https://feeds.soundcloud.com/users/soundcloud:users:7143896/sounds.rss' target='_blank' rel='nofollow'>SoundCloud RSS Feed</a>",
180
+ # "<a href='https://github.com/diasks2/confidential_info_redactor' target='_blank' rel='nofollow'><code>confidential_info_redactor</code></a>",
181
+ # "<a href='https://super-fake-merger.com' target='_blank' rel='nofollow'><code>super-fake-merger.com</code></a>",
182
+ # "<a href='https://www.mslinn.com' target='_blank'><code>www.mslinn.com</code></a>"
183
+ # ],
184
+ # }
185
+ # )
237
186
  end
238
187
 
239
- it "Obtains mailto without text" do
240
- href = ExternalHref.send(
188
+ it 'obtains mailto without text' do
189
+ href = described_class.send(
241
190
  :new,
242
191
  'href',
243
- 'mailto:mslinn@mslinn.com'.dup,
192
+ + 'mailto:mslinn@mslinn.com',
244
193
  parse_context
245
194
  )
246
- href.send(:globals_initial, parse_context)
247
- linkk = href.send(:compute_linkk)
248
- href.send(:globals_update, href.helper.argv, linkk)
195
+ href.render TestLiquidContext.new
249
196
  expect(href.follow).to eq('')
250
197
  expect(href.link).to eq('mailto:mslinn@mslinn.com')
251
198
  expect(href.target).to eq('')
252
199
  expect(href.text).to eq('<code>mslinn@mslinn.com</code>')
253
200
  end
254
201
 
255
- it "Obtains mailto with text" do
256
- href = ExternalHref.send(
202
+ it 'obtains mailto with text' do
203
+ href = described_class.send(
257
204
  :new,
258
205
  'href',
259
- 'mailto:mslinn@mslinn.com Mike Slinn'.dup,
206
+ + 'mailto:mslinn@mslinn.com Mike Slinn',
260
207
  parse_context
261
208
  )
262
- href.send(:globals_initial, parse_context)
263
- linkk = href.send(:compute_linkk)
264
- href.send(:globals_update, href.helper.argv, linkk)
209
+ href.render TestLiquidContext.new
265
210
  expect(href.follow).to eq('')
266
211
  expect(href.link).to eq('mailto:mslinn@mslinn.com')
267
212
  expect(href.target).to eq('')
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,13 @@
1
- require "liquid"
2
- require "fileutils"
1
+ require 'jekyll'
2
+ require 'jekyll_plugin_logger'
3
+ require 'liquid'
4
+ require 'fileutils'
5
+ require 'yaml'
3
6
  require_relative "../lib/jekyll_href"
4
7
 
5
8
  RSpec.configure do |config|
6
9
  config.filter_run :focus
7
- config.order = "random"
10
+ # config.order = "random"
8
11
  config.run_all_when_everything_filtered = true
9
12
 
10
13
  # See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
@@ -12,3 +15,65 @@ RSpec.configure do |config|
12
15
 
13
16
  config.filter_run_when_matching focus: true
14
17
  end
18
+
19
+ Registers = Struct.new(:page, :site)
20
+
21
+ # Mock for Collections
22
+ class Collections
23
+ def values
24
+ []
25
+ end
26
+ end
27
+
28
+ # Mock for Site
29
+ class SiteMock
30
+ attr_reader :config
31
+
32
+ def initialize
33
+ @config = YAML.safe_load(File.read('../demo/_config.yml'))
34
+ @config['env'] = { 'JEKYLL_ENV' => 'development' }
35
+ end
36
+
37
+ def collections
38
+ Collections.new
39
+ end
40
+ end
41
+
42
+ class TestLiquidContext < Liquid::Context
43
+ def initialize
44
+ super
45
+
46
+ page = {
47
+ "content" => "blah blah",
48
+ "description" => "Jekyll plugin support demo",
49
+ "dir" => "/",
50
+ "excerpt" => nil,
51
+ "layout" => "default",
52
+ "name" => "index.html",
53
+ "path" => "index.html",
54
+ "title" => "Welcome",
55
+ "url" => "/",
56
+ }
57
+
58
+ @content = "Interior of the tag"
59
+ @registers = Registers.new(
60
+ page,
61
+ SiteMock.new
62
+ )
63
+ end
64
+ end
65
+
66
+ # Mock for Liquid::ParseContent
67
+ class TestParseContext < Liquid::ParseContext
68
+ attr_reader :line_number, :registers
69
+
70
+ def initialize
71
+ super
72
+ @line_number = 123
73
+
74
+ @registers = Registers.new(
75
+ { 'path' => 'path/to/page.html' },
76
+ SiteMock.new
77
+ )
78
+ end
79
+ end
@@ -1,15 +1,29 @@
1
1
  example_id | status | run_time |
2
2
  ----------------------------------------------------------------- | ------ | --------------- |
3
- /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:1] | passed | 0.00581 seconds |
4
- /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:2] | passed | 0.00416 seconds |
5
- /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:3] | passed | 0.00401 seconds |
6
- /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:4] | passed | 0.00384 seconds |
7
- /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:5] | passed | 0.00401 seconds |
8
- /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:6] | passed | 0.00405 seconds |
9
- /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:7] | passed | 0.00501 seconds |
10
- /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:8] | passed | 0.00461 seconds |
11
- /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:9] | passed | 0.00397 seconds |
12
- /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:10] | passed | 0.0039 seconds |
13
- /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:11] | passed | 0.00404 seconds |
14
- /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:12] | passed | 0.00427 seconds |
15
- /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:13] | passed | 0.0041 seconds |
3
+ ./spec/hash_array_spec.rb[1:1] | passed | 0.17104 seconds |
4
+ ./spec/href_spec.rb[1:1] | passed | 0.03236 seconds |
5
+ ./spec/href_spec.rb[1:2] | passed | 0.02884 seconds |
6
+ ./spec/href_spec.rb[1:3] | passed | 0.02956 seconds |
7
+ ./spec/href_spec.rb[1:4] | passed | 0.02841 seconds |
8
+ ./spec/href_spec.rb[1:5] | passed | 0.02897 seconds |
9
+ ./spec/href_spec.rb[1:6] | passed | 0.02866 seconds |
10
+ ./spec/href_spec.rb[1:7] | passed | 0.02966 seconds |
11
+ ./spec/href_spec.rb[1:8] | passed | 0.02983 seconds |
12
+ ./spec/href_spec.rb[1:9] | passed | 0.02735 seconds |
13
+ ./spec/href_spec.rb[1:10] | passed | 0.02928 seconds |
14
+ ./spec/href_spec.rb[1:11] | passed | 0.02861 seconds |
15
+ ./spec/href_spec.rb[1:12] | passed | 0.02958 seconds |
16
+ ./spec/href_spec.rb[1:13] | passed | 0.02714 seconds |
17
+ /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:1] | passed | 0.02582 seconds |
18
+ /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:2] | passed | 0.01031 seconds |
19
+ /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:3] | passed | 0.01045 seconds |
20
+ /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:4] | passed | 0.01038 seconds |
21
+ /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:5] | passed | 0.01081 seconds |
22
+ /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:6] | passed | 0.01053 seconds |
23
+ /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:7] | passed | 0.01125 seconds |
24
+ /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:8] | passed | 0.01113 seconds |
25
+ /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:9] | passed | 0.01088 seconds |
26
+ /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:10] | passed | 0.01066 seconds |
27
+ /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:11] | failed | 0.06099 seconds |
28
+ /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:12] | passed | 0.01096 seconds |
29
+ /mnt/_/work/jekyll/my_plugins/jekyll_href/spec/href_spec.rb[1:13] | passed | 0.01028 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.0
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-11 00:00:00.000000000 Z
11
+ date: 2023-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -28,58 +28,42 @@ dependencies:
28
28
  name: jekyll_all_collections
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
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:
33
+ version: 0.3.0
38
34
  - - ">="
39
35
  - !ruby/object:Gem::Version
40
- version: 0.2.0
41
- - !ruby/object:Gem::Dependency
42
- name: jekyll_plugin_logger
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
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: '0'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
43
+ version: 0.3.0
66
44
  - - ">="
67
45
  - !ruby/object:Gem::Version
68
- version: '0'
46
+ version: 0.3.1
69
47
  - !ruby/object:Gem::Dependency
70
- name: shellwords
48
+ name: jekyll_plugin_support
71
49
  requirement: !ruby/object:Gem::Requirement
72
50
  requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 0.6.0
73
54
  - - ">="
74
55
  - !ruby/object:Gem::Version
75
- version: '0'
56
+ version: 0.6.1
76
57
  type: :runtime
77
58
  prerelease: false
78
59
  version_requirements: !ruby/object:Gem::Requirement
79
60
  requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: 0.6.0
80
64
  - - ">="
81
65
  - !ruby/object:Gem::Version
82
- version: '0'
66
+ version: 0.6.1
83
67
  description: 'Generates an ''a href'' tag, possibly with target=''_blank'' and rel=''nofollow''.
84
68
 
85
69
  '
@@ -95,20 +79,23 @@ files:
95
79
  - README.md
96
80
  - Rakefile
97
81
  - jekyll_href.gemspec
82
+ - lib/hash_array.rb
83
+ - lib/href_summary_tag.rb
84
+ - lib/href_tag.rb
98
85
  - lib/jekyll_href.rb
99
86
  - lib/jekyll_href/version.rb
100
- - lib/jekyll_tag_helper2.rb
87
+ - spec/hash_array_spec.rb
101
88
  - spec/href_spec.rb
102
89
  - spec/spec_helper.rb
103
90
  - spec/status_persistence.txt
104
- homepage: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#href
91
+ homepage: https://www.mslinn.com/jekyll/3000-jekyll-plugins.html#href
105
92
  licenses:
106
93
  - MIT
107
94
  metadata:
108
95
  allowed_push_host: https://rubygems.org
109
96
  bug_tracker_uri: https://github.com/mslinn/jekyll_href/issues
110
97
  changelog_uri: https://github.com/mslinn/jekyll_href/CHANGELOG.md
111
- homepage_uri: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#href
98
+ homepage_uri: https://www.mslinn.com/jekyll/3000-jekyll-plugins.html#href
112
99
  source_code_uri: https://github.com/mslinn/jekyll_href
113
100
  post_install_message: |2+
114
101
 
@@ -133,6 +120,7 @@ signing_key:
133
120
  specification_version: 4
134
121
  summary: Generates an 'a href' tag, possibly with target='_blank' and rel='nofollow'.
135
122
  test_files:
123
+ - spec/hash_array_spec.rb
136
124
  - spec/href_spec.rb
137
125
  - spec/spec_helper.rb
138
126
  - spec/status_persistence.txt
@@ -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