Class: Asciidoctor::Ogc::Converter
- Inherits:
-
Standoc::Converter
- Object
- Standoc::Converter
- Asciidoctor::Ogc::Converter
- Defined in:
- lib/asciidoctor/ogc/front.rb,
lib/asciidoctor/ogc/validate.rb,
lib/asciidoctor/ogc/converter.rb
Overview
A Converter implementation that generates RSD output, and a document schema encapsulation of the document for validation
Constant Summary collapse
- STANDARDTYPE =
%w{standard standard-with-suite abstract-specification community-standard profile}.freeze
- SEQ =
spec of permissible section sequence we skip normative references, it goes to end of list
[ { msg: "Prefatory material must be followed by (clause) Scope", val: [{ tag: "clause", title: "Scope" }], }, { msg: "Scope must be followed by Conformance", val: [{ tag: "clause", title: "Conformance" }], }, { msg: "Normative References must be followed by "\ "Terms and Definitions", val: [ { tag: "terms", title: "Terms and definitions" }, { tag: "clause", title: "Terms and definitions" }, { tag: "terms", title: "Terms, definitions, symbols and abbreviated terms", }, { tag: "clause", title: "Terms, definitions, symbols and abbreviated terms", }, ], }, ].freeze
Instance Method Summary collapse
- #bibdata_validate(doc) ⇒ Object
- #bibliography_parse(attrs, xml, node) ⇒ Object
- #clause_parse(attrs, xml, node) ⇒ Object
- #cleanup(xmldoc) ⇒ Object
- #content_validate(doc) ⇒ Object
- #corporate_author(node, xml) ⇒ Object
- #doctype(node) ⇒ Object
- #document(node) ⇒ Object
- #externalurl(node) ⇒ Object
- #html_converter(node) ⇒ Object
- #make_preface(x, s) ⇒ Object
- #makexml(node) ⇒ Object
- #metadata_author(node, xml) ⇒ Object
- #metadata_committee(node, xml) ⇒ Object
- #metadata_copyright(node, xml) ⇒ Object
- #metadata_date(node, xml) ⇒ Object
- #metadata_ext(node, xml) ⇒ Object
- #metadata_id(node, xml) ⇒ Object
- #metadata_publisher(node, xml) ⇒ Object
- #metadata_source(node, xml) ⇒ Object
- #metadata_subdoctype(node, xml) ⇒ Object
- #ogc_date(node, xml, ogcname, metanormaname) ⇒ Object
- #ogc_editor(node, xml) ⇒ Object
- #pdf_converter(node) ⇒ Object
- #personal_author(node, xml) ⇒ Object
- #personal_author1(node, xml, suffix) ⇒ Object
- #preface_sequence_validate(root) ⇒ Object
- #section_validate(doc) ⇒ Object
- #sections_cleanup(x) ⇒ Object
- #sections_sequence_validate(root) ⇒ Object
- #seqcheck(names, msg, accepted) ⇒ Object
- #stage_validate(xmldoc) ⇒ Object
- #style(n, t) ⇒ Object
- #submitters_parse(attrs, xml, node) ⇒ Object
- #termdef_boilerplate_cleanup(xmldoc) ⇒ Object
- #title_validate(root) ⇒ Object
-
#toc(value) ⇒ Object
ignore, we generate ToC outside of asciidoctor.
- #validate(doc) ⇒ Object
- #word_converter(node) ⇒ Object
Instance Method Details
#bibdata_validate(doc) ⇒ Object
13 14 15 |
# File 'lib/asciidoctor/ogc/validate.rb', line 13 def bibdata_validate(doc) stage_validate(doc) end |
#bibliography_parse(attrs, xml, node) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/asciidoctor/ogc/converter.rb', line 92 def bibliography_parse(attrs, xml, node) clausetype = node&.attr("heading")&.downcase || node.title.downcase if clausetype == "references" then norm_ref_parse(attrs, xml, node) else super end end |
#clause_parse(attrs, xml, node) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/asciidoctor/ogc/converter.rb', line 84 def clause_parse(attrs, xml, node) clausetype = node&.attr("heading")&.downcase || node.title.downcase if clausetype == "submitters" then submitters_parse(attrs, xml, node) else super end end |
#cleanup(xmldoc) ⇒ Object
114 115 116 |
# File 'lib/asciidoctor/ogc/converter.rb', line 114 def cleanup(xmldoc) super end |
#content_validate(doc) ⇒ Object
8 9 10 11 |
# File 'lib/asciidoctor/ogc/validate.rb', line 8 def content_validate(doc) super bibdata_validate(doc.root) end |
#corporate_author(node, xml) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/asciidoctor/ogc/front.rb', line 18 def (node, xml) return unless node.attr("submitting-organizations") node.attr("submitting-organizations").split(/;[ ]*/).each do |org| xml.contributor do |c| c.role **{ type: "author" } c.organization do |a| a.name org end end end end |
#doctype(node) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/asciidoctor/ogc/converter.rb', line 34 def doctype(node) d = node.attr("doctype") unless %w{abstract-specification-topic best-practice change-request-supporting-document community-practice community-standard discussion-paper engineering-report other policy reference-model release-notes standard user-guide white-paper test-suite}.include? d warn "'#{d}' is not a legal document type: reverting to 'standard'" unless @warned_doctype @warned_doctype = true d = "standard" end d end |
#document(node) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/asciidoctor/ogc/converter.rb', line 46 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 @files_to_delete.each { |f| FileUtils.rm f } ret end |
#externalurl(node) ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/asciidoctor/ogc/front.rb', line 106 def externalurl(node) if node.attr("doctype") == "engineering-report" "http://www.opengis.net/doc/PER/t14-#{node.attr('referenceurlid')}" else node.attr('referenceurlid') end end |
#html_converter(node) ⇒ Object
118 119 120 |
# File 'lib/asciidoctor/ogc/converter.rb', line 118 def html_converter(node) IsoDoc::Ogc::HtmlConvert.new(html_extract_attributes(node)) end |
#make_preface(x, s) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/asciidoctor/ogc/converter.rb', line 75 def make_preface(x, s) super if x.at("//submitters") preface = s.at("//preface") || s.add_previous_sibling("<preface/>").first submitters = x.at("//submitters").remove preface.add_child submitters.remove end end |
#makexml(node) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/asciidoctor/ogc/converter.rb', line 21 def makexml(node) result = ["<?xml version='1.0' encoding='UTF-8'?>\n<ogc-standard>"] @draft = node.attributes.has_key?("draft") result << noko { |ixml| front node, ixml } result << noko { |ixml| middle node, ixml } result << "</ogc-standard>" result = textcleanup(result) ret1 = cleanup(Nokogiri::XML(result)) validate(ret1) unless @novalid ret1.root.add_namespace(nil, Metanorma::Ogc::DOCUMENT_NAMESPACE) ret1 end |
#metadata_author(node, xml) ⇒ Object
13 14 15 16 |
# File 'lib/asciidoctor/ogc/front.rb', line 13 def (node, xml) (node, xml) (node, xml) end |
#metadata_committee(node, xml) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/asciidoctor/ogc/front.rb', line 79 def (node, xml) return unless node.attr("committee") xml.editorialgroup do |a| a.committee(node.attr("committee") || "technical") node.attr("subcommittee") and a.subcommittee(node.attr("subcommittee"), **attr_code(type: node.attr("subcommittee-type"), number: node.attr("subcommittee-number"))) (node.attr("workgroup") || node.attr("workinggroup")) and a.workgroup(node.attr("workgroup") || node.attr("workinggroup"), **attr_code(type: node.attr("workgroup-type"), number: node.attr("workgroup-number"))) end end |
#metadata_copyright(node, xml) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/asciidoctor/ogc/front.rb', line 120 def (node, xml) from = node.attr("copyright-year") || node.attr("copyrightyear") || Date.today.year xml.copyright do |c| c.from from c.owner do |owner| owner.organization do |o| o.name Metanorma::Ogc::ORGANIZATION_NAME_SHORT end end end end |
#metadata_date(node, xml) ⇒ Object
133 134 135 136 137 138 |
# File 'lib/asciidoctor/ogc/front.rb', line 133 def (node, xml) super ogc_date(node, xml, "submissiondate", "received" ) ogc_date(node, xml, "publicationdate", "published" ) ogc_date(node, xml, "approvaldate", "issued" ) end |
#metadata_ext(node, xml) ⇒ Object
170 171 172 173 174 |
# File 'lib/asciidoctor/ogc/front.rb', line 170 def (node, xml) (node, xml) (node, xml) (node, xml) end |
#metadata_id(node, xml) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/asciidoctor/ogc/front.rb', line 94 def (node, xml) node.attr("external-id") and xml.docidentifier node.attr("external-id"), **{ type: "ogc-external" } node.attr("referenceurlid") and xml.docidentifier externalurl(node), **{ type: "ogc-external" } docnumber = node.attr("docnumber") || node.attr("docreference") if docnumber xml.docidentifier docnumber, **{ type: "ogc-internal" } xml.docnumber docnumber end end |
#metadata_publisher(node, xml) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/asciidoctor/ogc/front.rb', line 70 def (node, xml) xml.contributor do |c| c.role **{ type: "publisher" } c.organization do |a| a.name Metanorma::Ogc::ORGANIZATION_NAME_SHORT end end end |
#metadata_source(node, xml) ⇒ Object
114 115 116 117 118 |
# File 'lib/asciidoctor/ogc/front.rb', line 114 def (node, xml) super node.attr("previous-uri") && xml.uri(node.attr("previous-uri"), type: "previous") end |
#metadata_subdoctype(node, xml) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/asciidoctor/ogc/front.rb', line 148 def (node, xml) s = node.attr("docsubtype") case doctype(node) when "standard" unless %w{conceptual-model conceptual-model-and-encoding conceptual-model-and-implementation encoding extension implementation profile profile-with-extension}.include? s warn "'#{s}' is not a permitted subtype of Standard: "\ "reverting to 'implementation'" s = "implementation" end when "best-practice" unless %w{general encoding extension profile profile-with-extension}.include? s warn "'#{s}' is not a permitted subtype of Standard: "\ "reverting to 'implementation'" s = "general" end end s and xml.docsubtype s end |
#ogc_date(node, xml, ogcname, metanormaname) ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/asciidoctor/ogc/front.rb', line 140 def ogc_date(node, xml, ogcname, ) if node.attr(ogcname) xml.date **{ type: } do |d| d.on node.attr(ogcname) end end end |
#ogc_editor(node, xml) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/asciidoctor/ogc/front.rb', line 42 def ogc_editor(node, xml) return unless node.attr("editor") xml.contributor do |c| c.role **{ type: "editor" } c.person do |p| p.name do |n| n.completename node.attr("editor") end end end end |
#pdf_converter(node) ⇒ Object
122 123 124 |
# File 'lib/asciidoctor/ogc/converter.rb', line 122 def pdf_converter(node) IsoDoc::Ogc::PdfConvert.new(html_extract_attributes(node)) end |
#personal_author(node, xml) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/asciidoctor/ogc/front.rb', line 30 def (node, xml) ogc_editor(node, xml) if node.attr("fullname") || node.attr("surname") (node, xml, "") end i = 2 while node.attr("fullname_#{i}") || node.attr("surname_#{i}") (node, xml, "_#{i}") i += 1 end end |
#personal_author1(node, xml, suffix) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/asciidoctor/ogc/front.rb', line 54 def (node, xml, suffix) xml.contributor do |c| c.role **{ type: node&.attr("role#{suffix}")&.downcase || "editor" } c.person do |p| p.name do |n| if node.attr("fullname#{suffix}") n.completename node.attr("fullname#{suffix}") else n.forename node.attr("givenname#{suffix}") n.surname node.attr("surname#{suffix}") end end end end end |
#preface_sequence_validate(root) ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/asciidoctor/ogc/validate.rb', line 93 def preface_sequence_validate(root) root.at("//preface/abstract") or warn "OGC style: Abstract is missing!" root.at("//bibdata/keyword | //bibdata/ext/keyword") or warn "OGC style: Keywords are missing!" root.at("//foreword") or warn "OGC style: Preface is missing!" root.at("//bibdata/contributor[role/@type = 'author']/organization/"\ "name") or warn "OGC style: Submitting Organizations is missing!" root.at("//submitters") or warn "OGC style: Submitters is missing!" end |
#section_validate(doc) ⇒ Object
24 25 26 27 |
# File 'lib/asciidoctor/ogc/validate.rb', line 24 def section_validate(doc) preface_sequence_validate(doc.root) sections_sequence_validate(doc.root) end |
#sections_cleanup(x) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/asciidoctor/ogc/converter.rb', line 68 def sections_cleanup(x) super x.xpath("//*[@inline-header]").each do |h| h.delete("inline-header") end end |
#sections_sequence_validate(root) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/asciidoctor/ogc/validate.rb', line 71 def sections_sequence_validate(root) return unless STANDARDTYPE.include?( root&.at("//bibdata/ext/doctype")&.text) f = root.at("//sections").elements names = f.map { |s| { tag: s.name, title: s&.at("./title")&.text } } names = seqcheck(names, SEQ[0][:msg], SEQ[0][:val]) || return names = seqcheck(names, SEQ[1][:msg], SEQ[1][:val]) || return names = seqcheck(names, SEQ[2][:msg], SEQ[2][:val]) || return n = names.shift if !n.nil? && n[:tag] == "definitions" n = names.shift end unless n warn "OGC style: Document must contain at least one clause" return end root.at("//references | //clause[descendant::references]"\ "[not(parent::clause)]") or seqcheck([{tag: "clause"}], "Normative References are mandatory", [{tag: "references"}]) end |
#seqcheck(names, msg, accepted) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/asciidoctor/ogc/validate.rb', line 62 def seqcheck(names, msg, accepted) n = names.shift unless accepted.include? n warn "OGC style: #{msg}" names = [] end names end |
#stage_validate(xmldoc) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/asciidoctor/ogc/validate.rb', line 17 def stage_validate(xmldoc) stage = xmldoc&.at("//bibdata/status/stage")&.text %w(swg-draft oab-review public-rfc tc-vote published deprecated retired).include? stage or warn "Document Attributes: #{stage} is not a recognised status" end |
#style(n, t) ⇒ Object
106 107 108 |
# File 'lib/asciidoctor/ogc/converter.rb', line 106 def style(n, t) return end |
#submitters_parse(attrs, xml, node) ⇒ Object
100 101 102 103 104 |
# File 'lib/asciidoctor/ogc/converter.rb', line 100 def submitters_parse(attrs, xml, node) xml.submitters **attr_code(attrs) do |xml_section| xml_section << node.content end end |
#termdef_boilerplate_cleanup(xmldoc) ⇒ Object
110 111 112 |
# File 'lib/asciidoctor/ogc/converter.rb', line 110 def termdef_boilerplate_cleanup(xmldoc) return end |
#title_validate(root) ⇒ Object
4 5 6 |
# File 'lib/asciidoctor/ogc/validate.rb', line 4 def title_validate(root) nil end |
#toc(value) ⇒ Object
ignore, we generate ToC outside of asciidoctor
18 19 |
# File 'lib/asciidoctor/ogc/converter.rb', line 18 def toc(value) end |
#validate(doc) ⇒ Object
62 63 64 65 66 |
# File 'lib/asciidoctor/ogc/converter.rb', line 62 def validate(doc) content_validate(doc) schema_validate(formattedstr_strip(doc.dup), File.join(File.dirname(__FILE__), "ogc.rng")) end |
#word_converter(node) ⇒ Object
126 127 128 |
# File 'lib/asciidoctor/ogc/converter.rb', line 126 def word_converter(node) IsoDoc::Ogc::WordConvert.new(doc_extract_attributes(node)) end |