yard_ghurt 1.2.0 → 1.2.1

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: 3d6655a3fefa8677dd2b00ea73dbd7b87cf1c6d13b888ed67c29feb899f2555e
4
- data.tar.gz: 52ffccc6f6a7d98e7865396b1c8c3e2b8c9a58452d3e724b0d0eb0c75e3495ab
3
+ metadata.gz: 1ba77aa5e6b3ec3b9467138381e4c0af1e3c7e2cd1b08f48b496b6ccbce682a7
4
+ data.tar.gz: 1343014b656ac37ca4639ee0ff4ec0f9efbdbff6c74cac272a733287ea2406ca
5
5
  SHA512:
6
- metadata.gz: bcab8039ee10ff48858cd161483bbbc32ebe23a038f32303defe23081932ab4bc97b7e0d64a4de15307c14993cdf4d311d7385ed00a920af324b641b3e11d110
7
- data.tar.gz: 31b278e7cbc842b3431eda53f8737bf957ff7068c4796ca984c0362040777b31f8542270e0844942b7a47906b464a41be7cf155712f4a9f1a05b2a41c391ad93
6
+ metadata.gz: e86568ddae7285e682359272e8376af0c0c72a3559e61be6db1e7f165f38117484bddcb137a978fd29ce6e2144d5d60ee3bd2ec717daee86aea9fa8254debfb8
7
+ data.tar.gz: aa4842125f2dfb966543b7bc78771d928da1de5d44cc6d7ad1b6bf1d57ad1096f6f07d5cfc4064bb80eac9556a20f77dd02ac30fd96ce7bf3c84b84e4f58cc14
data/CHANGELOG.md CHANGED
@@ -1,8 +1,22 @@
1
1
  # Changelog | YardGhurt
2
2
 
3
- Format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ Format is based on [Keep a Changelog v1.0.0](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning v2.0.0](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [[Unreleased]](https://github.com/esotericpig/yard_ghurt/compare/v1.2.1...HEAD)
9
+ -
10
+
11
+
12
+ ## [v1.2.1] - 2021-06-16
13
+ ### Fixed
14
+ - Fixed to work with YARD v0.9.25+
15
+ - From v0.9.25, YARD changed to use RedCarpert's method of trying to create GitHub-style anchor links. RedCarpet does NOT match GitHub's algorithm exactly, so it all got messed up. I changed the code to grab the new `id="..."` field from `<h\d+...` tags and use that as the YARD ID. I tried recreating RedCarpert's C code (`rndr_header_anchor()` in `ext/redcarpet/html.c`) but this failed miserably, so resorted to just this. All that matters is that it works!
16
+
17
+ ### Changed
18
+ - Formatted code using RuboCop.
4
19
 
5
- ## [[Unreleased]](https://github.com/esotericpig/yard_ghurt/compare/v1.2.0...master)
6
20
 
7
21
  ## [v1.2.0] - 2020-02-29
8
22
  ### Added
@@ -18,6 +32,7 @@ Format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
18
32
  - In AnchorLinks, don't use obsolete method URI.escape()/encode()
19
33
  - This outputted a lot of warnings
20
34
 
35
+
21
36
  ## [v1.1.0] - 2019-07-31
22
37
  ### Added
23
38
  - Added environment var *dryrun* to GFMFixTask:
@@ -30,6 +45,7 @@ Format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
30
45
  - lib/yard_ghurt/ghp_syncer_task.rb => lib/yard_ghurt/ghp_sync_task.rb
31
46
  - Updated development dependency gems
32
47
 
48
+
33
49
  ## [v1.0.1] - 2019-07-28
34
50
  ### Changed
35
51
  - Some minor comments/doc
@@ -38,6 +54,7 @@ Format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
38
54
  ### Fixed
39
55
  - In GFMFixerTask, ignore empty lines
40
56
 
57
+
41
58
  ## [v1.0.0] - 2019-07-23
42
59
  ### Added
43
60
  - .gitignore
data/Gemfile CHANGED
@@ -1,24 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
- #--
5
- # This file is part of YardGhurt.
6
- # Copyright (c) 2019 Jonathan Bradley Whited (@esotericpig)
7
- #
8
- # YardGhurt is free software: you can redistribute it and/or modify
9
- # it under the terms of the GNU Lesser General Public License as published by
10
- # the Free Software Foundation, either version 3 of the License, or
11
- # (at your option) any later version.
12
- #
13
- # YardGhurt is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU Lesser General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU Lesser General Public License
19
- # along with YardGhurt. If not, see <https://www.gnu.org/licenses/>.
20
- #++
21
-
22
4
 
23
5
  source 'https://rubygems.org'
24
6
 
data/README.md CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/yard_ghurt.svg)](https://badge.fury.io/rb/yard_ghurt)
4
4
 
5
- [![Documentation](https://img.shields.io/badge/doc-yard-%23A0522D.svg?style=for-the-badge)](https://esotericpig.github.io/docs/yard_ghurt/yardoc/index.html)
6
- [![Source Code](https://img.shields.io/badge/source-github-%23A0522D.svg?style=for-the-badge)](https://github.com/esotericpig/yard_ghurt)
7
- [![Changelog](https://img.shields.io/badge/changelog-md-%23A0522D.svg?style=for-the-badge)](CHANGELOG.md)
8
- [![License](https://img.shields.io/github/license/esotericpig/yard_ghurt.svg?color=%23A0522D&style=for-the-badge)](LICENSE.txt)
5
+ [![Documentation](https://img.shields.io/badge/doc-yard-%23A0522D.svg)](https://esotericpig.github.io/docs/yard_ghurt/yardoc/index.html)
6
+ [![Source Code](https://img.shields.io/badge/source-github-%23211F1F.svg)](https://github.com/esotericpig/yard_ghurt)
7
+ [![Changelog](https://img.shields.io/badge/changelog-md-%23A0522D.svg)](CHANGELOG.md)
8
+ [![License](https://img.shields.io/github/license/esotericpig/yard_ghurt.svg)](LICENSE.txt)
9
9
 
10
10
  <u>YARD</u>oc <u>G</u>it<u>Hu</u>b <u>R</u>ake <u>T</u>asks
11
11
 
@@ -60,6 +60,8 @@ $ bundle exec rake install:local
60
60
 
61
61
  ## [Using](#contents)
62
62
 
63
+ Currently, you can't use this project as a YARDoc Plugin, but planning on it for v2.0. Read the [TODO](TODO.md) for more info.
64
+
63
65
  **Rake Tasks:**
64
66
 
65
67
  | Task | Description |
@@ -78,6 +80,16 @@ $ bundle exec rake install:local
78
80
 
79
81
  Fix (find & replace) text in the GitHub Flavored Markdown (GFM) files in the YARDoc directory, for differences between the two formats.
80
82
 
83
+ **Very Important!**
84
+
85
+ In order for this to work, you must also add `redcarpet` as a dependency, per YARDoc's documentation:
86
+
87
+ ```Ruby
88
+ spec.add_development_dependency 'redcarpet','~> X.X' # For YARDoc Markdown (*.md)
89
+ ```
90
+
91
+ Else, you'll get a bunch of `label-*` relative links.
92
+
81
93
  You can set *dry_run* on the command line:
82
94
 
83
95
  `$ rake yard_gfm_fix dryrun=true`
@@ -90,16 +102,16 @@ YardGhurt::GFMFixTask.new() do |task|
90
102
  task.dry_run = false
91
103
  task.fix_code_langs = true
92
104
  task.md_files = ['index.html']
93
-
94
- task.before = Proc.new() do |task,args|
105
+
106
+ task.before = Proc.new() do |t2,args|
95
107
  # Delete this file as it's never used (index.html is an exact copy)
96
- YardGhurt.rm_exist(File.join(task.doc_dir,'file.README.html'))
97
-
108
+ YardGhurt.rm_exist(File.join(t2.doc_dir,'file.README.html'))
109
+
98
110
  # Root dir of my GitHub Page for CSS/JS
99
- GHP_ROOT_DIR = YardGhurt.to_bool(args.dev) ? '../../esotericpig.github.io' : '../../..'
100
-
101
- task.css_styles << %Q(<link rel="stylesheet" type="text/css" href="#{GHP_ROOT_DIR}/css/prism.css" />)
102
- task.js_scripts << %Q(<script src="#{GHP_ROOT_DIR}/js/prism.js"></script>)
111
+ ghp_root_dir = YardGhurt.to_bool(args.dev) ? '../../esotericpig.github.io' : '../../..'
112
+
113
+ t2.css_styles << %Q(<link rel="stylesheet" type="text/css" href="#{ghp_root_dir}/css/prism.css" />)
114
+ t2.js_scripts << %Q(<script src="#{ghp_root_dir}/js/prism.js"></script>)
103
115
  end
104
116
  end
105
117
  ```
@@ -126,7 +138,7 @@ YardGhurt::GFMFixTask.new(:yard_fix) do |task|
126
138
  task.js_scripts << '<script>document.write("Hello World!");</script>'
127
139
  task.md_files = ['index.html']
128
140
  task.verbose = false
129
-
141
+
130
142
  task.before = Proc.new() {|task,args| puts "Hi, #{args.name}!"}
131
143
  task.during = Proc.new() {|task,args,file| puts "#{args.name} can haz #{file}?"}
132
144
  task.after = Proc.new() {|task,args| puts "Goodbye, #{args.name}!"}
@@ -159,7 +171,7 @@ YardGhurt::GHPSyncTask.new(:ghp_doc) do |task|
159
171
  task.strict = true # Fail if doc_dir doesn't exist
160
172
  task.sync_args << '--delete-after'
161
173
  task.sync_cmd = '/usr/bin/rsync'
162
-
174
+
163
175
  task.before = Proc.new() {|task,args| puts "Hi, #{args.name}!"}
164
176
  task.after = Proc.new() {|task,args| puts "Goodbye, #{args.name}!"}
165
177
  end
@@ -276,6 +288,7 @@ Usage: yard_ghurt [options]
276
288
 
277
289
  ```
278
290
  $ git clone 'https://github.com/esotericpig/yard_ghurt.git'
291
+ $ cd yard_ghurt
279
292
  $ bundle install
280
293
  $ bundle exec rake -T
281
294
  ```
@@ -352,7 +365,7 @@ Newline
352
365
  [GNU LGPL v3+](LICENSE.txt)
353
366
 
354
367
  > YardGhurt (<https://github.com/esotericpig/yard_ghurt>)
355
- > Copyright (c) 2019-2020 Jonathan Bradley Whited (@esotericpig)
368
+ > Copyright (c) 2019-2021 Jonathan Bradley Whited
356
369
  >
357
370
  > YardGhurt is free software: you can redistribute it and/or modify
358
371
  > it under the terms of the GNU Lesser General Public License as published by
data/Rakefile CHANGED
@@ -1,68 +1,55 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
- #--
5
- # This file is part of YardGhurt.
6
- # Copyright (c) 2019 Jonathan Bradley Whited (@esotericpig)
7
- #
8
- # YardGhurt is free software: you can redistribute it and/or modify
9
- # it under the terms of the GNU Lesser General Public License as published by
10
- # the Free Software Foundation, either version 3 of the License, or
11
- # (at your option) any later version.
12
- #
13
- # YardGhurt is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU Lesser General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU Lesser General Public License
19
- # along with YardGhurt. If not, see <https://www.gnu.org/licenses/>.
20
- #++
21
-
22
4
 
23
5
  require 'bundler/gem_tasks'
24
6
 
7
+ require 'rake/clean'
8
+
25
9
  require 'yard'
26
10
  require 'yard_ghurt'
27
11
 
28
- require 'rake/clean'
29
12
 
30
- task default: [:yard,:yard_gfm_fix]
13
+ task default: [:doc]
31
14
 
32
15
  CLEAN.exclude('.git/','stock/')
33
16
  CLOBBER.include('doc/')
34
17
 
35
- YARD::Rake::YardocTask.new() do |task|
18
+
19
+ desc 'Generate documentation (YARDoc)'
20
+ task :doc,%i[] => %i[ yard yard_gfm_fix ] do |task|
21
+ # pass
22
+ end
23
+
24
+ YARD::Rake::YardocTask.new do |task|
36
25
  task.files = [File.join('lib','**','*.rb')]
37
-
38
- task.options += ['--files','CHANGELOG.md,LICENSE.txt']
26
+
27
+ task.options += ['--files','CHANGELOG.md,LICENSE.txt,TODO.md']
39
28
  task.options += ['--readme','README.md']
40
-
29
+
41
30
  task.options << '--protected' # Show protected methods
42
31
  task.options += ['--template-path',File.join('yard','templates')]
43
32
  task.options += ['--title',"YardGhurt v#{YardGhurt::VERSION} Doc"]
44
33
  end
45
34
 
46
- desc 'Generate pristine YARDoc'
47
- task :yard_fresh => [:clobber,:yard,:yard_gfm_fix] do |task|
48
- end
49
-
50
- YardGhurt::GFMFixTask.new() do |task|
51
- task.arg_names = [:dev]
35
+ YardGhurt::GFMFixTask.new do |task|
36
+ task.arg_names = %i[ dev ]
52
37
  task.dry_run = false
53
38
  task.fix_code_langs = true
54
-
55
- task.before = Proc.new() do |task,args|
39
+
40
+ task.before = proc do |t2,args|
41
+ # Do not delete 'file.README.html', as we need it for testing.
42
+
56
43
  # Root dir of my GitHub Page for CSS/JS
57
- GHP_ROOT_DIR = YardGhurt.to_bool(args.dev) ? '../../esotericpig.github.io' : '../../..'
58
-
59
- task.css_styles << %Q(<link rel="stylesheet" type="text/css" href="#{GHP_ROOT_DIR}/css/prism.css" />)
60
- task.js_scripts << %Q(<script src="#{GHP_ROOT_DIR}/js/prism.js"></script>)
44
+ ghp_root_dir = YardGhurt.to_bool(args.dev) ? '../../esotericpig.github.io' : '../../..'
45
+
46
+ t2.css_styles << %Q(<link rel="stylesheet" type="text/css" href="#{ghp_root_dir}/css/prism.css" />)
47
+ t2.js_scripts << %Q(<script src="#{ghp_root_dir}/js/prism.js"></script>)
61
48
  end
62
49
  end
63
50
 
64
51
  # Probably not useful for others.
65
- YardGhurt::GHPSyncTask.new() do |task|
52
+ YardGhurt::GHPSyncTask.new do |task|
66
53
  task.ghp_dir = '../esotericpig.github.io/docs/yard_ghurt/yardoc'
67
54
  task.sync_args << '--delete-after'
68
55
  end
data/bin/yard_ghurt CHANGED
@@ -4,20 +4,9 @@
4
4
 
5
5
  #--
6
6
  # This file is part of YardGhurt.
7
- # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
8
- #
9
- # YardGhurt is free software: you can redistribute it and/or modify
10
- # it under the terms of the GNU Lesser General Public License as published by
11
- # the Free Software Foundation, either version 3 of the License, or
12
- # (at your option) any later version.
13
- #
14
- # YardGhurt is distributed in the hope that it will be useful,
15
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- # GNU Lesser General Public License for more details.
18
- #
19
- # You should have received a copy of the GNU Lesser General Public License
20
- # along with YardGhurt. If not, see <https://www.gnu.org/licenses/>.
7
+ # Copyright (c) 2020-2021 Jonathan Bradley Whited
8
+ #
9
+ # SPDX-License-Identifier: LGPL-3.0-or-later
21
10
  #++
22
11
 
23
12
 
@@ -25,5 +14,5 @@ require 'yard_ghurt'
25
14
 
26
15
 
27
16
  # @since 1.2.0
28
- yg = YardGhurt::App.new()
29
- yg.run()
17
+ yg = YardGhurt::App.new
18
+ yg.run
data/lib/yard_ghurt.rb CHANGED
@@ -1,23 +1,11 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: UTF-8
3
2
  # frozen_string_literal: true
4
3
 
5
4
  #--
6
5
  # This file is part of YardGhurt.
7
- # Copyright (c) 2019-2020 Jonathan Bradley Whited (@esotericpig)
8
- #
9
- # YardGhurt is free software: you can redistribute it and/or modify
10
- # it under the terms of the GNU Lesser General Public License as published by
11
- # the Free Software Foundation, either version 3 of the License, or
12
- # (at your option) any later version.
13
- #
14
- # YardGhurt is distributed in the hope that it will be useful,
15
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- # GNU Lesser General Public License for more details.
18
- #
19
- # You should have received a copy of the GNU Lesser General Public License
20
- # along with YardGhurt. If not, see <https://www.gnu.org/licenses/>.
6
+ # Copyright (c) 2019-2021 Jonathan Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: LGPL-3.0-or-later
21
9
  #++
22
10
 
23
11
 
@@ -31,58 +19,58 @@ require 'yard_ghurt/version'
31
19
 
32
20
  ###
33
21
  # YARDoc GitHub Rake Tasks
34
- #
35
- # @author Jonathan Bradley Whited (@esotericpig)
22
+ #
23
+ # @author Jonathan Bradley Whited
36
24
  # @since 1.0.0
37
25
  ###
38
26
  module YardGhurt
39
27
  # Internal code should use +Util.+!
40
28
  # See {Util} for details.
41
29
  include Util
42
-
30
+
43
31
  ###
44
32
  # A simple CLI app used in file +bin/yard_ghurt+.
45
- #
33
+ #
46
34
  # Mainly for getting GitHub/YARDoc anchor link IDs.
47
- #
48
- # @author Jonathan Bradley Whited (@esotericpig)
35
+ #
36
+ # @author Jonathan Bradley Whited
49
37
  # @since 1.2.0
50
38
  ###
51
39
  class App
52
40
  attr_reader :args
53
-
41
+
54
42
  def initialize(args=ARGV)
55
43
  super()
56
-
44
+
57
45
  @args = args
58
46
  end
59
-
60
- def run()
61
- parser = OptionParser.new() do |op|
47
+
48
+ def run
49
+ parser = OptionParser.new do |op|
62
50
  op.program_name = 'yard_ghurt'
63
51
  op.version = VERSION
64
-
52
+
65
53
  op.banner = "Usage: #{op.program_name} [options]"
66
-
54
+
67
55
  op.on('-a','--anchor <string>','Print GitHub & YARDoc anchor link IDs of <string>') do |str|
68
- al = AnchorLinks.new()
56
+ al = AnchorLinks.new
69
57
  puts "GitHub: #{al.to_github_anchor_id(str)}"
70
58
  puts "YARDoc: #{al.to_yard_anchor_id(str)}"
71
59
  exit
72
60
  end
73
61
  op.on('-g','--github <string>','Print GitHub anchor link ID of <string>') do |str|
74
- al = AnchorLinks.new()
62
+ al = AnchorLinks.new
75
63
  puts al.to_github_anchor_id(str)
76
64
  exit
77
65
  end
78
66
  op.on('-y','--yard <string>','Print YARDoc anchor link ID of <string>') do |str|
79
- al = AnchorLinks.new()
67
+ al = AnchorLinks.new
80
68
  puts al.to_yard_anchor_id(str)
81
69
  exit
82
70
  end
83
-
71
+
84
72
  op.separator op.summary_indent + '---'
85
-
73
+
86
74
  op.on_tail('-h','--help','Print this help') do
87
75
  puts op
88
76
  exit
@@ -92,7 +80,7 @@ module YardGhurt
92
80
  exit
93
81
  end
94
82
  end
95
-
83
+
96
84
  parser.parse!(@args)
97
85
  puts parser # Print help if nothing was parsed
98
86
  end
@@ -1,23 +1,11 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: UTF-8
3
2
  # frozen_string_literal: true
4
3
 
5
4
  #--
6
5
  # This file is part of YardGhurt.
7
- # Copyright (c) 2019-2020 Jonathan Bradley Whited (@esotericpig)
8
- #
9
- # YardGhurt is free software: you can redistribute it and/or modify
10
- # it under the terms of the GNU Lesser General Public License as published by
11
- # the Free Software Foundation, either version 3 of the License, or
12
- # (at your option) any later version.
13
- #
14
- # YardGhurt is distributed in the hope that it will be useful,
15
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- # GNU Lesser General Public License for more details.
18
- #
19
- # You should have received a copy of the GNU Lesser General Public License
20
- # along with YardGhurt. If not, see <https://www.gnu.org/licenses/>.
6
+ # Copyright (c) 2019-2021 Jonathan Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: LGPL-3.0-or-later
21
9
  #++
22
10
 
23
11
 
@@ -27,249 +15,252 @@ require 'uri'
27
15
  module YardGhurt
28
16
  ###
29
17
  # A "database" of anchor links specific to GitHub Flavored Markdown (GFM) & YARDoc.
30
- #
18
+ #
31
19
  # You can use this by itself to view what anchor IDs would be generated:
32
20
  # al = YardGhurt::AnchorLinks.new()
33
- #
21
+ #
34
22
  # puts al.to_github_anchor_id('This is a test!')
35
23
  # puts al.to_yard_anchor_id('This is a test!')
36
- #
24
+ #
37
25
  # # Output:
38
26
  # # ---
39
27
  # # this-is-a-test
40
28
  # # This_is_a_test_
41
- #
29
+ #
42
30
  # Be aware that YARDoc depends on a common number that will be incremented for all duplicates,
43
31
  # while GFM's number is only local to each specific duplicate:
44
32
  # al = YardGhurt::AnchorLinks.new()
45
33
  # name = 'This is a test!'
46
- #
34
+ #
47
35
  # puts al.to_yard_anchor_id(name) # This_is_a_test_
48
36
  # puts al.to_yard_anchor_id(name) # This_is_a_test_
49
- #
37
+ #
50
38
  # puts al.to_github_anchor_id(name) # this-is-a-test
51
39
  # puts al.to_github_anchor_id(name) # this-is-a-test
52
- #
40
+ #
53
41
  # al << name # Officially add it to the database
54
- #
42
+ #
55
43
  # # Instead of being 0 & 0, will be 0 & 1 (incremented),
56
44
  # # even without being added to the database
57
45
  # puts al.to_yard_anchor_id(name) # This_is_a_test_0
58
46
  # puts al.to_yard_anchor_id(name) # This_is_a_test_1
59
- #
47
+ #
60
48
  # puts al.to_github_anchor_id(name) # this-is-a-test-1
61
49
  # puts al.to_github_anchor_id(name) # this-is-a-test-1
62
- #
50
+ #
63
51
  # name = 'This is another test!'
64
52
  # al << name # Officially add it to the database
65
- #
53
+ #
66
54
  # # Instead of being 0 & 1, will be 2 & 3 (global increment),
67
55
  # # even without being added to the database
68
56
  # puts al.to_yard_anchor_id(name) # This_is_another_test_2
69
57
  # puts al.to_yard_anchor_id(name) # This_is_another_test_3
70
- #
58
+ #
71
59
  # puts al.to_github_anchor_id(name) # this-is-another-test-1
72
60
  # puts al.to_github_anchor_id(name) # this-is-another-test-1
73
- #
74
- # @author Jonathan Bradley Whited (@esotericpig)
61
+ #
62
+ # @author Jonathan Bradley Whited
75
63
  # @since 1.0.0
76
- #
64
+ #
77
65
  # @see GFMFixTask
78
66
  ###
79
67
  class AnchorLinks
80
68
  # @return [Hash] the GFM-style anchor IDs pointing to their YARDoc ID equivalents that have been added
81
69
  attr_reader :anchor_ids
82
-
70
+
83
71
  # @return [Set] the YARDoc anchor IDs that have been added
84
72
  attr_accessor :yard_anchor_ids
85
-
73
+
86
74
  # @return [Integer] the next YARDoc number to use if there is a duplicate anchor ID
87
75
  attr_accessor :yard_dup_num
88
-
89
- def initialize()
90
- reset()
76
+
77
+ def initialize
78
+ super()
79
+ reset
91
80
  end
92
-
81
+
93
82
  # Reset the database back to its fresh, pristine self,
94
83
  # including common numbers for duplicates.
95
- def reset()
84
+ def reset
96
85
  @anchor_ids = {}
97
- @yard_anchor_ids = Set.new()
86
+ @yard_anchor_ids = Set.new
98
87
  @yard_dup_num = 0
99
88
  end
100
-
89
+
101
90
  # (see #add_anchor)
102
91
  def <<(name)
103
92
  return add_anchor(name)
104
93
  end
105
-
94
+
106
95
  # (see #store_anchor)
107
96
  def []=(github_anchor_id,yard_anchor_id)
108
- return store_anchor(github_anchor_id,yard_anchor_id)
97
+ store_anchor(github_anchor_id,yard_anchor_id)
109
98
  end
110
-
99
+
111
100
  # Convert +name+ (header text) to a GFM and YARDoc anchor ID and add the IDs to the database.
112
- #
113
- # @param name [String] the name (header text) to convert to anchor IDs and add to the database
114
- #
101
+ #
102
+ # @note +yard_id:+ was added in v1.2.1 for YARD v0.9.25+.
103
+ #
104
+ # @param name [String] the name (header text) to convert to anchor IDs and add to the database
115
105
  # @return [self]
116
- def add_anchor(name)
117
- store_anchor(to_github_anchor_id(name),to_yard_anchor_id(name))
118
-
106
+ def add_anchor(name,yard_id: nil)
107
+ yard_id = to_yard_anchor_id(name) if yard_id.nil?
108
+
109
+ store_anchor(to_github_anchor_id(name),yard_id)
110
+
119
111
  return self
120
112
  end
121
-
113
+
122
114
  # Escape +str+ for the web (e.g., "%20" for a space).
123
- #
115
+ #
124
116
  # Mainly used for non-English languages.
125
- #
117
+ #
126
118
  # @param str [String] the string to escape
127
- #
119
+ #
128
120
  # @return [String] the escaped string
129
- #
121
+ #
130
122
  # @since 1.2.0
131
123
  def self.escape(str)
132
124
  # URI.escape()/encode() is obsolete
133
125
  return URI.encode_www_form_component(str)
134
126
  end
135
-
127
+
136
128
  # Merge +anchor_ids+ with {anchor_ids} and {yard_anchor_ids}.
137
- #
129
+ #
138
130
  # @param anchor_ids [Hash] the anchor IDs (of GFM anchor IDs to YARDoc anchor IDs) to merge
139
131
  def merge_anchor_ids!(anchor_ids)
140
132
  @anchor_ids.merge!(anchor_ids)
141
133
  @yard_anchor_ids.merge(anchor_ids.values)
142
-
134
+
143
135
  return @anchor_ids
144
136
  end
145
-
137
+
146
138
  # Store & associate key +github_anchor_id+ with value +yard_anchor_id+,
147
139
  # and add +yard_anchor_id+ to the YARDoc anchor IDs.
148
- #
140
+ #
149
141
  # @param github_anchor_id [String] the GitHub anchor ID; the key
150
142
  # @param yard_anchor_id [String] the YARDoc anchor ID; the value
151
- #
143
+ #
152
144
  # @return [String] the +yard_anchor_id+ added
153
145
  def store_anchor(github_anchor_id,yard_anchor_id)
154
146
  @anchor_ids[github_anchor_id] = yard_anchor_id
155
147
  @yard_anchor_ids << yard_anchor_id
156
-
148
+
157
149
  return yard_anchor_id
158
150
  end
159
-
151
+
160
152
  def anchor_ids=(anchor_ids)
161
153
  @anchor_ids = anchor_ids
162
154
  @yard_anchor_ids.merge(anchor_ids.values)
163
-
164
- return @anchor_ids
165
155
  end
166
-
156
+
167
157
  # (see #anchor_id)
168
158
  def [](github_anchor_id)
169
159
  return anchor_id(github_anchor_id)
170
160
  end
171
-
161
+
172
162
  # Get the YARDoc anchor ID associated with this +github_anchor_id+.
173
- #
163
+ #
174
164
  # @param github_anchor_id [String] the GitHub anchor ID key to look up
175
- #
165
+ #
176
166
  # @return [String,nil] the YARDoc anchor ID associated with +github_anchor_id+
177
167
  def anchor_id(github_anchor_id)
178
168
  return @anchor_ids[github_anchor_id]
179
169
  end
180
-
170
+
181
171
  # Check if +id+ exists in the database of YARDoc anchor IDs
182
- #
172
+ #
183
173
  # @param id [String] the YARDoc anchor ID to check
184
- #
174
+ #
185
175
  # @return [true,false] whether this ID exists in the database of YARDoc anchor IDs
186
176
  def yard_anchor_id?(id)
187
177
  return @yard_anchor_ids.include?(id)
188
178
  end
189
-
179
+
190
180
  # Convert +name+ (header text) to a GitHub anchor ID.
191
- #
181
+ #
192
182
  # If the converted ID already exists in the database,
193
183
  # then the ID will be updated according to GFM rules.
194
- #
184
+ #
195
185
  # @param name [String] the name (header text) to convert
196
- #
186
+ #
197
187
  # @return [String] the converted GitHub anchor ID for this database
198
- #
188
+ #
199
189
  # @see https://gist.github.com/asabaylus/3071099#gistcomment-2834467
200
190
  # @see https://github.com/jch/html-pipeline/blob/master/lib/html/pipeline/toc_filter.rb
201
191
  def to_github_anchor_id(name)
202
- id = name.dup()
203
-
204
- id.strip!()
192
+ id = name.dup
193
+
194
+ id.strip!
205
195
  id.gsub!(/&[^;]+;/,'') # Remove entities: &...;
206
196
  id.gsub!(/[^\p{Word}\- ]/u,'')
207
197
  id.tr!(' ','-')
208
-
198
+
209
199
  if RUBY_VERSION >= '2.4'
210
200
  id.downcase!(:ascii)
211
201
  else
212
- id.downcase!()
202
+ id.downcase!
213
203
  end
214
-
204
+
215
205
  id = self.class.escape(id) # For non-English languages
216
-
206
+
217
207
  # Duplicates
218
208
  dup_num = 1
219
- orig_id = id.dup()
220
-
209
+ orig_id = id.dup
210
+
221
211
  while @anchor_ids.key?(id)
222
212
  id = "#{orig_id}-#{dup_num}"
223
213
  dup_num += 1
224
214
  end
225
-
215
+
226
216
  return id
227
217
  end
228
-
218
+
229
219
  # Dumps the key-value database of GFM & YARDoc anchor IDs.
230
- #
220
+ #
231
221
  # @return [String] the database of anchor IDs as a String
232
- def to_s()
233
- s = ''.dup()
234
-
235
- @anchor_ids.keys.sort_by{|key| key.to_s()}.each do |key|
222
+ def to_s
223
+ s = ''.dup
224
+
225
+ @anchor_ids.keys.sort_by(&:to_s).each do |key|
236
226
  s << "[#{key}] => '#{@anchor_ids[key]}'\n"
237
227
  end
238
-
228
+
239
229
  return s
240
230
  end
241
-
231
+
242
232
  # Convert +name+ (header text) to a YARDoc anchor ID.
243
- #
233
+ #
244
234
  # If the converted ID already exists in the database,
245
235
  # then the ID will be updated according to YARDoc rules,
246
236
  # which requires incrementing a common number variable.
247
- #
248
- # The logic for this is pulled from +doc/app.js#generateTOC()+,
249
- # which you can generate using +rake yard+ or +yardoc+ on the command line.
250
- #
237
+ #
238
+ # The logic for this is pulled from +doc/app.js#generateTOC()+
239
+ # (or +doc/js/app.js+), which you can generate using +rake yard+
240
+ # or +yardoc+ on the command line.
241
+ #
251
242
  # @note Be aware that this will increment a common number variable
252
243
  # every time you call this with a duplicate.
253
- #
244
+ #
254
245
  # @param name [String] the name (header text) to convert
255
- #
246
+ #
256
247
  # @return [String] the converted YARDoc anchor ID for this database
257
248
  def to_yard_anchor_id(name)
258
- id = name.dup()
259
-
260
- id.strip!()
249
+ id = name.dup
250
+
251
+ id.strip!
261
252
  id.gsub!(/&[^;]+;/,'_') # Replace entities: &...;
262
253
  id.gsub!(/[^a-z0-9-]/i,'_')
263
254
  id = self.class.escape(id) # For non-English languages
264
-
255
+
265
256
  # Duplicates
266
- orig_id = id.dup()
267
-
257
+ orig_id = id.dup
258
+
268
259
  while @yard_anchor_ids.include?(id)
269
260
  id = "#{orig_id}#{@yard_dup_num}"
270
261
  @yard_dup_num += 1
271
262
  end
272
-
263
+
273
264
  return id
274
265
  end
275
266
  end