Skip to content

Commit

Permalink
Fixed table of * generation for newer Asciidoctor versions
Browse files Browse the repository at this point in the history
  • Loading branch information
hylkevds committed May 2, 2019
1 parent 348c754 commit 251d5eb
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions src/generate_tof.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,48 @@
#!/usr/bin/ruby
require 'asciidoctor'
require 'pp'

doc = Asciidoctor.load_file(ARGV[0], to_file: false, safe: :unsafe, catalog_assets: true)

def dumpObj(obj)
obj.instance_variables.map do |var|
type = obj.instance_variable_get(var).class
case type.name
when "String", "Integer"
val = obj.instance_variable_get(var)
else
val = '[undetermined]'
end
print "" , var , " : " , type , " : " , val , "\n"
end
end

print "// DO NOT EDIT THIS AUTOGENERATED FILE.\n\n"
print "[preface]\n== Table of Figures\n\n"

figs = doc.references[:ids].keys.find_all { |x| x.start_with? "fig-" }
figs.each do |fig|
print "* <<" + fig + ">> - " + doc.references[:ids][fig].gsub("<code>","`").gsub("</code>","`") + "\n"
refs = doc.references[:refs].keys.find_all { |x| x.start_with? "fig-" }
refs = refs.sort{|a, b| doc.references[:refs][a].numeral <=> doc.references[:refs][b].numeral}
refs.each do |figName|
fig = doc.references[:refs][figName]
print "* <<" + figName + ">> - " + fig.title.gsub("<code>","`").gsub("</code>","`") + "\n"
end
print "\n\n"

print "\n\n"
print "[preface]\n== Table of Tables\n\n"

figs = doc.references[:ids].keys.find_all { |x| x.start_with? "tab-" }
figs.each do |fig|
print "* <<" + fig + ">> - " + doc.references[:ids][fig].gsub("<code>","`").gsub("</code>","`") + "\n"
refs = doc.references[:refs].keys.find_all { |x| x.start_with? "tab-" }
refs = refs.sort{|a, b| doc.references[:refs][a].numeral <=> doc.references[:refs][b].numeral}
refs.each do |refName|
ref = doc.references[:refs][refName];
print "* <<" + refName + ">> - " + ref.title.gsub("<code>","`").gsub("</code>","`") + "\n"
end
print "\n\n"

print "[preface]\n== Table of Requirements\n\n"

figs = doc.references[:ids].keys.find_all { |x| x.start_with? "req-" }
figs.each do |fig|
print "* Requirement <<" + fig + ">> - <<requirement-" + fig[4 .. -1] + ">>\n"
refs = doc.references[:refs].keys.find_all { |x| x.start_with? "req-" }
refs = refs.sort{|a, b| Integer(doc.references[:refs][a].reftext) <=> Integer(doc.references[:refs][b].reftext)}
refs.each do |refName|
print "* Requirement <<" + refName + ">> - <<requirement-" + refName[4 .. -1] + ">>\n"
end
print "\n\n"

0 comments on commit 251d5eb

Please sign in to comment.