Module: Asciidoctor::Standoc::Base
- Included in:
- Converter
- Defined in:
- lib/asciidoctor/standoc/base.rb
Constant Summary collapse
- XML_ROOT_TAG =
"standard-document".freeze
- XML_NAMESPACE =
"https://www.metanorma.org/ns/standoc".freeze
Instance Method Summary collapse
- #clean_abort(msg, file = nil) ⇒ Object
- #clean_exit ⇒ Object
- #content(node) ⇒ Object
- #default_fonts(node) ⇒ Object
- #doc_converter(node) ⇒ Object
- #doc_extract_attributes(node) ⇒ Object
- #doctype(node) ⇒ Object
- #document(node) ⇒ Object
- #draft? ⇒ Boolean
- #front(node, xml) ⇒ Object
- #html_converter(node) ⇒ Object
- #html_extract_attributes(node) ⇒ Object
- #init(node) ⇒ Object
- #makexml(node) ⇒ Object
- #makexml1(node) ⇒ Object
- #middle(node, xml) ⇒ Object
- #outputs(node, ret) ⇒ Object
- #presentation_xml_converter(node) ⇒ Object
- #skip(node, name = nil) ⇒ Object
- #version ⇒ Object
- #xml_namespace ⇒ Object
- #xml_root_tag ⇒ Object
Instance Method Details
#clean_abort(msg, file = nil) ⇒ Object
178 179 180 181 182 183 |
# File 'lib/asciidoctor/standoc/base.rb', line 178 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 |
#clean_exit ⇒ Object
172 173 174 175 176 |
# File 'lib/asciidoctor/standoc/base.rb', line 172 def clean_exit @log.write("#{@output_dir}#{@filename}.err") unless @novalid @files_to_delete.each { |f| FileUtils.rm f } end |
#content(node) ⇒ Object
27 28 29 |
# File 'lib/asciidoctor/standoc/base.rb', line 27 def content(node) node.content end |
#default_fonts(node) ⇒ Object
141 142 143 144 145 146 147 148 |
# File 'lib/asciidoctor/standoc/base.rb', line 141 def default_fonts(node) b = node.attr("body-font") || (node.attr("script") == "Hans" ? '"Source Han Sans",serif' : '"Cambria",serif') h = node.attr("header-font") || (node.attr("script") == "Hans" ? '"Source Han Sans",sans-serif' : '"Cambria",serif') m = node.attr("monospace-font") || '"Courier New",monospace' "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n" end |
#doc_converter(node) ⇒ Object
94 95 96 |
# File 'lib/asciidoctor/standoc/base.rb', line 94 def doc_converter(node) IsoDoc::WordConvert.new(doc_extract_attributes(node)) end |
#doc_extract_attributes(node) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/asciidoctor/standoc/base.rb', line 64 def doc_extract_attributes(node) attrs = { script: node.attr("script"), bodyfont: node.attr("body-font"), headerfont: node.attr("header-font"), monospacefont: node.attr("monospace-font"), i18nyaml: node.attr("i18nyaml"), scope: node.attr("scope"), wordstylesheet: node.attr("wordstylesheet"), wordstylesheet_override: node.attr("wordstylesheet-override"), standardstylesheet: node.attr("standardstylesheet"), header: node.attr("header"), wordcoverpage: node.attr("wordcoverpage"), wordintropage: node.attr("wordintropage"), ulstyle: node.attr("ulstyle"), olstyle: node.attr("olstyle"), htmltoclevels: node.attr("htmltoclevels") || node.attr("toclevels"), doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"), break_up_urls_in_tables: node.attr("break-up-urls-in-tables"), } if font_manifest_file = node.attr("mn2pdf-font-manifest-file") attrs[IsoDoc::XslfoPdfConvert::MN2PDF_OPTIONS] = { IsoDoc::XslfoPdfConvert::MN2PDF_FONT_MANIFEST => font_manifest_file, } end attrs end |
#doctype(node) ⇒ Object
206 207 208 |
# File 'lib/asciidoctor/standoc/base.rb', line 206 def doctype(node) node.attr("doctype")&.gsub(/\s+/, "-")&.downcase end |
#document(node) ⇒ Object
159 160 161 162 163 164 165 |
# File 'lib/asciidoctor/standoc/base.rb', line 159 def document(node) init(node) ret = makexml(node).to_xml(encoding: "US-ASCII", indent: 2) outputs(node, ret) unless node.attr("nodoc") || !node.attr("docfile") clean_exit ret end |
#draft? ⇒ Boolean
202 203 204 |
# File 'lib/asciidoctor/standoc/base.rb', line 202 def draft? @draft end |
#front(node, xml) ⇒ Object
210 211 212 213 214 |
# File 'lib/asciidoctor/standoc/base.rb', line 210 def front(node, xml) xml.bibdata **attr_code(type: "standard") do |b| node, b end end |
#html_converter(node) ⇒ Object
60 61 62 |
# File 'lib/asciidoctor/standoc/base.rb', line 60 def html_converter(node) IsoDoc::HtmlConvert.new(html_extract_attributes(node)) end |
#html_extract_attributes(node) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/asciidoctor/standoc/base.rb', line 38 def html_extract_attributes(node) { script: node.attr("script"), bodyfont: node.attr("body-font"), headerfont: node.attr("header-font"), monospacefont: node.attr("monospace-font"), i18nyaml: node.attr("i18nyaml"), scope: node.attr("scope"), htmlstylesheet: node.attr("htmlstylesheet"), htmlstylesheet_override: node.attr("htmlstylesheet-override"), htmlcoverpage: node.attr("htmlcoverpage"), htmlintropage: node.attr("htmlintropage"), scripts: node.attr("scripts"), scripts_pdf: node.attr("scripts-pdf"), datauriimage: node.attr("data-uri-image"), htmltoclevels: node.attr("htmltoclevels") || node.attr("toclevels"), doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"), break_up_urls_in_tables: node.attr("break-up-urls-in-tables"), sectionsplit: node.attr("sectionsplit"), } end |
#init(node) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/asciidoctor/standoc/base.rb', line 102 def init(node) @fn_number ||= 0 @draft = false @refids = Set.new @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" @fontheader = default_fonts(node) @files_to_delete = [] 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") || "{{{" @sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}" @bibdb = nil @seen_headers = [] @datauriimage = node.attr("data-uri-image") = node.attr("boilerplate-authority") @sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{" @sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}" @log = Metanorma::Utils::Log.new init_bib_caches(node) init_iev_caches(node) @lang = (node.attr("language") || "en") @script = (node.attr("script") || default_script(node.attr("language"))) @isodoc = isodoc(@lang, @script, node.attr("i18nyaml")) @i18n = @isodoc.i18n end |
#makexml(node) ⇒ Object
194 195 196 197 198 199 200 |
# File 'lib/asciidoctor/standoc/base.rb', line 194 def makexml(node) result = makexml1(node) ret1 = cleanup(Nokogiri::XML(result)) ret1.root.add_namespace(nil, xml_namespace) validate(ret1) unless @novalid ret1 end |
#makexml1(node) ⇒ Object
185 186 187 188 189 190 191 192 |
# File 'lib/asciidoctor/standoc/base.rb', line 185 def makexml1(node) 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 |
#middle(node, xml) ⇒ Object
216 217 218 219 220 |
# File 'lib/asciidoctor/standoc/base.rb', line 216 def middle(node, xml) xml.sections do |s| s << node.content if node.blocks? end end |
#outputs(node, ret) ⇒ Object
150 151 152 153 154 155 156 157 |
# File 'lib/asciidoctor/standoc/base.rb', line 150 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") end |
#presentation_xml_converter(node) ⇒ Object
98 99 100 |
# File 'lib/asciidoctor/standoc/base.rb', line 98 def presentation_xml_converter(node) IsoDoc::PresentationXMLConvert.new(html_extract_attributes(node)) end |
#skip(node, name = nil) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/asciidoctor/standoc/base.rb', line 31 def skip(node, name = nil) name = name || node.node_name w = "converter missing for #{name} node in Metanorma backend" @log.add("AsciiDoc Input", node, w) nil end |
#version ⇒ Object
167 168 169 170 |
# File 'lib/asciidoctor/standoc/base.rb', line 167 def version flavour = self.class.name.sub(/::Converter$/, "").sub(/^.+::/, "") Metanorma.versioned(Metanorma, flavour)[-1]::VERSION end |
#xml_namespace ⇒ Object
23 24 25 |
# File 'lib/asciidoctor/standoc/base.rb', line 23 def xml_namespace self.class::XML_NAMESPACE end |
#xml_root_tag ⇒ Object
19 20 21 |
# File 'lib/asciidoctor/standoc/base.rb', line 19 def xml_root_tag self.class::XML_ROOT_TAG end |