lib/asciidoctor/standoc/base.rb in metanorma-standoc-1.9.0 vs lib/asciidoctor/standoc/base.rb in metanorma-standoc-1.9.1

- old
+ new

@@ -106,14 +106,19 @@ @anchors = {} @internal_eref_namespaces = [] @draft = node.attributes.has_key?("draft") @novalid = node.attr("novalid") @smartquotes = node.attr("smartquotes") != "false" - @keepasciimath = node.attr("mn-keep-asciimath") && node.attr("mn-keep-asciimath") != "false" + @keepasciimath = node.attr("mn-keep-asciimath") && + node.attr("mn-keep-asciimath") != "false" @fontheader = default_fonts(node) @files_to_delete = [] - @filename = node.attr("docfile") ? File.basename(node.attr("docfile")).gsub(/\.adoc$/, "") : "" + if node.attr("docfile") + @filename = File.basename(node.attr("docfile"))&.gsub(/\.adoc$/, "") + else + @filename = "" + end @localdir = Metanorma::Utils::localdir(node) @output_dir = outputdir node @no_isobib_cache = node.attr("no-isobib-cache") @no_isobib = node.attr("no-isobib") @sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{" @@ -141,14 +146,16 @@ m = node.attr("monospace-font") || '"Courier New",monospace' "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n" end def outputs(node, ret) - File.open(@filename + ".xml", "w:UTF-8") { |f| f.write(ret) } - presentation_xml_converter(node).convert(@filename + ".xml") - html_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}.html") - doc_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}.doc") + File.open("#{@filename}.xml", "w:UTF-8") { |f| f.write(ret) } + presentation_xml_converter(node).convert("#{@filename}.xml") + html_converter(node).convert("#{@filename}.presentation.xml", + nil, false, "#{@filename}.html") + doc_converter(node).convert("#{@filename}.presentation.xml", + nil, false, "#{@filename}.doc") end def document(node) init(node) ret = makexml(node).to_xml(encoding: "US-ASCII", indent: 2) @@ -161,16 +168,25 @@ flavour = self.class.name.sub(/::Converter$/, "").sub(/^.+::/, "") Metanorma.versioned(Metanorma, flavour)[-1]::VERSION end def clean_exit - @log.write(@output_dir + @filename + ".err") unless @novalid + @log.write("#{@output_dir}#{@filename}.err") unless @novalid + @files_to_delete.each { |f| FileUtils.rm f } end + def clean_abort(msg, file = nil) + file and + File.open("#{@filename}.xml.abort", "w:UTF-8") { |f| f.write(file) } + clean_exit + abort(msg) + end + def makexml1(node) - result = ["<?xml version='1.0' encoding='UTF-8'?>", "<#{xml_root_tag} type='semantic' version='#{version}'>"] + result = ["<?xml version='1.0' encoding='UTF-8'?>", + "<#{xml_root_tag} type='semantic' version='#{version}'>"] result << noko { |ixml| front node, ixml } result << noko { |ixml| middle node, ixml } result << "</#{xml_root_tag}>" textcleanup(result) end @@ -201,39 +217,16 @@ xml.sections do |s| s << node.content if node.blocks? end end - def default_script(lang) - case lang - when "ar", "fa" - "Arab" - when "ur" - "Aran" - when "ru", "bg" - "Cyrl" - when "hi" - "Deva" - when "el" - "Grek" - when "zh" - "Hans" - when "ko" - "Kore" - when "he" - "Hebr" - when "ja" - "Jpan" - else - "Latn" - end - end - private def outputdir(node) - if node.attr("output_dir").nil_or_empty? then Metanorma::Utils::localdir(node) - else File.join(node.attr("output_dir"), "") + if node.attr("output_dir").nil_or_empty? + Metanorma::Utils::localdir(node) + else + File.join(node.attr("output_dir"), "") end end end end end