From 251d5eb5fc45c6dc3b6a0b41f01257d842fdb561 Mon Sep 17 00:00:00 2001 From: Hylke van der Schaaf Date: Thu, 2 May 2019 09:38:11 +0200 Subject: [PATCH] Fixed table of * generation for newer Asciidoctor versions --- src/generate_tof.rb | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/generate_tof.rb b/src/generate_tof.rb index 7324a09..4898634 100755 --- a/src/generate_tof.rb +++ b/src/generate_tof.rb @@ -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("","`").gsub("","`") + "\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("","`").gsub("","`") + "\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("","`").gsub("","`") + "\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("","`").gsub("","`") + "\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 + ">> - <>\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 + ">> - <>\n" end print "\n\n"