Class: Asciidoctor::M3d::Converter
- Inherits:
-
Standoc::Converter
- Object
- Standoc::Converter
- Asciidoctor::M3d::Converter
- Defined in:
- lib/asciidoctor/m3d/converter.rb,
lib/asciidoctor/m3d/validate.rb
Overview
A Converter implementation that generates M3D output, and a document schema encapsulation of the document for validation
Constant Summary collapse
- XML_ROOT_TAG =
"m3d-standard".freeze
- XML_NAMESPACE =
"https://www.metanorma.org/ns/m3d".freeze
Instance Method Summary collapse
- #bibdata_validate(doc) ⇒ Object
- #content_validate(doc) ⇒ Object
- #doctype(node) ⇒ Object
- #document(node) ⇒ Object
- #html_converter(node) ⇒ Object
- #makexml(node) ⇒ Object
- #metadata_author(node, xml) ⇒ Object
- #metadata_committee(node, xml) ⇒ Object
- #metadata_copyright(node, xml) ⇒ Object
- #metadata_id(node, xml) ⇒ Object
- #metadata_publisher(node, xml) ⇒ Object
- #pdf_converter(node) ⇒ Object
- #sections_cleanup(x) ⇒ Object
- #stage_validate(xmldoc) ⇒ Object
- #style(n, t) ⇒ Object
- #title_validate(root) ⇒ Object
- #validate(doc) ⇒ Object
- #word_converter(node) ⇒ Object
Instance Method Details
#bibdata_validate(doc) ⇒ Object
9 10 11 |
# File 'lib/asciidoctor/m3d/validate.rb', line 9 def bibdata_validate(doc) stage_validate(doc) end |
#content_validate(doc) ⇒ Object
4 5 6 7 |
# File 'lib/asciidoctor/m3d/validate.rb', line 4 def content_validate(doc) super bibdata_validate(doc.root) end |
#doctype(node) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/asciidoctor/m3d/converter.rb', line 90 def doctype(node) d = node.attr("doctype") unless %w{policy best-practices supporting-document report}.include? d @log.add("Document Attributes", nil, "#{d} is not a legal document type: reverting to 'report'") d = "report" end d end |
#document(node) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/asciidoctor/m3d/converter.rb', line 99 def document(node) init(node) ret1 = makexml(node) ret = ret1.to_xml(indent: 2) unless node.attr("nodoc") || !node.attr("docfile") filename = node.attr("docfile").gsub(/\.adoc/, ".xml"). gsub(%r{^.*/}, "") File.open(filename, "w") { |f| f.write(ret) } html_converter(node).convert filename unless node.attr("nodoc") word_converter(node).convert filename unless node.attr("nodoc") pdf_converter(node)&.convert filename unless node.attr("nodoc") end @log.write(@localdir + @filename + ".err") unless @novalid @files_to_delete.each { |f| FileUtils.rm f } ret end |
#html_converter(node) ⇒ Object
133 134 135 |
# File 'lib/asciidoctor/m3d/converter.rb', line 133 def html_converter(node) IsoDoc::M3d::HtmlConvert.new(html_extract_attributes(node)) end |
#makexml(node) ⇒ Object
85 86 87 88 |
# File 'lib/asciidoctor/m3d/converter.rb', line 85 def makexml(node) @draft = node.attributes.has_key?("draft") super end |
#metadata_author(node, xml) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/asciidoctor/m3d/converter.rb', line 21 def (node, xml) xml.contributor do |c| c.role **{ type: "author" } c.organization do |a| a.name "Messaging Malware and Mobile Anti-Abuse Working Group" a.abbreviation "M3AAWG" end end end |
#metadata_committee(node, xml) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/asciidoctor/m3d/converter.rb', line 41 def (node, xml) return unless node.attr("technical-committee") xml.editorialgroup do |a| a.committee node.attr("technical-committee"), **attr_code(type: node.attr("technical-committee-type")) i = 2 while node.attr("technical-committee_#{i}") do a.committee node.attr("technical-committee_#{i}"), **attr_code(type: node.attr("technical-committee-type_#{i}")) i += 1 end end end |
#metadata_copyright(node, xml) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/asciidoctor/m3d/converter.rb', line 68 def (node, xml) from = node.attr("copyright-year") || Date.today.year xml.copyright do |c| c.from from c.owner do |owner| owner.organization do |o| o.name "Messaging Malware and Mobile Anti-Abuse Working Group" o.abbreviation "M3AAWG" end end end end |
#metadata_id(node, xml) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/asciidoctor/m3d/converter.rb', line 55 def (node, xml) docstatus = node.attr("status") dn = node.attr("docnumber") if docstatus abbr = IsoDoc::M3d::Metadata.new("en", "Latn", {}). stage_abbr(docstatus) dn = "#{dn}(#{abbr})" unless abbr.empty? end node.attr("copyright-year") and dn += ":#{node.attr("copyright-year")}" xml.docidentifier dn, **{type: "m3d"} xml.docnumber { |i| i << node.attr("docnumber") } end |
#metadata_publisher(node, xml) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/asciidoctor/m3d/converter.rb', line 31 def (node, xml) xml.contributor do |c| c.role **{ type: "publisher" } c.organization do |a| a.name "Messaging Malware and Mobile Anti-Abuse Working Group" a.abbreviation "M3AAWG" end end end |
#pdf_converter(node) ⇒ Object
141 142 143 144 |
# File 'lib/asciidoctor/m3d/converter.rb', line 141 def pdf_converter(node) return nil if node.attr("no-pdf") IsoDoc::M3d::PdfConvert.new(doc_extract_attributes(node)) end |
#sections_cleanup(x) ⇒ Object
122 123 124 125 126 127 |
# File 'lib/asciidoctor/m3d/converter.rb', line 122 def sections_cleanup(x) super x.xpath("//*[@inline-header]").each do |h| h.delete("inline-header") end end |
#stage_validate(xmldoc) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/asciidoctor/m3d/validate.rb', line 13 def stage_validate(xmldoc) stage = xmldoc&.at("//bibdata/status/stage")&.text %w(proposal working-draft committee-draft draft-standard final-draft published withdrawn).include? stage or @log.add("Document Attributes", nil, "#{stage} is not a recognised status") end |
#style(n, t) ⇒ Object
129 130 131 |
# File 'lib/asciidoctor/m3d/converter.rb', line 129 def style(n, t) return end |
#title_validate(root) ⇒ Object
81 82 83 |
# File 'lib/asciidoctor/m3d/converter.rb', line 81 def title_validate(root) nil end |
#validate(doc) ⇒ Object
116 117 118 119 120 |
# File 'lib/asciidoctor/m3d/converter.rb', line 116 def validate(doc) content_validate(doc) schema_validate(formattedstr_strip(doc.dup), File.join(File.dirname(__FILE__), "m3d.rng")) end |
#word_converter(node) ⇒ Object
137 138 139 |
# File 'lib/asciidoctor/m3d/converter.rb', line 137 def word_converter(node) IsoDoc::M3d::WordConvert.new(doc_extract_attributes(node)) end |