-
Notifications
You must be signed in to change notification settings - Fork 24
/
convert.rb
53 lines (42 loc) · 1.48 KB
/
convert.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Safe script for converting Asciidoc file to HTML
# Converts all .adoc files in the parent director to .html files
# Usage requires a sitemap.adoc file in the project's root directory
require 'asciidoctor'
require 'asciidoctor/cli/options'
require 'asciidoctor/cli/invoker'
require 'asciidoctor-diagram'
sitemappuml = File.open("sitemap.puml", "w")
sitemappuml.write "@startuml\nhide empty description\n"
Dir["./*.adoc"].each { |x|
if not x.include? "sitemap"
f = File.open(x, "r")
filename = x.gsub(/.\//, "")
filename = filename.gsub(/.adoc/, "")
filename = filename.gsub(/-/, "")
f.each_line do |line|
if line.start_with? "="
if not line.include? "image"
level = line.count("=")
if level <= 2
line = line.gsub(/\s+/, "")
line = line.gsub(/=+/, "")
line = line.gsub(/<</, "")
line = line.gsub(/>>/, "")
line = line.gsub(/\)/, "")
line = line.gsub(/\(/, "")
line = line.gsub(/-/, "")
line = line.gsub(/#/, "")
line = line.gsub(/\,/, "")
sitemappuml.write filename + " -down-> " + line + "\n"
end
end
end
end
f.close
Asciidoctor.convert_file x, to_file: true, safe: :safe
end
}
sitemappuml.write "@enduml"
sitemappuml.close
Asciidoctor.convert_file "./sitemap.adoc", to_file: true, safe: :safe
puts "Sitemap generated successfully."