yard_ghurt 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,267 +1,225 @@
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 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 Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: LGPL-3.0-or-later
21
9
  #++
22
10
 
23
-
24
11
  require 'rake'
25
- require 'set'
26
-
27
12
  require 'rake/tasklib'
28
-
13
+ require 'set'
29
14
  require 'yard_ghurt/anchor_links'
30
15
  require 'yard_ghurt/util'
31
16
 
32
17
  module YardGhurt
33
- ###
34
18
  # Fix (find & replace) text in the GitHub Flavored Markdown (GFM) files in the YARDoc directory,
35
19
  # for differences between the two formats.
36
- #
20
+ #
37
21
  # You can set {dry_run} on the command line:
38
22
  # rake yard_gfm_fix dryrun=true
39
- #
23
+ #
40
24
  # @example What I Use
41
- # YardGhurt::GFMFixTask.new() do |task|
25
+ # YardGhurt::GFMFixTask.new do |task|
42
26
  # task.arg_names = [:dev]
43
27
  # task.dry_run = false
44
28
  # task.fix_code_langs = true
45
29
  # task.md_files = ['index.html']
46
- #
47
- # task.before = Proc.new() do |task,args|
48
- # # Delete this file as it's never used (index.html is an exact copy)
49
- # YardGhurt.rm_exist(File.join(task.doc_dir,'file.README.html'))
50
- #
51
- # # Root dir of my GitHub Page for CSS/JS
52
- # GHP_ROOT_DIR = YardGhurt.to_bool(args.dev) ? '../../esotericpig.github.io' : '../../..'
53
- #
54
- # task.css_styles << %Q(<link rel="stylesheet" type="text/css" href="#{GHP_ROOT_DIR}/css/prism.css" />)
55
- # task.js_scripts << %Q(<script src="#{GHP_ROOT_DIR}/js/prism.js"></script>)
30
+ #
31
+ # task.before = proc do |task2,args|
32
+ # # Delete this file as it's never used (`index.html` is an exact copy).
33
+ # YardGhurt.rm_exist(File.join(task2.doc_dir,'file.README.html'))
34
+ #
35
+ # # Root dir of my GitHub Page for CSS/JS.
36
+ # ghp_root_dir = YardGhurt.to_bool(args.dev) ? '../../esotericpig.github.io' : '../../..'
37
+ #
38
+ # task2.css_styles << %(
39
+ # <link rel="stylesheet" type="text/css" href="#{ghp_root_dir}/css/prism.css" />
40
+ # )
41
+ # task2.js_scripts << %(<script src="#{ghp_root_dir}/js/prism.js"></script>)
56
42
  # end
57
43
  # end
58
- #
59
- # @example Using All Options
60
- # YardGhurt::GFMFixTask.new(:yard_fix) do |task|
61
- # task.anchor_db = {'tests' => 'Testing'} # #tests => #Testing
62
- # task.arg_names << :name # Custom args
63
- # task.css_styles << '<link rel="stylesheet" href="css/my_css.css" />' # Inserted at </head>
64
- # task.css_styles << '<style>body{ background-color: linen; }</style>'
65
- # task.custom_gsub = Proc.new() {|line| !line.gsub!('YardGhurt','YARD GHURT!').nil?()}
66
- # task.custom_gsubs << [/newline/i,'Do you smell what The Rock is cooking?']
67
- # task.deps << :yard # Custom dependencies
68
- # task.description = 'Fix it'
69
- # task.doc_dir = 'doc'
70
- # task.dry_run = false
71
- # task.exclude_code_langs = Set['ruby']
72
- # task.fix_anchor_links = true
73
- # task.fix_code_langs = true
74
- # task.fix_file_links = true
75
- # task.js_scripts << '<script src="js/my_js.js"></script>' # Inserted at </body>
76
- # task.js_scripts << '<script>document.write("Hello World!");</script>'
77
- # task.md_files = ['index.html']
78
- # task.verbose = false
79
- #
80
- # task.before = Proc.new() {|task,args| puts "Hi, #{args.name}!"}
81
- # task.during = Proc.new() {|task,args,file| puts "#{args.name} can haz #{file}?"}
82
- # task.after = Proc.new() {|task,args| puts "Goodbye, #{args.name}!"}
83
- # end
84
- #
85
- # @author Jonathan Bradley Whited (@esotericpig)
86
- # @since 1.1.0
87
- ###
44
+ #
45
+ # @since 1.1.0
88
46
  class GFMFixTask < Rake::TaskLib
89
47
  # This is important so that a subsequent call to this task will not write the CSS again.
90
- #
48
+ #
91
49
  # @return [String] the comment tag of where to place {css_styles}
92
- #
50
+ #
93
51
  # @see add_css_styles!
94
52
  CSS_COMMENT = "<!-- #{self} CSS - Do NOT remove this comment! -->"
95
-
53
+
96
54
  # This is important so that a subsequent call to this task will not write the JS again.
97
- #
55
+ #
98
56
  # @return [String] the comment tag of where to place {js_scripts}
99
- #
57
+ #
100
58
  # @see add_js_scripts!
101
59
  JS_COMMENT = "<!-- #{self} JS - Do NOT remove this comment! -->"
102
-
60
+
103
61
  # @example
104
62
  # task.arg_names = [:dev]
105
- #
63
+ #
106
64
  # # @param task [self]
107
65
  # # @param args [Rake::TaskArguments] the args specified by {arg_names}
108
- # task.after = Proc.new do |task,args|
66
+ # task.after = proc do |task,args|
109
67
  # puts args.dev
110
68
  # end
111
- #
69
+ #
112
70
  # @return [Proc,nil] the Proc ( +respond_to?(:call)+ ) to call at the end of this task or +nil+;
113
71
  # default: +nil+
114
72
  attr_accessor :after
115
-
73
+
116
74
  # The anchor links to override in the database.
117
- #
75
+ #
118
76
  # The keys are GFM anchor IDs and the values are their equivalent YARDoc anchor IDs.
119
- #
77
+ #
120
78
  # @return [Hash] the custom database (key-value pairs) of GFM anchor links to YARDoc anchor links;
121
79
  # default: +{}+
122
- #
80
+ #
123
81
  # @see build_anchor_links_db
124
82
  # @see AnchorLinks#merge_anchor_ids!
125
83
  attr_accessor :anchor_db
126
-
84
+
127
85
  # @return [Array<Symbol>,Symbol] the custom arg(s) for this task; default: +[]+
128
86
  attr_accessor :arg_names
129
-
87
+
130
88
  # @example
131
89
  # task.arg_names = [:dev]
132
- #
90
+ #
133
91
  # # @param task [self]
134
92
  # # @param args [Rake::TaskArguments] the args specified by {arg_names}
135
- # task.before = Proc.new do |task,args|
93
+ # task.before = proc do |task,args|
136
94
  # puts args.dev
137
95
  # end
138
- #
96
+ #
139
97
  # @return [Proc,nil] the Proc ( +respond_to?(:call)+ ) to call at the beginning of this task or +nil+;
140
98
  # default: +nil+
141
99
  attr_accessor :before
142
-
100
+
143
101
  # @example
144
102
  # task.css_styles << '<link rel="stylesheet" type="text/css" href="css/prism.css" />'
145
- #
103
+ #
146
104
  # @return [Array<String>] the CSS styles to add to each file; default: +[]+
147
105
  attr_accessor :css_styles
148
-
106
+
149
107
  # @example
150
108
  # # +gsub!()+ (and other mutable methods) must be used
151
109
  # # as the return value must be +true+ or +false+.
152
- # #
110
+ # #
153
111
  # # @param line [String] the current line being processed from the current file
154
- # #
112
+ # #
155
113
  # # @return [true,false] whether there was a change
156
- # task.custom_gsub = Proc.new do |line|
114
+ # task.custom_gsub = proc do |line|
157
115
  # has_change = false
158
- #
159
- # has_change = !line.gsub!('dev','prod').nil?() || has_change
116
+ #
117
+ # has_change = !line.gsub!('dev','prod').nil? || has_change
160
118
  # # More changes...
161
- #
119
+ #
162
120
  # return has_change
163
121
  # end
164
- #
122
+ #
165
123
  # @return [Proc,nil] the custom Proc ( +respond_to?(:call)+ ) to call to gsub! each line for each file
166
124
  attr_accessor :custom_gsub
167
-
125
+
168
126
  # @example
169
127
  # task.custom_gsubs = [
170
128
  # ['dev','prod'],
171
129
  # [/href="#[^"]*"/,'href="#contents"']
172
130
  # ]
173
- #
131
+ #
174
132
  # # Internal code:
175
133
  # # ---
176
134
  # # @custom_gsubs.each do |custom_gsub|
177
135
  # # line.gsub!(custom_gsub[0],custom_gsub[1])
178
136
  # # end
179
- #
137
+ #
180
138
  # @return [Array<[Regexp,String]>] the custom args to use in gsub on each line for each file
181
139
  attr_accessor :custom_gsubs
182
-
140
+
183
141
  # @example
184
142
  # task.deps = :yard
185
143
  # # or...
186
144
  # task.deps = [:clobber,:yard]
187
- #
145
+ #
188
146
  # @return [Array<Symbol>,Symbol] the custom dependencies for this task; default: +[]+
189
147
  attr_accessor :deps
190
-
148
+
191
149
  # @return [String] the description of this task (customizable)
192
150
  attr_accessor :description
193
-
151
+
194
152
  # @return [String] the directory of generated YARDoc files; default: +doc+
195
153
  attr_accessor :doc_dir
196
-
154
+
197
155
  # @return [true,false] whether to run a dry run (no writing to the files); default: +false+
198
156
  attr_accessor :dry_run
199
-
157
+
200
158
  # @example
201
159
  # task.arg_names = [:dev]
202
- #
160
+ #
203
161
  # # @param task [self]
204
162
  # # @param args [Rake::TaskArguments] the args specified by {arg_names}
205
163
  # # @param file [String] the current file being processed
206
- # task.during = Proc.new do |task,args,file|
164
+ # task.during = proc do |task,args,file|
207
165
  # puts args.dev
208
166
  # end
209
- #
167
+ #
210
168
  # @return [Proc,nil] the Proc to call ( +respond_to?(:call)+ ) at the beginning of processing
211
169
  # each file or +nil+; default: +nil+
212
170
  attr_accessor :during
213
-
171
+
214
172
  # @return [Set<String>] the case-sensitive code languages to not fix; default: +Set[ 'ruby' ]+
215
- #
173
+ #
216
174
  # @see fix_code_langs
217
175
  attr_accessor :exclude_code_langs
218
-
176
+
219
177
  # @return [true,false] whether to fix anchor links; default: +true+
220
178
  attr_accessor :fix_anchor_links
221
-
179
+
222
180
  # If +true+, +language-+ will be added to code classes, except for {exclude_code_langs}.
223
- #
181
+ #
224
182
  # For example, +code class="ruby"+ will be changed to +code class="language-ruby"+.
225
- #
183
+ #
226
184
  # @return [true,false] whether to fix code languages; default: +false+
227
185
  attr_accessor :fix_code_langs
228
-
186
+
229
187
  # If +true+, local file links (if the local file exists), will be changed to +file.{filename}.html+.
230
- #
188
+ #
231
189
  # This is useful for +README.md+, +LICENSE.txt+, etc.
232
- #
190
+ #
233
191
  # @return [true,false] whether to fix local file links; default: +true+
234
192
  attr_accessor :fix_file_links
235
-
193
+
236
194
  # This is an internal flag meant to be changed internally.
237
- #
195
+ #
238
196
  # @return [true,false] whether {CSS_COMMENT} has been seen/added; default: +false+
239
- #
197
+ #
240
198
  # @see add_css_styles!
241
199
  attr_accessor :has_css_comment
242
-
200
+
243
201
  # This is an internal flag meant to be changed internally.
244
- #
202
+ #
245
203
  # @return [true,false] whether {JS_COMMENT} has been seen/added; default: +false+
246
- #
204
+ #
247
205
  # @see add_js_scripts!
248
206
  attr_accessor :has_js_comment
249
-
207
+
250
208
  # @example
251
209
  # task.js_scripts << '<script src="js/prism.js"></script>'
252
- #
210
+ #
253
211
  # @return [Array<String>] the JS scripts to add to each file; default: +[]+
254
212
  attr_accessor :js_scripts
255
-
213
+
256
214
  # @return [Array<String>] the (GFM) Markdown files to fix; default: +['file.README.html','index.html']+
257
215
  attr_accessor :md_files
258
-
216
+
259
217
  # @return [String] the name of this task (customizable); default: +yard_gfm_fix+
260
218
  attr_accessor :name
261
-
219
+
262
220
  # @return [true,false] whether to output each change to stdout; default: +true+
263
221
  attr_accessor :verbose
264
-
222
+
265
223
  alias_method :dry_run?,:dry_run
266
224
  alias_method :fix_anchor_links?,:fix_anchor_links
267
225
  alias_method :fix_code_langs?,:fix_code_langs
@@ -269,9 +227,11 @@ module YardGhurt
269
227
  alias_method :has_css_comment?,:has_css_comment
270
228
  alias_method :has_js_comment?,:has_js_comment
271
229
  alias_method :verbose?,:verbose
272
-
230
+
273
231
  # @param name [Symbol] the name of this task to use on the command line with +rake+
274
- def initialize(name=:yard_gfm_fix)
232
+ def initialize(name = :yard_gfm_fix)
233
+ super()
234
+
275
235
  @after = nil
276
236
  @anchor_db = {}
277
237
  @arg_names = []
@@ -292,125 +252,137 @@ module YardGhurt
292
252
  @md_files = ['file.README.html','index.html']
293
253
  @name = name
294
254
  @verbose = true
295
-
296
- yield self if block_given?()
297
- define()
255
+
256
+ yield(self) if block_given?
257
+ define
298
258
  end
299
-
259
+
300
260
  # Reset certain instance vars per file.
301
- def reset_per_file()
302
- @anchor_links = AnchorLinks.new()
261
+ def reset_per_file
262
+ @anchor_links = AnchorLinks.new
303
263
  @has_css_comment = false
304
264
  @has_js_comment = false
305
265
  @has_verbose_anchor_links = false
306
266
  end
307
-
267
+
308
268
  # Define the Rake task and description using the instance variables.
309
- def define()
269
+ def define
310
270
  desc @description
311
- task @name,Array(@arg_names) => Array(@deps) do |task,args|
271
+ task @name,Array(@arg_names) => Array(@deps) do |_task,args|
312
272
  env_dryrun = ENV['dryrun']
313
-
314
- if !env_dryrun.nil?() && !(env_dryrun = env_dryrun.to_s().strip()).empty?()
273
+
274
+ if !env_dryrun.nil? && !(env_dryrun = env_dryrun.to_s.strip).empty?
315
275
  @dry_run = Util.to_bool(env_dryrun)
316
276
  end
317
-
277
+
318
278
  @before.call(self,args) if @before.respond_to?(:call)
319
-
279
+
320
280
  @md_files.each do |md_file|
321
- reset_per_file()
281
+ reset_per_file
322
282
  build_anchor_links_db(md_file)
323
-
283
+
324
284
  @during.call(self,args,md_file) if @during.respond_to?(:call)
325
-
285
+
326
286
  fix_md_file(md_file)
327
287
  end
328
-
288
+
329
289
  @after.call(self,args) if @after.respond_to?(:call)
330
290
  end
331
-
291
+
332
292
  return self
333
293
  end
334
-
294
+
335
295
  # Convert each HTML header tag in +md_file+ to a GFM & YARDoc anchor link
336
296
  # and build a database using them.
337
- #
297
+ #
338
298
  # @param md_file [String] the file (no dir) to build the anchor links database with,
339
299
  # will be joined to {doc_dir}
340
- #
300
+ #
341
301
  # @see AnchorLinks#<<
342
302
  # @see AnchorLinks#merge_anchor_ids!
343
303
  def build_anchor_links_db(md_file)
344
304
  filename = File.join(@doc_dir,md_file)
345
-
305
+
346
306
  return unless File.exist?(filename)
347
-
307
+
348
308
  File.open(filename,'r') do |file|
349
309
  file.each_line do |line|
350
- next if line !~ /<h\d+>/i
351
-
310
+ # +<h3 id="..."+ or +<h3...+
311
+ # - +yard_id+ was added for YARD v0.9.25+.
312
+ match = line.match(/<\s*h\d+.*?id\s*=\s*["'](?<yard_id>[^"']+)["']|<\s*h\d+[\s>]/ui)
313
+
314
+ next unless match
315
+
316
+ yard_id = nil
317
+ caps = match.named_captures
318
+
319
+ if caps.key?('yard_id')
320
+ yard_id = caps['yard_id'].to_s.strip
321
+ yard_id = nil if yard_id.empty?
322
+ end
323
+
352
324
  line.gsub!(/<[^>]+>/,'') # Remove tags: <...>
353
- line.strip!()
354
-
355
- next if line.empty?()
356
-
357
- @anchor_links << line
325
+ line.strip!
326
+
327
+ next if line.empty?
328
+
329
+ @anchor_links.add_anchor(line,yard_id: yard_id)
358
330
  end
359
331
  end
360
-
332
+
361
333
  @anchor_links.merge_anchor_ids!(@anchor_db)
362
334
  end
363
-
335
+
364
336
  # Fix (find & replace) text in +md_file+. Calls all +add_*+ & +gsub_*+ methods.
365
- #
337
+ #
366
338
  # @param md_file [String] the file (no dir) to fix, will be joined to {doc_dir}
367
339
  def fix_md_file(md_file)
368
340
  filename = File.join(@doc_dir,md_file)
369
-
341
+
370
342
  puts "[#{filename}]:"
371
-
343
+
372
344
  if !File.exist?(filename)
373
345
  puts '! File does not exist'
374
-
346
+
375
347
  return
376
348
  end
377
-
349
+
378
350
  changes = 0
379
351
  lines = []
380
-
352
+
381
353
  File.open(filename,'r') do |file|
382
354
  file.each_line do |line|
383
- if line.strip().empty?()
355
+ if line.strip.empty?
384
356
  lines << line
385
-
357
+
386
358
  next
387
359
  end
388
-
360
+
389
361
  has_change = false
390
-
391
- # Standard
362
+
363
+ # Standard.
392
364
  has_change = add_css_styles!(line) || has_change
393
365
  has_change = add_js_scripts!(line) || has_change
394
366
  has_change = gsub_anchor_links!(line) || has_change
395
367
  has_change = gsub_code_langs!(line) || has_change
396
368
  has_change = gsub_local_file_links!(line) || has_change
397
-
398
- # Custom
369
+
370
+ # Custom.
399
371
  has_change = gsub_customs!(line) || has_change
400
372
  has_change = gsub_custom!(line) || has_change
401
-
373
+
402
374
  if has_change
403
375
  puts "+ #{line}" if @verbose
404
-
376
+
405
377
  changes += 1
406
378
  end
407
-
379
+
408
380
  lines << line
409
381
  end
410
382
  end
411
-
383
+
412
384
  print '= '
413
-
385
+
414
386
  if changes > 0
415
387
  if @dry_run
416
388
  puts 'Nothing written (dry run)'
@@ -418,195 +390,195 @@ module YardGhurt
418
390
  File.open(filename,'w') do |file|
419
391
  file.puts lines
420
392
  end
421
-
393
+
422
394
  puts "#{changes} changes written"
423
395
  end
424
396
  else
425
397
  puts 'Nothing written (up-to-date)'
426
398
  end
427
399
  end
428
-
400
+
429
401
  # Add {CSS_COMMENT} & {css_styles} to +line+ if it is +</head>+,
430
402
  # unless {CSS_COMMENT} has already been found or {has_css_comment}.
431
- #
403
+ #
432
404
  # @param line [String] the line from the file to check if +</head>+
433
405
  def add_css_styles!(line)
434
- return false if @has_css_comment || @css_styles.empty?()
435
-
436
- if line.strip() == CSS_COMMENT
406
+ return false if @has_css_comment || @css_styles.empty?
407
+
408
+ if line.strip == CSS_COMMENT
437
409
  @has_css_comment = true
438
-
410
+
439
411
  return false
440
412
  end
441
-
442
- return false unless line =~ /^\s*<\/head>\s*$/i
443
-
444
- line.slice!(0,line.length())
413
+
414
+ return false unless line =~ %r{^\s*</head>\s*$}i
415
+
416
+ line.slice!(0,line.length)
445
417
  line << " #{CSS_COMMENT}"
446
-
418
+
447
419
  @css_styles.each do |css_style|
448
420
  line << "\n #{css_style}"
449
421
  end
450
-
422
+
451
423
  line << "\n\n </head>"
452
-
424
+
453
425
  @has_css_comment = true
454
-
426
+
455
427
  return true
456
428
  end
457
-
429
+
458
430
  # Add {JS_COMMENT} & {js_scripts} to +line+ if it is +</body>+,
459
431
  # unless {JS_COMMENT} has already been found or {has_js_comment}.
460
- #
432
+ #
461
433
  # @param line [String] the line from the file to check if +</body>+
462
434
  def add_js_scripts!(line)
463
- return false if @has_js_comment || @js_scripts.empty?()
464
-
465
- if line.strip() == JS_COMMENT
435
+ return false if @has_js_comment || @js_scripts.empty?
436
+
437
+ if line.strip == JS_COMMENT
466
438
  @has_js_comment = true
467
-
439
+
468
440
  return false
469
441
  end
470
-
471
- return false unless line =~ /^\s*<\/body>\s*$/i
472
-
473
- line.slice!(0,line.length())
442
+
443
+ return false unless line =~ %r{^\s*</body>\s*$}i
444
+
445
+ line.slice!(0,line.length)
474
446
  line << "\n #{JS_COMMENT}"
475
-
447
+
476
448
  @js_scripts.each do |js_script|
477
449
  line << "\n #{js_script}"
478
450
  end
479
-
451
+
480
452
  line << "\n\n </body>"
481
-
453
+
482
454
  @has_js_comment = true
483
-
455
+
484
456
  return true
485
457
  end
486
-
458
+
487
459
  # Replace GFM anchor links with their equivalent YARDoc anchor links,
488
460
  # using {build_anchor_links_db} & {anchor_db}, if {fix_anchor_links}.
489
- #
461
+ #
490
462
  # @param line [String] the line from the file to fix
491
463
  def gsub_anchor_links!(line)
492
464
  return false unless @fix_anchor_links
493
-
465
+
494
466
  has_change = false
495
- tag = 'href="#'
496
-
497
- line.gsub!(Regexp.new(Regexp.quote(tag) + '[^"]*"')) do |href|
498
- link = href[tag.length..-2].strip()
499
-
500
- if link.empty?() || @anchor_links.yard_anchor_id?(link)
467
+
468
+ # +href="#..."+ or +href='#...'+
469
+ line.gsub!(/href\s*=\s*["']\s*#\s*(?<link>[^"']+)["']/ui) do |href|
470
+ link = Regexp.last_match[:link].to_s.strip # Same as +$~[:link]+.
471
+
472
+ if link.empty? || @anchor_links.yard_anchor_id?(link)
501
473
  href
502
474
  else
503
475
  yard_link = @anchor_links[link]
504
-
505
- if yard_link.nil?()
476
+
477
+ if yard_link.nil?
506
478
  # Either the GFM link is wrong [check with @anchor_links.to_github_anchor_id()]
507
- # or the internal code is broken [check with @anchor_links.to_s()]
479
+ # or the internal code is broken [check with @anchor_links.to_s()].
508
480
  puts "! YARDoc anchor link for GFM anchor link [#{link}] does not exist"
509
-
481
+
510
482
  if !@has_verbose_anchor_links
511
483
  if @verbose
512
484
  puts ' GFM anchor link in the Markdown file is wrong?'
513
485
  puts ' Please check the generated links:'
514
- puts %Q( #{@anchor_links.to_s().strip().gsub("\n","\n ")})
486
+ puts %( #{@anchor_links.to_s.strip.gsub("\n","\n ")})
515
487
  else
516
488
  puts " Turn on #{self.class}.verbose for more info"
517
489
  end
518
-
490
+
519
491
  @has_verbose_anchor_links = true
520
492
  end
521
-
493
+
522
494
  href
523
495
  else
524
496
  has_change = true
525
-
526
- %Q(#{tag}#{yard_link}")
497
+
498
+ %(href="##{yard_link}")
527
499
  end
528
500
  end
529
501
  end
530
-
502
+
531
503
  return has_change
532
504
  end
533
-
505
+
534
506
  # Add +language-+ to code class languages and down case them,
535
507
  # if {fix_code_langs} and the language is not in {exclude_code_langs}.
536
- #
508
+ #
537
509
  # @param line [String] the line from the file to fix
538
510
  def gsub_code_langs!(line)
539
511
  return false unless @fix_code_langs
540
-
512
+
541
513
  has_change = false
542
514
  tag = 'code class="'
543
-
544
- line.gsub!(Regexp.new(Regexp.quote(tag) + '[^"]*"')) do |code_class|
545
- lang = code_class[tag.length..-2].strip()
546
-
547
- if lang.empty?() || lang =~ /^language\-/ || @exclude_code_langs.include?(lang)
515
+
516
+ line.gsub!(Regexp.new(%(#{Regexp.quote(tag)}[^"]*"))) do |code_class|
517
+ lang = code_class[tag.length..-2].strip
518
+
519
+ if lang.empty? || lang =~ /^language-/ || @exclude_code_langs.include?(lang)
548
520
  code_class
549
521
  else
550
522
  has_change = true
551
-
552
- %Q(#{tag}language-#{lang.downcase()}")
523
+
524
+ %(#{tag}language-#{lang.downcase}")
553
525
  end
554
526
  end
555
-
527
+
556
528
  return has_change
557
529
  end
558
-
559
- # Call the custom Proc {custom_gsub} (if it responds to +:call+) on +line+,
560
- #
530
+
531
+ # Call the custom Proc {custom_gsub} (if it responds to +:call+) on +line+.
532
+ #
561
533
  # @param line [String] the line from the file to fix
562
534
  def gsub_custom!(line)
563
535
  return false unless @custom_gsub.respond_to?(:call)
564
536
  return @custom_gsub.call(line)
565
537
  end
566
-
538
+
567
539
  # Call +gsub!()+ on +line+ with each {custom_gsubs},
568
540
  # which is an Array of pairs of arguments:
569
541
  # task.custom_gsubs = [
570
542
  # ['dev','prod'],
571
543
  # [/href="#[^"]*"/,'href="#contents"']
572
544
  # ]
573
- #
545
+ #
574
546
  # @param line [String] the line from the file to fix
575
547
  def gsub_customs!(line)
576
- return false if @custom_gsubs.empty?()
577
-
548
+ return false if @custom_gsubs.empty?
549
+
578
550
  has_change = false
579
-
551
+
580
552
  @custom_gsubs.each do |custom_gsub|
581
- has_change = !line.gsub!(custom_gsub[0],custom_gsub[1]).nil?() || has_change
553
+ has_change = !line.gsub!(custom_gsub[0],custom_gsub[1]).nil? || has_change
582
554
  end
583
-
555
+
584
556
  return has_change
585
557
  end
586
-
558
+
587
559
  # Replace local file links (that exist) to be +file.{filename}.html+,
588
560
  # if {fix_file_links}.
589
- #
561
+ #
590
562
  # @param line [String] the line from the file to fix
591
563
  def gsub_local_file_links!(line)
592
564
  return false unless @fix_file_links
593
-
565
+
594
566
  has_change = false
595
567
  tag = 'href="'
596
-
597
- line.gsub!(Regexp.new(Regexp.quote(tag) + '[^#][^"]*"')) do |href|
598
- link = href[tag.length..-2].strip()
599
-
600
- if link.empty?() || !File.exist?(link)
568
+
569
+ line.gsub!(Regexp.new(%(#{Regexp.quote(tag)}[^#][^"]*"))) do |href|
570
+ link = href[tag.length..-2].strip
571
+
572
+ if link.empty? || !File.exist?(link)
601
573
  href
602
574
  else
603
575
  link = File.basename(link,'.*')
604
576
  has_change = true
605
-
606
- %Q(#{tag}file.#{link}.html")
577
+
578
+ %(#{tag}file.#{link}.html")
607
579
  end
608
580
  end
609
-
581
+
610
582
  return has_change
611
583
  end
612
584
  end