Skip to content

Commit 0c5dde9

Browse files
committed
Refactor to satisfy rubocop
1 parent 9f5f16e commit 0c5dde9

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

resources/asciidoctor/lib/chunker/url_to_v3.rb

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,48 @@
1-
module Chunker
1+
# frozen_string_literal: true
22

3+
module Chunker
4+
# Add a warning to the page with a link to docs v3
35
class UrlToV3
4-
56
attr_reader :url
67

78
def initialize(doc)
89
current_url = doc.attr('current-url')
910
outdir = doc.attr('outdir')
1011
current_url ||= 'index.html'
11-
file_path = File.expand_path('v3-mapping.json', __dir__)
12-
mapping = JSON.parse(File.read(file_path)) if File.exist?(file_path)
13-
segments = outdir.sub('/tmp/docsbuild/target_repo/raw', '').split('/') # This only works in CI.
12+
m = mapping
13+
# This only works in CI.
14+
segments = outdir.sub('/tmp/docsbuild/target_repo/raw', '').split('/')
1415
version = segments[-1] || 'unknown'
16+
actual_url = get_actual_url(outdir, current_url)
17+
new_url = if m.key?(actual_url)
18+
m[actual_url]
19+
else
20+
'/docs'
21+
end
22+
render_warning(doc, version, new_url)
23+
end
24+
25+
def mapping
26+
file_path = File.expand_path('v3-mapping.json', __dir__)
27+
JSON.parse(File.read(file_path)) if File.exist?(file_path)
28+
end
1529

16-
path_dir = if segments.empty?
30+
def get_path_dir(outdir)
31+
segments = outdir.sub('/tmp/docsbuild/target_repo/raw', '').split('/')
32+
if segments.empty?
1733
''
1834
elsif segments.length > 1
1935
segments[0...-1].join('/')
2036
else
2137
segments[0]
2238
end
39+
end
2340

24-
actual_url = path_dir + '/*/' + current_url
25-
new_url = if mapping.key?(actual_url)
26-
mapping[actual_url]
27-
else
28-
'/docs'
29-
end
41+
def get_actual_url(outdir, current_url)
42+
get_path_dir(outdir) + '/*/' + current_url
43+
end
3044

45+
def render_warning(doc, version, new_url)
3146
if version == '8.18'
3247
@url = Asciidoctor::Block.new(doc, :pass, source: <<~HTML)
3348
<div id="url-to-v3" style="version-warning">

0 commit comments

Comments
 (0)