Class: Metanorma::Ogc::Converter
- Inherits:
-
Standoc::Converter
- Object
- Standoc::Converter
- Metanorma::Ogc::Converter
- Defined in:
- lib/metanorma/ogc/converter.rb,
lib/metanorma/ogc/front.rb,
lib/metanorma/ogc/cleanup.rb,
lib/metanorma/ogc/validate.rb
Overview
A Converter implementation that generates RSD output, and a document schema encapsulation of the document for validation
Constant Summary collapse
- PUBLISHER =
"./contributor[role/@type = 'publisher']/organization".freeze
- 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: ["./self::clause[@type = 'scope']"], }, { msg: "Scope must be followed by Conformance", val: ["./self::clause[@type = 'conformance']"], }, { msg: "Normative References must be followed by " \ "Terms and Definitions", val: ["./self::terms | .//terms"], }, ].freeze
- XML_ROOT_TAG =
"ogc-standard".freeze
- XML_NAMESPACE =
"https://www.metanorma.org/ns/ogc".freeze
- OGC_COLORS =
{ "text": "rgb(88, 89, 91)", "secondary-shade-1": "rgb(237, 193, 35)", "secondary-shade-2": "rgb(246, 223, 140)", "background-definition-term": "rgb(215, 243, 255)", "background-definition-description": "rgb(242, 251, 255)", "text-title": "rgb(33, 55, 92)", "background-page": "rgb(33, 55, 92)", "background-text-label-legacy": "rgb(33, 60, 107)", "background-term-preferred-label": "rgb(249, 235, 187)", "background-term-deprecated-label": "rgb(237, 237, 238)", "background-term-admitted-label": "rgb(223, 236, 249)", "background-table-header": "rgb(33, 55, 92)", "background-table-row-even": "rgb(252, 246, 222)", "background-table-row-odd": "rgb(254, 252, 245)", "admonition-note": "rgb(79, 129, 189)", "admonition-tip": "rgb(79, 129, 189)", "admonition-editor": "rgb(79, 129, 189)", "admonition-important": "rgb(79, 129, 189)", "admonition-warning": "rgb(79, 129, 189)", "admonition-caution": "rgb(79, 129, 189)", "admonition-todo": "rgb(79, 129, 189)", "admonition-safety-precaution": "rgb(79, 129, 189)", }.freeze
Instance Method Summary collapse
- #add_id ⇒ Object
-
#adoc2xml(text, flavour) ⇒ Object
preempt subdoctype warning.
- #author_title_key(pubclass, title, bib) ⇒ Object
- #bibdata_cleanup(xmldoc) ⇒ Object
- #bibdata_validate(doc) ⇒ Object
- #boilerplate_file(_xmldoc) ⇒ Object
- #clause_parse(attrs, xml, node) ⇒ Object
- #content_validate(doc) ⇒ Object
- #corporate_author(node, xml) ⇒ Object
- #create_security_clause(xml) ⇒ Object
- #default_publisher ⇒ Object
- #default_requirement_model ⇒ Object
- #doc_converter(node) ⇒ Object
- #doctype(node) ⇒ Object
- #execsummary_validate(xmldoc) ⇒ Object
- #externalid(node) ⇒ Object
- #externalurl(node) ⇒ Object
- #highlight_parse(text, xml) ⇒ Object
- #html_converter(node) ⇒ Object
- #init_toc(node) ⇒ Object
- #insert_execsummary(xml, sect) ⇒ Object
- #insert_security(xml, sect) ⇒ Object
- #insert_submitters(xml, sect) ⇒ Object
- #make_preface(xml, sect) ⇒ Object
- #makexml(node) ⇒ Object
- #metadata_attrs(node) ⇒ Object
- #metadata_author(node, xml) ⇒ Object
- #metadata_committee(node, xml) ⇒ Object
- #metadata_committee1(node, xml) ⇒ Object
- #metadata_copyright(node, xml) ⇒ Object
- #metadata_date(node, xml) ⇒ Object
- #metadata_id(node, xml) ⇒ Object
- #metadata_source(node, xml) ⇒ Object
- #metadata_subdoctype(node, xml) ⇒ Object
- #metadata_version(node, xml) ⇒ Object
- #norm_ref_validate(doc) ⇒ Object
- #normref_cleanup(xmldoc) ⇒ Object
- #obligations_cleanup_inherit(xml) ⇒ Object
- #ogc_date(node, xml, ogcname, metanormaname) ⇒ Object
- #ogc_editor(node, xml) ⇒ Object
- #org_abbrev ⇒ Object
- #outputs(node, ret) ⇒ Object
- #override_style(node) ⇒ Object
- #pdf_converter(node) ⇒ Object
- #personal_author(node, xml) ⇒ Object
- #personal_author1(node, xml, suffix) ⇒ Object
- #personal_author_name(node, xml, suffix) ⇒ Object
- #personal_role(node, contrib, suffix) ⇒ Object
- #preface_sequence_validate(root) ⇒ Object
- #presentation_xml_converter(node) ⇒ Object
- #pub_class(bib) ⇒ Object
- #remove_security(xml) ⇒ Object
- #safe_xml_string(node, key, value) ⇒ Object
- #section(node) ⇒ Object
- #section_names_terms_cleanup(xml) ⇒ Object
- #section_validate(doc) ⇒ Object
- #sections_cleanup(xml) ⇒ Object
- #sections_order_cleanup(xml) ⇒ Object
- #sections_sequence_validate(root) ⇒ Object
- #sectiontype(node, level = true) ⇒ Object
- #sectiontype_streamline(ret) ⇒ Object
- #seqcheck(names, msg, accepted) ⇒ Object
- #set_obligation(attrs, node) ⇒ Object
- #sort_annexes(xml) ⇒ Object
- #sort_biblio(bib) ⇒ Object
- #sort_biblio_ids_key(bib) ⇒ Object
-
#sort_biblio_key(bib) ⇒ Object
sort by: doc class (OGC, other standard (not DOI &c), other then standard class (docid class other than DOI &c) then if OGC, doc title else if other, authors then docnumber if present, numeric sort else alphanumeric metanorma id (abbreviation) then doc part number if present, numeric sort then doc id (not DOI &c) then title.
- #stage_type_validate(stage, doctype) ⇒ Object
- #stage_validate(xmldoc) ⇒ Object
- #style(_node, _text) ⇒ Object
- #submitters_parse(attrs, xml, node) ⇒ Object
-
#symbol_key(sym) ⇒ Object
Numbers sort before letters; we leave out using thorn to force that sort order.
- #symbols_cleanup(docxml) ⇒ Object
- #table_cell(node, xml_tr, tblsec) ⇒ Object
- #term_def_parse(attrs, xml, node, _toplevel) ⇒ Object
- #termdef_boilerplate_cleanup(xmldoc) ⇒ Object
- #termdef_cleanup(xmldoc) ⇒ Object
-
#termdef_subclause_cleanup(xmldoc) ⇒ Object
skip annex/terms/terms, which is empty node.
- #terms_annex_parse(attrs, xml, node) ⇒ Object
- #title(node, xml) ⇒ Object
- #title_key(bib) ⇒ Object
- #title_validate(_root) ⇒ Object
-
#toc(value) ⇒ Object
ignore, we generate ToC outside of asciidoctor.
- #update_colors(node) ⇒ Object
- #validate(doc) ⇒ Object
- #version_validate(xmldoc) ⇒ Object
Instance Method Details
#add_id ⇒ Object
22 23 24 |
# File 'lib/metanorma/ogc/cleanup.rb', line 22 def add_id %(id="_#{UUIDTools::UUID.random_create}") end |
#adoc2xml(text, flavour) ⇒ Object
preempt subdoctype warning
250 251 252 253 254 255 256 257 258 |
# File 'lib/metanorma/ogc/converter.rb', line 250 def adoc2xml(text, flavour) Nokogiri::XML(text).root and return text c = Asciidoctor .convert("= X\nA\n:semantic-metadata-headless: true\n" \ ":novalid:\n:docsubtype: implementation\n" \ ":doctype: standard\n\n#{text}\n", backend: flavour, header_footer: true) Nokogiri::XML(c).at("//xmlns:sections") end |
#author_title_key(pubclass, title, bib) ⇒ Object
201 202 203 204 205 206 207 208 209 |
# File 'lib/metanorma/ogc/cleanup.rb', line 201 def (pubclass, title, bib) case pubclass when 1, 2 then title when 3 cite = ::Relaton::Render::General.new .render_all("<references>#{bib.to_xml}</references>") cite[:author] end end |
#bibdata_cleanup(xmldoc) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/metanorma/ogc/cleanup.rb', line 78 def bibdata_cleanup(xmldoc) super a = xmldoc.at("//bibdata/status/stage") a.text == "published" and a.children = "approved" if @doctype == "technical-paper" doctype = xmldoc.at("//bibdata/ext/doctype") doctype.children = "white-paper" @doctype = "white-paper" end end |
#bibdata_validate(doc) ⇒ Object
19 20 21 22 |
# File 'lib/metanorma/ogc/validate.rb', line 19 def bibdata_validate(doc) stage_validate(doc) version_validate(doc) end |
#boilerplate_file(_xmldoc) ⇒ Object
4 5 6 |
# File 'lib/metanorma/ogc/cleanup.rb', line 4 def boilerplate_file(_xmldoc) File.join(@libdir, "boilerplate.adoc") end |
#clause_parse(attrs, xml, node) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/metanorma/ogc/converter.rb', line 107 def clause_parse(attrs, xml, node) %w(executivesummary overview future_outlook value_proposition contributors aims objectives topics outlook security) .include?(node.attr("type")) and attrs = attrs.merge(type: node.attr("type")) case node.attr("heading")&.downcase || node.title.downcase when "submitters" return submitters_parse(attrs, xml, node) when "contributors" return submitters_parse(attrs.merge(type: "contributors"), xml, node) when "conformance" then attrs = attrs.merge(type: "conformance") when "security considerations" attrs = attrs.merge(type: "security") when "executive summary" attrs = attrs.merge(type: "executivesummary") end super end |
#content_validate(doc) ⇒ Object
14 15 16 17 |
# File 'lib/metanorma/ogc/validate.rb', line 14 def content_validate(doc) super bibdata_validate(doc.root) end |
#corporate_author(node, xml) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/metanorma/ogc/front.rb', line 19 def (node, xml) node.attr("submitting-organizations") or return csv_split(@c.decode(node.attr("submitting-organizations")), ";")&.each do |org| xml.contributor do |c| c.role type: "author" c.organization do |a| safe_xml_string(a, "name", org) end end end end |
#create_security_clause(xml) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/metanorma/ogc/cleanup.rb', line 51 def create_security_clause(xml) doctype = xml.at("//bibdata/ext/doctype")&.text description = "document" description = "standard" if %w(standard community-standard) .include?(doctype) <<~CLAUSE <clause type='security' #{add_id}> <title>Security considerations</title> <p>#{@i18n.security_empty.sub('%', description)}</p></clause> CLAUSE end |
#default_publisher ⇒ Object
86 87 88 |
# File 'lib/metanorma/ogc/front.rb', line 86 def default_publisher "OGC" end |
#default_requirement_model ⇒ Object
29 30 31 |
# File 'lib/metanorma/ogc/converter.rb', line 29 def default_requirement_model "ogc" end |
#doc_converter(node) ⇒ Object
245 246 247 |
# File 'lib/metanorma/ogc/converter.rb', line 245 def doc_converter(node) IsoDoc::Ogc::WordConvert.new(doc_extract_attributes(node)) end |
#doctype(node) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/metanorma/ogc/converter.rb', line 42 def doctype(node) d = super d1 = ::IsoDoc::Ogc::DOCTYPE_ABBR.invert[d] and d = d1 unless %w{abstract-specification-topic best-practice other policy change-request-supporting-document community-practice community-standard discussion-paper engineering-report reference-model release-notes standard user-guide white-paper technical-paper test-suite draft-standard}.include? d @warned_doctype or @log.add("Document Attributes", nil, "'#{d}' is not a legal document type: reverting to 'standard'") @warned_doctype = true d = @default_doctype end d end |
#execsummary_validate(xmldoc) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/metanorma/ogc/validate.rb', line 60 def execsummary_validate(xmldoc) sect = xmldoc.at("//clause[@type = 'executivesummary']") @doctype == "engineering-report" && sect.nil? and @log.add("Style", nil, "Executive Summary required for Engineering Reports!") @doctype != "engineering-report" && !sect.nil? and @log.add("Style", nil, "Executive Summary only allowed for Engineering Reports!") end |
#externalid(node) ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/metanorma/ogc/front.rb', line 113 def externalid(node) i = node.attr("external-id") and return i d = doctype(node) a = node.attr("abbrev") d && a or return url = "http://www.opengis.net/doc/#{IsoDoc::Ogc::DOCTYPE_ABBR[d]}/#{a}" v = node.attr("edition") || node.attr("version") and url += "/#{v}" url end |
#externalurl(node) ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/metanorma/ogc/front.rb', line 132 def externalurl(node) if doctype(node) == "engineering-report" "http://www.opengis.net/doc/PER/t14-#{node.attr('referenceurlid')}" else node.attr("referenceurlid") end end |
#highlight_parse(text, xml) ⇒ Object
167 168 169 |
# File 'lib/metanorma/ogc/converter.rb', line 167 def highlight_parse(text, xml) xml.hi { |s| s << text } end |
#html_converter(node) ⇒ Object
235 236 237 |
# File 'lib/metanorma/ogc/converter.rb', line 235 def html_converter(node) IsoDoc::Ogc::HtmlConvert.new(html_extract_attributes(node)) end |
#init_toc(node) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/metanorma/ogc/converter.rb', line 19 def init_toc(node) super @tocfigures = true @toctables = true @tocrecommendations = true end |
#insert_execsummary(xml, sect) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/metanorma/ogc/cleanup.rb', line 26 def insert_execsummary(xml, sect) summ = xml&.at("//clause[@type = 'executivesummary']")&.remove or return preface = sect.at("//preface") || sect.add_previous_sibling("<preface/>").first preface.add_child summ end |
#insert_security(xml, sect) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/metanorma/ogc/cleanup.rb', line 34 def insert_security(xml, sect) description = "document" description = "standard" if %w(standard community-standard) .include?(@doctype) @doctype == "engineering-report" and return remove_security(xml) preface = sect.at("//preface") || sect.add_previous_sibling("<preface/>").first sect = xml.at("//clause[@type = 'security']")&.remove || create_security_clause(xml) preface.add_child sect end |
#insert_submitters(xml, sect) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/metanorma/ogc/cleanup.rb', line 63 def insert_submitters(xml, sect) if xml.at("//submitters") preface = sect.at("//preface") || sect.add_previous_sibling("<preface/>").first xml.xpath("//submitters").each do |s| s.xpath(".//table").each do |t| t["unnumbered"] = true end preface.add_child s.remove end end end |
#make_preface(xml, sect) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/metanorma/ogc/cleanup.rb', line 15 def make_preface(xml, sect) super insert_execsummary(xml, sect) insert_security(xml, sect) insert_submitters(xml, sect) end |
#makexml(node) ⇒ Object
37 38 39 40 |
# File 'lib/metanorma/ogc/converter.rb', line 37 def makexml(node) @draft = node.attributes.has_key?("draft") super end |
#metadata_attrs(node) ⇒ Object
206 207 208 209 210 211 212 213 214 |
# File 'lib/metanorma/ogc/converter.rb', line 206 def (node) c = update_colors(node) ret = super c.keys.sort.each do |k| ret += "<presentation-metadata><name>color-#{k}</name>" \ "<value>#{c[k]}</value></presentation-metadata>" end ret end |
#metadata_author(node, xml) ⇒ Object
8 9 10 11 |
# File 'lib/metanorma/ogc/front.rb', line 8 def (node, xml) (node, xml) (node, xml) end |
#metadata_committee(node, xml) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/metanorma/ogc/front.rb', line 94 def (node, xml) node.attr("committee") or return xml.editorialgroup do |a| (node, a) end end |
#metadata_committee1(node, xml) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/metanorma/ogc/front.rb', line 101 def (node, xml) xml.committee(node.attr("committee") || "technical") node.attr("subcommittee") and xml.subcommittee(node.attr("subcommittee"), **attr_code(type: node.attr("subcommittee-type"), number: node.attr("subcommittee-number"))) (node.attr("workgroup") || node.attr("workinggroup")) and xml.workgroup(node.attr("workgroup") || node.attr("workinggroup"), **attr_code(type: node.attr("workgroup-type"), number: node.attr("workgroup-number"))) end |
#metadata_copyright(node, xml) ⇒ Object
146 147 148 149 150 |
# File 'lib/metanorma/ogc/front.rb', line 146 def (node, xml) node.attr("copyrightyear") and node.set_attr("copyright-year", node.attr("copyrightyear")) super end |
#metadata_date(node, xml) ⇒ Object
152 153 154 155 156 157 |
# File 'lib/metanorma/ogc/front.rb', line 152 def (node, xml) super ogc_date(node, xml, "submissiondate", "received") ogc_date(node, xml, "publicationdate", "published") ogc_date(node, xml, "approvaldate", "issued") end |
#metadata_id(node, xml) ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/metanorma/ogc/front.rb', line 123 def (node, xml) e = externalid(node) and xml.docidentifier e, type: "ogc-external" node.attr("referenceurlid") and xml.docidentifier externalurl(node), type: "ogc-external" docnumber = node.attr("docnumber") || node.attr("docreference") id = node.attr("docidentifier") || docnumber xml.docidentifier id, type: "ogc-internal", primary: "true" end |
#metadata_source(node, xml) ⇒ Object
140 141 142 143 144 |
# File 'lib/metanorma/ogc/front.rb', line 140 def (node, xml) super node.attr("previous-uri") && xml.uri(node.attr("previous-uri"), type: "previous") end |
#metadata_subdoctype(node, xml) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/metanorma/ogc/front.rb', line 173 def (node, xml) s = node.attr("docsubtype") s1 = ::IsoDoc::Ogc::DOCSUBTYPE_ABBR.invert[s] and s = s1 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 @log.add("Document Attributes", nil, "'#{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 @log.add("Document Attributes", nil, "'#{s}' is not a permitted subtype of best-practice: " \ "reverting to 'general'") s = "general" end end s && !s.empty? and xml.subdoctype s end |
#metadata_version(node, xml) ⇒ Object
167 168 169 170 171 |
# File 'lib/metanorma/ogc/front.rb', line 167 def (node, xml) node.attr("version") and node.set_attr("edition", node.attr("version"), false) super end |
#norm_ref_validate(doc) ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/metanorma/ogc/validate.rb', line 146 def norm_ref_validate(doc) @doctype == "engineering-report" or return super doc.xpath("//references[@normative = 'true']").each do |b| @log.add("Bibliography", b, "Engineering report should not contain normative references") end end |
#normref_cleanup(xmldoc) ⇒ Object
126 127 128 129 130 131 132 133 134 |
# File 'lib/metanorma/ogc/cleanup.rb', line 126 def normref_cleanup(xmldoc) r1 = xmldoc.at("//references[title[translate(text(), 'R', 'r') = " \ "'Normative references']]") r2 = xmldoc.at("//references[title[text() = 'References']]") if r1 && r2 r2["normative"] = false end super end |
#obligations_cleanup_inherit(xml) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/metanorma/ogc/cleanup.rb', line 136 def obligations_cleanup_inherit(xml) xml.xpath("//annex").each do |r| r["obligation"] = "informative" unless r["obligation"] end xml.xpath("//clause[not(ancestor::boilerplate)]").each do |r| r["obligation"] = "normative" unless r["obligation"] end xml.xpath(::Metanorma::Standoc::Utils::SUBCLAUSE_XPATH).each do |r| o = r.at("./ancestor::*/@obligation")&.text and r["obligation"] = o end end |
#ogc_date(node, xml, ogcname, metanormaname) ⇒ Object
159 160 161 162 163 164 165 |
# File 'lib/metanorma/ogc/front.rb', line 159 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
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/metanorma/ogc/front.rb', line 54 def ogc_editor(node, xml) node.attr("editor") or return 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 |
#org_abbrev ⇒ Object
90 91 92 |
# File 'lib/metanorma/ogc/front.rb', line 90 def org_abbrev { "Open Geospatial Consortium" => "OGC" } end |
#outputs(node, ret) ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/metanorma/ogc/converter.rb', line 96 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") pdf_converter(node)&.convert("#{@filename}.presentation.xml", nil, false, "#{@filename}.pdf") end |
#override_style(node) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/metanorma/ogc/converter.rb', line 72 def override_style(node) s = node.attr("style") if %w(executive_summary overview future_outlook value_proposition contributors).include?(s) node.set_attr("style", "preface") s == "executive_summary" and s = "executivesummary" node.set_attr("type", s) end if %w(aims objectives topics outlook security).include?(s) node.set_attr("type", s) end end |
#pdf_converter(node) ⇒ Object
239 240 241 242 243 |
# File 'lib/metanorma/ogc/converter.rb', line 239 def pdf_converter(node) return nil if node.attr("no-pdf") IsoDoc::Ogc::PdfConvert.new(pdf_extract_attributes(node)) end |
#personal_author(node, xml) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/metanorma/ogc/front.rb', line 32 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
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/metanorma/ogc/front.rb', line 66 def (node, xml, suffix) xml.contributor do |c| personal_role(node, c, suffix) c.person do |p| p.name do |n| (node, n, suffix) end end end end |
#personal_author_name(node, xml, suffix) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/metanorma/ogc/front.rb', line 77 def (node, xml, suffix) if node.attr("fullname#{suffix}") safe_xml_string(xml, "completename", node.attr("fullname#{suffix}")) else safe_xml_string(xml, "forename", node.attr("givenname#{suffix}")) safe_xml_string(xml, "surname", node.attr("surname#{suffix}")) end end |
#personal_role(node, contrib, suffix) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/metanorma/ogc/front.rb', line 44 def personal_role(node, contrib, suffix) type = node.attr("role#{suffix}")&.downcase || "editor" if type == "contributor" contrib.role type: "author" do |r| safe_xml_string(r, "description", type) end else contrib.role type: type end end |
#preface_sequence_validate(root) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/metanorma/ogc/validate.rb', line 131 def preface_sequence_validate(root) @doctype == "engineering-report" and return root.at("//preface/abstract") or @log.add("Style", nil, "Abstract is missing!") root.at("//bibdata/keyword | //bibdata/ext/keyword") or @log.add("Style", nil, "Keywords are missing!") root.at("//foreword") or @log.add("Style", nil, "Preface is missing!") root.at("//bibdata/contributor[role/@type = 'author']/organization/" \ "name") or @log.add("Style", nil, "Submitting Organizations is missing!") root.at("//submitters") or @log.add("Style", nil, "Submitters is missing!") end |
#presentation_xml_converter(node) ⇒ Object
229 230 231 232 233 |
# File 'lib/metanorma/ogc/converter.rb', line 229 def presentation_xml_converter(node) IsoDoc::Ogc::PresentationXMLConvert .new(html_extract_attributes(node) .merge(output_formats: ::Metanorma::Ogc::Processor.new.output_formats)) end |
#pub_class(bib) ⇒ Object
171 172 173 174 175 176 177 178 179 |
# File 'lib/metanorma/ogc/cleanup.rb', line 171 def pub_class(bib) return 1 if bib.at("#{PUBLISHER}[abbreviation = 'OGC']") return 1 if bib.at("#{PUBLISHER}[name = 'Open Geospatial " \ "Consortium']") return 2 if bib.at("./docidentifier[@type][not(#{skip_docid} or " \ "@type = 'metanorma')]") 3 end |
#remove_security(xml) ⇒ Object
46 47 48 49 |
# File 'lib/metanorma/ogc/cleanup.rb', line 46 def remove_security(xml) a = xml.at("//clause[@type = 'security']") and a.delete("type") end |
#safe_xml_string(node, key, value) ⇒ Object
13 14 15 16 17 |
# File 'lib/metanorma/ogc/front.rb', line 13 def safe_xml_string(node, key, value) node.send key do |n| n << value end end |
#section(node) ⇒ Object
67 68 69 70 |
# File 'lib/metanorma/ogc/converter.rb', line 67 def section(node) override_style(node) super end |
#section_names_terms_cleanup(xml) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/metanorma/ogc/cleanup.rb', line 89 def section_names_terms_cleanup(xml) @i18n or return replace_title(xml, "//definitions[@type = 'symbols']", @i18n.symbols) replace_title(xml, "//definitions[@type = 'abbreviated_terms']", @i18n.abbrev) replace_title(xml, "//definitions[not(@type)]", @i18n.symbolsabbrev) replace_title(xml, "//sections//terms#{SYMnoABBR} | " \ "//sections//clause[.//terms]#{SYMnoABBR}", @i18n.termsdefsymbols, true) replace_title(xml, "//sections//terms#{ABBRnoSYM} | " \ "//sections//clause[.//terms]#{ABBRnoSYM}", @i18n.termsdefabbrev, true) replace_title(xml, "//sections//terms#{SYMABBR} | " \ "//sections//clause[.//terms]#{SYMABBR}", @i18n.termsdefsymbolsabbrev, true) replace_title(xml, "//sections//terms#{NO_SYMABBR} | " \ "//sections//clause[.//terms]#{NO_SYMABBR}", @i18n.termsdefsymbolsabbrev, true) replace_title(xml, "//sections//terms[not(.//definitions)] | " \ "//sections//clause[.//terms][not(.//definitions)]", @i18n.termsdef, true) end |
#section_validate(doc) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/metanorma/ogc/validate.rb', line 70 def section_validate(doc) preface_sequence_validate(doc.root) execsummary_validate(doc.root) sections_sequence_validate(doc.root) super end |
#sections_cleanup(xml) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/metanorma/ogc/cleanup.rb', line 8 def sections_cleanup(xml) super xml.xpath("//*[@inline-header]").each do |h| h.delete("inline-header") end end |
#sections_order_cleanup(xml) ⇒ Object
148 149 150 151 |
# File 'lib/metanorma/ogc/cleanup.rb', line 148 def sections_order_cleanup(xml) super sort_annexes(xml) end |
#sections_sequence_validate(root) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/metanorma/ogc/validate.rb', line 110 def sections_sequence_validate(root) return unless STANDARDTYPE.include?(@doctype) names = root.xpath("//sections/* | //bibliography/*") names = seqcheck(names, SEQ[0][:msg], SEQ[0][:val]) names = seqcheck(names, SEQ[1][:msg], SEQ[1][:val]) names = seqcheck(names, SEQ[2][:msg], SEQ[2][:val]) n = names.shift if n&.at("./self::definitions") n = names.shift end if n.nil? || n.name != "clause" @log.add("Style", nil, "Document must contain at least one clause") return end root.at("//references | //clause[descendant::references]" \ "[not(parent::clause)]") or @log.add("Style", nil, "Normative References are mandatory") end |
#sectiontype(node, level = true) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/metanorma/ogc/converter.rb', line 59 def sectiontype(node, level = true) ret = sectiontype_streamline(sectiontype1(node)) return ret if ret == "terms and definitions" && node.attr("style") == "appendix" && node.level == 1 super end |
#sectiontype_streamline(ret) ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/metanorma/ogc/converter.rb', line 85 def sectiontype_streamline(ret) case ret when "preface" then "foreword" when "foreword", "introduction" then "donotrecognise-foreword" when "references" then "normative references" when "glossary" then "terms and definitions" else super end end |
#seqcheck(names, msg, accepted) ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/metanorma/ogc/validate.rb', line 99 def seqcheck(names, msg, accepted) n = names.shift return [] if n.nil? test = accepted.map { |a| n.at(a) } if test.all?(&:nil?) @log.add("Style", nil, msg) end names end |
#set_obligation(attrs, node) ⇒ Object
171 172 173 174 175 176 177 178 179 |
# File 'lib/metanorma/ogc/converter.rb', line 171 def set_obligation(attrs, node) if node.attr("style") == "appendix" && node.level == 1 attrs[:obligation] = if node.attributes.has_key?("obligation") node.attr("obligation") else "informative" end else super end end |
#sort_annexes(xml) ⇒ Object
153 154 155 156 157 158 159 160 161 |
# File 'lib/metanorma/ogc/cleanup.rb', line 153 def sort_annexes(xml) last = xml.at("//annex[last()]") or return last.next = "<sentinel/>" and last = last.next_element gl = xml.at("//annex[.//term]") and last.previous = gl.remove rev = xml.at("//annex[title[normalize-space(.) = 'Revision history']]") || xml.at("//annex[title[normalize-space(.) = 'Revision History']]") and last.previous = rev.remove last.remove end |
#sort_biblio(bib) ⇒ Object
163 164 165 166 167 |
# File 'lib/metanorma/ogc/cleanup.rb', line 163 def sort_biblio(bib) bib.sort do |a, b| sort_biblio_key(a) <=> sort_biblio_key(b) end end |
#sort_biblio_ids_key(bib) ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/metanorma/ogc/cleanup.rb', line 217 def sort_biblio_ids_key(bib) id = bib.at("./docidentifier[@primary]") || bib.at("./docidentifier[not(#{skip_docid} or @type = 'metanorma')]") = bib.at("./docidentifier[@type = 'metanorma']")&.text /\d-(?<partid>\d+)/ =~ id&.text { id: id&.text, num: bib.at("./docnumber")&.text, abbrid: /^\[\d+\]$/.match?() ? : nil, partid: partid&.to_i || 0, type: id ? id["type"] : nil } end |
#sort_biblio_key(bib) ⇒ Object
sort by: doc class (OGC, other standard (not DOI &c), other then standard class (docid class other than DOI &c) then if OGC, doc title else if other, authors then docnumber if present, numeric sort
else alphanumeric metanorma id (abbreviation)
then doc part number if present, numeric sort then doc id (not DOI &c) then title
189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/metanorma/ogc/cleanup.rb', line 189 def sort_biblio_key(bib) pubclass = pub_class(bib) ids = sort_biblio_ids_key(bib) title = title_key(bib) sortkey3 = (pubclass, title, bib) num = if ids[:num].nil? then ids[:abbrid] else sprintf("%09d", ids[:num].to_i) end "#{pubclass} :: #{ids[:type]} :: #{sortkey3} :: #{num} :: " \ "#{sprintf('%09d', ids[:partid])} :: #{ids[:id]} :: #{title}" end |
#stage_type_validate(stage, doctype) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/metanorma/ogc/validate.rb', line 34 def stage_type_validate(stage, doctype) err = case doctype when "standard", "abstract-specification-topic", "draft-standard" %w(draft work-item-draft).include?(stage) when "community-standard" %w(draft swg-draft).include?(stage) when "best-practice", "community-practice" %w(draft swg-draft work-item-draft).include?(stage) else %w(swg-draft oab-review public-rfc tc-vote work-item-draft deprecated rescinded legacy).include?(stage) end err and @log.add("Document Attributes", nil, "#{stage} is not an allowed status for #{doctype}") end |
#stage_validate(xmldoc) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/metanorma/ogc/validate.rb', line 24 def stage_validate(xmldoc) @doctype == "engineering-report" and return stage = xmldoc&.at("//bibdata/status/stage")&.text %w(draft swg-draft oab-review public-rfc tc-vote work-item-draft approved deprecated retired rescinded legacy).include? stage or @log.add("Document Attributes", nil, "#{stage} is not a recognised status") stage_type_validate(stage, @doctype) end |
#style(_node, _text) ⇒ Object
137 138 139 |
# File 'lib/metanorma/ogc/converter.rb', line 137 def style(_node, _text) nil end |
#submitters_parse(attrs, xml, node) ⇒ Object
126 127 128 129 130 131 132 133 134 135 |
# File 'lib/metanorma/ogc/converter.rb', line 126 def submitters_parse(attrs, xml, node) title = @i18n.submitters doctype(node) == "engineering-report" || attrs[:type] == "contributors" and title = @i18n.contributors_clause xml.submitters **attr_code(attrs) do |xml_section| xml_section.title title xml_section << node.content end end |
#symbol_key(sym) ⇒ Object
Numbers sort before letters; we leave out using thorn to force that sort order. case insensitive
231 232 233 234 235 |
# File 'lib/metanorma/ogc/cleanup.rb', line 231 def symbol_key(sym) @c.decode(asciimath_key(sym).text) .gsub(/[\[\]{}<>()]/, "").gsub(/\s/m, "") .gsub(/[[:punct:]]|[_^]/, ":\\0").delete("`") end |
#symbols_cleanup(docxml) ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/metanorma/ogc/cleanup.rb', line 237 def symbols_cleanup(docxml) docxml.xpath("//definitions/dl").each do |dl| dl_out = extract_symbols_list(dl) dl_out.sort! do |a, b| a[:key].downcase <=> b[:key].downcase || a[:key] <=> b[:key] || a[:dt] <=> b[:dt] end dl.children = dl_out.map { |d| d[:dt].to_s + d[:dd].to_s }.join("\n") end docxml end |
#table_cell(node, xml_tr, tblsec) ⇒ Object
149 150 151 152 |
# File 'lib/metanorma/ogc/converter.rb', line 149 def table_cell(node, xml_tr, tblsec) node.set_attr("valign", "middle") super end |
#term_def_parse(attrs, xml, node, _toplevel) ⇒ Object
141 142 143 144 145 146 147 |
# File 'lib/metanorma/ogc/converter.rb', line 141 def term_def_parse(attrs, xml, node, _toplevel) if node.attr("style") == "appendix" && node.level == 1 terms_annex_parse(attrs, xml, node) else super end end |
#termdef_boilerplate_cleanup(xmldoc) ⇒ Object
76 |
# File 'lib/metanorma/ogc/cleanup.rb', line 76 def termdef_boilerplate_cleanup(xmldoc); end |
#termdef_cleanup(xmldoc) ⇒ Object
112 113 114 115 |
# File 'lib/metanorma/ogc/cleanup.rb', line 112 def termdef_cleanup(xmldoc) super termdef_subclause_cleanup(xmldoc) end |
#termdef_subclause_cleanup(xmldoc) ⇒ Object
skip annex/terms/terms, which is empty node
118 119 120 121 122 123 124 |
# File 'lib/metanorma/ogc/cleanup.rb', line 118 def termdef_subclause_cleanup(xmldoc) xmldoc.xpath("//annex//clause[terms]").each do |t| t.xpath("./clause | ./terms | ./definitions").size == 1 or next t.children.each { |n| n.parent = t.parent } t.remove end end |
#terms_annex_parse(attrs, xml, node) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/metanorma/ogc/converter.rb', line 154 def terms_annex_parse(attrs, xml, node) attrs1 = attrs.merge(id: "_#{UUIDTools::UUID.random_create}") xml.annex **attr_code(attrs1) do |xml_section| xml_section.title { |name| name << node.title } xml_section.terms **attr_code(attrs) do |terms| (s = node.attr("source")) && s.split(",").each do |s1| terms.termdocsource(nil, **attr_code(bibitemid: s1)) end terms << node.content end end end |
#title(node, xml) ⇒ Object
198 199 200 201 202 203 |
# File 'lib/metanorma/ogc/front.rb', line 198 def title(node, xml) super at = { format: "text/plain", type: "abbrev" } a = node.attr("abbrev") and xml.title a, **attr_code(at) end |
#title_key(bib) ⇒ Object
211 212 213 214 215 |
# File 'lib/metanorma/ogc/cleanup.rb', line 211 def title_key(bib) title = bib.at("./title[@type = 'main']") || bib.at("./title") || bib.at("./formattedref") title&.text&.sub!(/^(OGC|Open Geospatial Consortium)\b/, "") end |
#title_validate(_root) ⇒ Object
10 11 12 |
# File 'lib/metanorma/ogc/validate.rb', line 10 def title_validate(_root) nil end |
#toc(value) ⇒ Object
ignore, we generate ToC outside of asciidoctor
27 |
# File 'lib/metanorma/ogc/converter.rb', line 27 def toc(value); end |
#update_colors(node) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/metanorma/ogc/converter.rb', line 216 def update_colors(node) c = OGC_COLORS.dup if document_scheme(node) == "2022" c[:"secondary-shade-1"] = "rgb(0, 177, 255)" c[:"secondary-shade-2"] = "rgb(0, 177, 255)" end if node.attr("doctype") == "white-paper" c[:"text-title"] = "rgb(68, 84, 106)" c[:"background-page"] = "rgb(68, 84, 106)" end c end |
#validate(doc) ⇒ Object
4 5 6 7 8 |
# File 'lib/metanorma/ogc/validate.rb', line 4 def validate(doc) content_validate(doc) schema_validate(formattedstr_strip(doc.dup), File.join(File.dirname(__FILE__), "ogc.rng")) end |
#version_validate(xmldoc) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/metanorma/ogc/validate.rb', line 49 def version_validate(xmldoc) version = xmldoc.at("//bibdata/edition")&.text if %w(engineering-report discussion-paper).include? @doctype version.nil? or @log.add("Document Attributes", nil, "Version not permitted for #{@doctype}") else version.nil? and @log.add("Document Attributes", nil, "Version required for #{@doctype}") end end |