jekyll_href 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6d09a2fc7a319e4fb417c383b15bb97acfc644cd795fefeba3faa5cbcf83403
4
- data.tar.gz: d0a2c065d042a1ff2cefb8a973849585fafe7d57da8f8dd512e7cf4ac6161257
3
+ metadata.gz: d29ce08e7cf07fc3acbe97e979f72e74d5110a32e3005d56b3910519f8edee6b
4
+ data.tar.gz: 798085924055ba3509413dccef85dcd584c2d781c3d32403d03ce9125b163349
5
5
  SHA512:
6
- metadata.gz: 034224a848331a861479db283806d0736e355cc042fdac5829405158f4bc777a6c15af2cf07b79739eaa272d40a452e3267a528c801fb14ddbdaa4444d336edb
7
- data.tar.gz: 18f59ff3419338872629d589adb3e9380fc963e9bda568afde8a45d8fbd8124a90bc7b45099262beaa67b8829708a9b762f93df3b9dfd29e0c0bb7a76aeb1740
6
+ metadata.gz: 13184917dbf55acf5e84fa64b01bc3c8c7446a75c5db61eadeca5087ee8c701d031687ca1c7c9412c00472635691369d4cd44f70bb8ae56e4789aeba1afdc956
7
+ data.tar.gz: b83722150b30f7845e26e7c065f982230581813aaefd5fac19ec33fecc19ef759f089d23b18b52892e932e8cca228880d4c849168101441ff6e676e9f6c4145a
data/.rubocop.yml CHANGED
@@ -12,6 +12,9 @@ AllCops:
12
12
  Layout/LineLength:
13
13
  Max: 150
14
14
 
15
+ Layout/MultilineOperationIndentation:
16
+ Enabled: false
17
+
15
18
  Layout/MultilineMethodCallIndentation:
16
19
  Enabled: false
17
20
 
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.0
@@ -0,0 +1,75 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "cwd": "${workspaceRoot}",
9
+ "name": "Attach rdebug-ide",
10
+ "request": "attach",
11
+ "remoteHost": "localhost",
12
+ "remotePort": "1234",
13
+ "remoteWorkspaceRoot": "/",
14
+ "restart": true,
15
+ "showDebuggerOutput": true,
16
+ "type": "Ruby",
17
+ },
18
+ {
19
+ "cwd": "${workspaceRoot}",
20
+ "debuggerPort": "1234",
21
+ "name": "Debug Jekyll",
22
+ "program": "/usr/local/bin/jekyll",
23
+ "args": [
24
+ "serve",
25
+ "--livereload_port", "35721",
26
+ "--force_polling",
27
+ "--host", "0.0.0.0",
28
+ "--port", "4001",
29
+ "--future",
30
+ "--incremental",
31
+ "--livereload",
32
+ "--drafts",
33
+ "--unpublished"
34
+ ],
35
+ "request": "launch",
36
+ "restart": true,
37
+ "showDebuggerOutput": true,
38
+ "stopOnEntry": true,
39
+ "type": "Ruby",
40
+ },
41
+ {
42
+ "name": "Debug Local Ruby",
43
+ "type": "Ruby",
44
+ "request": "launch",
45
+ "program": "${workspaceRoot}/main.rb"
46
+ },
47
+ {
48
+ "args": [
49
+ "-I",
50
+ "${workspaceRoot}",
51
+ "${file}"
52
+ ],
53
+ "cwd": "${workspaceRoot}",
54
+ "name": "RSpec - active spec file only",
55
+ "program": "/home/mslinn/.gems/bin/rspec",
56
+ "showDebuggerOutput": false,
57
+ "request": "launch",
58
+ "type": "Ruby",
59
+ "useBundler": true,
60
+ },
61
+ {
62
+ "args": [
63
+ "-I",
64
+ "${workspaceRoot}"
65
+ ],
66
+ "cwd": "${workspaceRoot}",
67
+ "name": "RSpec - all",
68
+ "program": "/home/mslinn/.gems/bin/rspec",
69
+ "request": "launch",
70
+ "showDebuggerOutput": false,
71
+ "type": "Ruby",
72
+ "useBundler": true,
73
+ }
74
+ ]
75
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "ruby.rubocop.configFilePath": ".rubocop.yml",
3
+ "ruby.rubocop.useBundler": true
4
+ }
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## HEAD / 2022-03-12
2
+ * Added unit tests
3
+
1
4
  ## 1.0.0 / 2022-03-11
2
5
  * Made into a Ruby gem and published on RubyGems.org as [jekyll_href](https://rubygems.org/gems/jekyll_href).
3
6
  * `bin/attach` script added for debugging
data/Gemfile CHANGED
@@ -5,4 +5,4 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in jekyll_href.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
8
+ gem "rake"
data/Gemfile.lock CHANGED
@@ -1,25 +1,76 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jekyll_href (1.0.0)
4
+ jekyll_href (1.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ addressable (2.8.0)
10
+ public_suffix (>= 2.0.2, < 5.0)
9
11
  ast (2.4.2)
10
12
  coderay (1.1.3)
13
+ colorator (1.1.0)
14
+ concurrent-ruby (1.1.9)
15
+ debase (0.2.4.1)
16
+ debase-ruby_core_source (>= 0.10.2)
17
+ debase-ruby_core_source (0.10.14)
11
18
  diff-lcs (1.5.0)
19
+ em-websocket (0.5.3)
20
+ eventmachine (>= 0.12.9)
21
+ http_parser.rb (~> 0)
22
+ eventmachine (1.2.7)
23
+ ffi (1.15.5)
24
+ forwardable-extended (2.6.0)
25
+ http_parser.rb (0.8.0)
26
+ i18n (1.10.0)
27
+ concurrent-ruby (~> 1.0)
28
+ jekyll (4.2.2)
29
+ addressable (~> 2.4)
30
+ colorator (~> 1.0)
31
+ em-websocket (~> 0.5)
32
+ i18n (~> 1.0)
33
+ jekyll-sass-converter (~> 2.0)
34
+ jekyll-watch (~> 2.0)
35
+ kramdown (~> 2.3)
36
+ kramdown-parser-gfm (~> 1.0)
37
+ liquid (~> 4.0)
38
+ mercenary (~> 0.4.0)
39
+ pathutil (~> 0.9)
40
+ rouge (~> 3.0)
41
+ safe_yaml (~> 1.0)
42
+ terminal-table (~> 2.0)
43
+ jekyll-sass-converter (2.2.0)
44
+ sassc (> 2.0.1, < 3.0)
45
+ jekyll-watch (2.2.1)
46
+ listen (~> 3.0)
47
+ kramdown (2.3.1)
48
+ rexml
49
+ kramdown-parser-gfm (1.1.0)
50
+ kramdown (~> 2.0)
51
+ liquid (4.0.3)
52
+ listen (3.7.1)
53
+ rb-fsevent (~> 0.10, >= 0.10.3)
54
+ rb-inotify (~> 0.9, >= 0.9.10)
55
+ mercenary (0.4.0)
12
56
  method_source (1.0.0)
13
57
  parallel (1.21.0)
14
58
  parser (3.1.1.0)
15
59
  ast (~> 2.4.1)
60
+ pathutil (0.16.2)
61
+ forwardable-extended (~> 2.6)
16
62
  pry (0.14.1)
17
63
  coderay (~> 1.1)
18
64
  method_source (~> 1.0)
65
+ public_suffix (4.0.6)
19
66
  rainbow (3.1.1)
20
67
  rake (13.0.6)
68
+ rb-fsevent (0.11.1)
69
+ rb-inotify (0.10.1)
70
+ ffi (~> 1.0)
21
71
  regexp_parser (2.2.1)
22
72
  rexml (3.2.5)
73
+ rouge (3.28.0)
23
74
  rspec (3.11.0)
24
75
  rspec-core (~> 3.11.0)
25
76
  rspec-expectations (~> 3.11.0)
@@ -50,20 +101,33 @@ GEM
50
101
  rubocop-performance (1.13.3)
51
102
  rubocop (>= 1.7.0, < 2.0)
52
103
  rubocop-ast (>= 0.4.0)
104
+ rubocop-rake (0.6.0)
105
+ rubocop (~> 1.0)
106
+ ruby-debug-ide (0.7.3)
107
+ rake (>= 0.8.1)
53
108
  ruby-progressbar (1.11.0)
54
- unicode-display_width (2.1.0)
109
+ safe_yaml (1.0.5)
110
+ sassc (2.4.0)
111
+ ffi (~> 1.9)
112
+ terminal-table (2.0.0)
113
+ unicode-display_width (~> 1.1, >= 1.1.1)
114
+ unicode-display_width (1.8.0)
55
115
 
56
116
  PLATFORMS
57
117
  x86_64-linux
58
118
 
59
119
  DEPENDENCIES
60
120
  bundler
121
+ debase
122
+ jekyll
61
123
  jekyll_href!
62
124
  pry
63
- rake (~> 13.0)
125
+ rake
64
126
  rspec
65
127
  rubocop
66
128
  rubocop-jekyll
129
+ rubocop-rake
130
+ ruby-debug-ide
67
131
 
68
132
  BUNDLED WITH
69
133
  2.3.7
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # `Jekyll_href`
1
+ `Jekyll_href`
2
+ [![Gem Version](https://badge.fury.io/rb/jekyll_href.svg)](https://badge.fury.io/rb/jekyll_href)
3
+ ===========
2
4
 
3
5
  `Jekyll_href` is a Jekyll plugin that provides a new Liquid tag: `href`.
4
6
  The Liquid tag generates and `<a href>` HTML tag, by default containing `target="_blank"` and `rel=nofollow`.
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
- task default: %i[]
4
+ # task default: %i[]
5
+ task :default => :spec
data/jekyll_href.gemspec CHANGED
@@ -32,9 +32,13 @@ Gem::Specification.new do |spec|
32
32
  spec.require_paths = ["lib"]
33
33
 
34
34
  spec.add_development_dependency 'bundler'
35
+ spec.add_development_dependency 'debase'
36
+ spec.add_development_dependency 'jekyll'
35
37
  spec.add_development_dependency 'pry'
36
38
  spec.add_development_dependency 'rake'
37
39
  spec.add_development_dependency 'rspec'
38
40
  spec.add_development_dependency 'rubocop'
39
41
  spec.add_development_dependency 'rubocop-jekyll'
42
+ spec.add_development_dependency 'rubocop-rake'
43
+ spec.add_development_dependency 'ruby-debug-ide'
40
44
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllHref
4
- VERSION = "1.0.0"
4
+ VERSION = '1.0.2'
5
5
  end
data/lib/jekyll_href.rb CHANGED
@@ -47,102 +47,139 @@ require_relative "jekyll_href/version"
47
47
  # @example Substitute name/value pair for the django-github variable:
48
48
  # {% href {{django-github}}/django/core/management/__init__.py#L398-L401
49
49
  # <code>django.core.management.execute_from_command_line</code> %}
50
-
51
50
  module JekyllHref
52
51
  class Error < StandardError; end
53
52
 
54
- class ExternalHref < Liquid::Tag
55
- # @param tag_name [String] is the name of the tag, which we already know.
56
- # @param command_line [Hash, String, Liquid::Tag::Parser] the arguments from the web page.
57
- # @param tokens [Liquid::ParseContext] tokenized command line
58
- # @return [void]
59
- def initialize(tag_name, command_line, tokens) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
60
- super
61
-
62
- @follow = " rel='nofollow'"
63
- @match = false
64
- @target = " target='_blank'"
53
+ class HrefSetup
54
+ attr_reader :follow, :match_keyword, :tokens, :target, :text
65
55
 
66
- tokens = command_line.strip.split
56
+ def initialize(tag_line, parse_context)
57
+ @tokens = tag_line.strip.split
58
+ @parse_context = parse_context
59
+ @follow = get_value('follow', " rel='nofollow'")
60
+ @target = get_value('notarget', " target='_blank'")
67
61
 
68
- follow_index = tokens.index("follow")
69
- if follow_index
70
- tokens.delete_at(follow_index)
71
- @follow = ""
62
+ @match_keyword = false
63
+ match_index = @tokens.index('match')
64
+ if match_index
65
+ context.delete_at(match_index)
66
+ @follow = ''
67
+ @match_keyword = true
68
+ @target = ''
72
69
  end
73
70
 
74
- target_index = tokens.index("notarget")
75
- if target_index
76
- tokens.delete_at(target_index)
77
- @target = ""
78
- end
71
+ finalize
72
+ end
79
73
 
80
- match_index = tokens.index("match")
81
- if match_index
82
- tokens.delete_at(match_index)
83
- @follow = ""
84
- @match = true
85
- @target = ""
74
+ def replace_vars(variables)
75
+ variables.each do |name, value|
76
+ @link = @link.gsub("{{#{name}}}", value)
86
77
  end
78
+ @link
79
+ end
80
+
81
+ private
87
82
 
88
- @link = tokens.shift
83
+ def finalize
84
+ @link = @tokens.shift
89
85
 
90
- @text = tokens.join(" ").strip
86
+ @text = @tokens.join(' ').strip
91
87
  if @text.empty?
92
88
  @text = "<code>${@link}</code>"
93
89
  @link = "https://#{@link}"
94
90
  end
95
91
 
96
- unless @link.start_with? "http"
97
- @follow = ""
98
- @target = ""
92
+ unless @link.start_with? 'http'
93
+ @follow = ''
94
+ @target = ''
99
95
  end
100
96
  end
101
97
 
102
- def match(context) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
103
- site = context.registers[:site]
104
- config = site.config['href']
105
- die_if_nomatch = !config.nil? && config['nomatch'] && config['nomatch']=='fatal'
98
+ def get_value(token, default_value)
99
+ value = default_value
100
+ target_index = @tokens.index(token)
101
+ if target_index
102
+ @tokens.delete_at(target_index)
103
+ value = ""
104
+ end
105
+ value
106
+ end
107
+ end
106
108
 
107
- path, fragment = @link.split('#')
109
+ class HrefRender
110
+ def initialize(context, href_setup)
111
+ @context = context
112
+ @site = @context.registers[:site]
113
+ @config = @site.config
114
+ @href_setup = href_setup
115
+ match(context) if @href_setup.match_keyword
116
+ end
117
+
118
+ def link
119
+ @href_setup.replace_vars @config['plugin-vars']
120
+ end
121
+
122
+ private
123
+
124
+ def handle_no_args
125
+ href_config = @config['href']
126
+ die_if_nomatch = !href_config.nil? &&
127
+ href_config['nomatch'] &&
128
+ href_config['nomatch'] == 'fatal'
129
+ if die_if_nomatch
130
+ abort "href error: No url matches '#{@link}'"
131
+ else
132
+ @link = "#"
133
+ @text = "<i>#{@link} is not available</i>"
134
+ end
135
+ end
108
136
 
109
- # puts "@link=#{@link}"
110
- # puts "site.posts[0].url = #{site.posts.docs[0].url}"
111
- # puts "site.posts[0].path = #{site.posts.docs[0].path}"
112
- posts = site.posts.docs.select { |x| x.url.include?(path) }
137
+ def match
138
+ path, fragment = @link.split('#')
139
+ posts = @site.posts.docs.select { |x| x.url.include?(path) }
113
140
  case posts.length
114
141
  when 0
115
- if die_if_nomatch
116
- abort "href error: No url matches '#{@link}'"
117
- else
118
- @link = "#"
119
- @text = "<i>#{@link} is not available</i>"
120
- end
142
+ handle_no_args
121
143
  when 1
122
144
  @link = "#{@link}\##{fragment}" if fragment
123
145
  else
124
- abort "Error: More than one url matched: #{ matches.join(", ")}"
146
+ abort "Error: More than one url matched: #{matches.join(", ")}"
125
147
  end
126
148
  end
149
+ end
127
150
 
128
- def replace_vars(context, link)
129
- variables = context.registers[:site].config['plugin-vars']
130
- variables.each do |name, value|
131
- # puts "#{name}=#{value}"
132
- link = link.gsub("{{#{name}}}", value)
133
- end
134
- link
151
+ class HrefTag < Liquid::Tag
152
+ # @param tag_name [String] is the name of the tag, which we already know.
153
+ # @param tag_line [Hash, String, Liquid::Tag::Parser] the contents between {% and %} in the web page (should be a string).
154
+ # @param parse_context [Liquid::ParseContext] looks like:
155
+ # <Liquid::ParseContext:0x00005595446e5800
156
+ # @template_options={
157
+ # :line_numbers=>true,
158
+ # :locale=>#<Liquid::I18n:0x00005595446e5760 @path="/home/mslinn/.gems/gems/liquid-4.0.3/lib/liquid/locales/en.yml">},
159
+ # @locale=#<Liquid::I18n:0x00005595446e5760
160
+ # @path="/home/mslinn/.gems/gems/liquid-4.0.3/lib/liquid/locales/en.yml">,
161
+ # @warnings=[],
162
+ # @depth=0,
163
+ # @partial=false,
164
+ # @options={:line_numbers=>true, :locale=>#<Liquid::I18n:0x00005595446e5760
165
+ # @path="/home/mslinn/.gems/gems/liquid-4.0.3/lib/liquid/locales/en.yml">},
166
+ # @error_mode=:strict,
167
+ # @line_number=9,
168
+ # @trim_whitespace=false>
169
+ # @return [void]
170
+ def initialize(tag_name, tag_line, parse_context)
171
+ super
172
+ @href_setup = HrefSetup.new(tag_line, parse_context)
135
173
  end
136
174
 
137
175
  # Method prescribed by the Jekyll plugin lifecycle.
176
+ # @param context [Liquid::Context] Context keeps the variable stack and resolves variables, as well as keywords
138
177
  # @return [String]
139
178
  def render(context)
140
- match(context) if @match
141
- link = replace_vars(context, @link)
142
- # puts "@link=#{@link}; link=#{link}"
143
- "<a href='#{link}'#{@target}#{@follow}>#{@text}</a>"
179
+ href_render = HrefRender.new(context, @href_setup)
180
+ "<a href='#{href_render.link}'#{@href_setup.target}#{@href_setup.follow}>#{@href_setup.text}</a>"
144
181
  end
145
182
  end
146
183
  end
147
184
 
148
- Liquid::Template.register_tag('href', JekyllHref::ExternalHref)
185
+ Liquid::Template.register_tag('href', JekyllHref::HrefTag)
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.0.0
4
+ version: 1.0.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: 2022-03-11 00:00:00.000000000 Z
11
+ date: 2022-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: debase
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: jekyll
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: pry
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +122,34 @@ dependencies:
94
122
  - - ">="
95
123
  - !ruby/object:Gem::Version
96
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: ruby-debug-ide
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
97
153
  description: Generates an 'a href' tag, possibly with target='_blank' and rel='nofollow'.
98
154
  email:
99
155
  - mslinn@mslinn.com
@@ -102,6 +158,9 @@ extensions: []
102
158
  extra_rdoc_files: []
103
159
  files:
104
160
  - ".rubocop.yml"
161
+ - ".ruby-version"
162
+ - ".vscode/launch.json"
163
+ - ".vscode/settings.json"
105
164
  - CHANGELOG.md
106
165
  - Gemfile
107
166
  - Gemfile.lock