Class: Metanorma::Ogc::Converter
- Inherits:
-
Standoc::Converter
- Object
- Standoc::Converter
- Metanorma::Ogc::Converter
- Defined in:
- lib/metanorma/ogc/log.rb,
lib/metanorma/ogc/front.rb,
lib/metanorma/ogc/cleanup.rb,
lib/metanorma/ogc/sections.rb,
lib/metanorma/ogc/validate.rb,
lib/metanorma/ogc/converter.rb
Constant Summary collapse
- OGC_LOG_MESSAGES =
{ # rubocop:disable Naming/VariableNumber "OGC_1": { category: "Document Attributes", error: "%s is not a recognised status", severity: 2 }, "OGC_2": { category: "Document Attributes", error: "%s is not an allowed status for %s", severity: 2 }, "OGC_3": { category: "Document Attributes", error: "Version not permitted for %s", severity: 2 }, "OGC_4": { category: "Document Attributes", error: "Version required for %s", severity: 2 }, "OGC_5": { category: "Style", error: "Executive Summary required for Engineering Reports!", severity: 2 }, "OGC_6": { category: "Style", error: "Executive Summary only allowed for Engineering Reports!", severity: 2 }, "OGC_7": { category: "Style", error: "(section sequencing) %s", severity: 2 }, "OGC_8": { category: "Style", error: "Document must contain at least one clause", severity: 2 }, "OGC_9": { category: "Style", error: "Normative References are mandatory", severity: 2 }, "OGC_10": { category: "Style", error: "Abstract is missing!", severity: 2 }, "OGC_11": { category: "Style", error: "Keywords are missing!", severity: 2 }, "OGC_12": { category: "Style", error: "Preface is missing!", severity: 2 }, "OGC_13": { category: "Style", error: "Submitting Organizations is missing!", severity: 2 }, "OGC_14": { category: "Style", error: "Submitters is missing!", severity: 2 }, "OGC_15": { category: "Bibliography", error: "Engineering report should not contain normative references", severity: 2 }, "OGC_16": { category: "Document Attributes", error: "'%s' is not a legal document type: reverting to 'standard'", severity: 2 }, "OGC_17": { category: "Document Attributes", error: "'%s' is not a permitted subtype of Standard: reverting to 'implementation'", severity: 2 }, "OGC_18": { category: "Document Attributes", error: "'%s' is not a permitted subtype of best-practice: reverting to 'general'", severity: 2 }, }.freeze
- 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
- 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
-
#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
- #create_security_clause(xml) ⇒ Object
- #default_publisher ⇒ Object
- #default_requirement_model ⇒ Object
- #doc_converter(node) ⇒ Object
- #doctype(node) ⇒ Object
- #document_scheme(node) ⇒ Object
- #execsummary_validate(xmldoc) ⇒ Object
- #externalid(node) ⇒ Object
- #externalurl(node) ⇒ Object
- #html_converter(node) ⇒ Object
- #init_toc(node) ⇒ Object
- #insert_security(xml, sect) ⇒ Object
- #insert_submitters(xml, sect) ⇒ Object
-
#log_messages ⇒ Object
rubocop:enable Naming/VariableNumber.
- #make_preface(xml, sect) ⇒ Object
- #metadata_attrs(node) ⇒ Object
- #metadata_committee_prep(node) ⇒ Object
- #metadata_committee_types(_node) ⇒ 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
- #org_author(node, xml) ⇒ Object
- #outputs(node, ret) ⇒ Object
- #override_style(node) ⇒ Object
- #parse_flexible_date(date_str) ⇒ 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
- #published?(status, _docxml) ⇒ Boolean
- #published_date_scheme(date_str) ⇒ Object
- #remove_security(xml) ⇒ Object
- #schema_file ⇒ Object
- #section(node) ⇒ Object
-
#section_names_terms1_cleanup(xml) ⇒ Object
as in standoc, but do not rename annex terms.
- #section_validate(doc) ⇒ Object
- #sections_cleanup(xml) ⇒ Object
- #sections_order_cleanup(xml) ⇒ Object
- #sections_sequence_validate(root) ⇒ Object
- #sectiontype(node, level = true) ⇒ Object
-
#sectiontype1(node) ⇒ Object
legacy encoding.
- #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
- #version_validate(xmldoc) ⇒ Object
Instance Method Details
#adoc2xml(text, flavour) ⇒ Object
preempt subdoctype warning
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/metanorma/ogc/converter.rb', line 166 def adoc2xml(text, flavour) Nokogiri::XML(text).root and return text c = isolated_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
179 180 181 182 183 184 185 186 187 |
# File 'lib/metanorma/ogc/cleanup.rb', line 179 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
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/metanorma/ogc/cleanup.rb', line 64 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
17 18 19 20 |
# File 'lib/metanorma/ogc/validate.rb', line 17 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
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/metanorma/ogc/sections.rb', line 48 def clause_parse(attrs, xml, node) %w(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.merge(type: "submitters"), 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") end super end |
#content_validate(doc) ⇒ Object
12 13 14 15 |
# File 'lib/metanorma/ogc/validate.rb', line 12 def content_validate(doc) super bibdata_validate(doc.root) end |
#create_security_clause(xml) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/metanorma/ogc/cleanup.rb', line 38 def create_security_clause(xml) doctype = xml.at("//bibdata/ext/doctype")&.text description = "document" description = "standard" if %w(standard community-standard) .include?(doctype) " <clause type='security' \#{add_id_text}>\n <title \#{add_id_text}>Security considerations</title>\n <p>\#{@i18n.security_empty.sub('%', description)}</p></clause>\n CLAUSE\nend\n" |
#default_publisher ⇒ Object
75 76 77 |
# File 'lib/metanorma/ogc/front.rb', line 75 def default_publisher "OGC" end |
#default_requirement_model ⇒ Object
22 23 24 |
# File 'lib/metanorma/ogc/converter.rb', line 22 def default_requirement_model "ogc" end |
#doc_converter(node) ⇒ Object
161 162 163 |
# File 'lib/metanorma/ogc/converter.rb', line 161 def doc_converter(node) IsoDoc::Ogc::WordConvert.new(doc_extract_attributes(node)) end |
#doctype(node) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/metanorma/ogc/converter.rb', line 30 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("OGC_16", nil, params: [d]) @warned_doctype = true d = @default_doctype end d end |
#document_scheme(node) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/metanorma/ogc/converter.rb', line 46 def document_scheme(node) if r = node.attr("document-scheme") r == "2022" ? "2022" : "2018" elsif r = node.attr("published-date") published_date_scheme(r) elsif r = node.attr("copyright-year") r.to_i >= 2022 ? "2022" : "2018" else "2022" end end |
#execsummary_validate(xmldoc) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/metanorma/ogc/validate.rb', line 54 def execsummary_validate(xmldoc) sect = xmldoc.at("//executivesummary") @doctype == "engineering-report" && sect.nil? and @log.add("OGC_5", nil) @doctype != "engineering-report" && !sect.nil? and @log.add("OGC_6", nil) end |
#externalid(node) ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/metanorma/ogc/front.rb', line 94 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
116 117 118 119 120 121 122 |
# File 'lib/metanorma/ogc/front.rb', line 116 def externalurl(node) if doctype(node) == "engineering-report" "http://www.opengis.net/doc/PER/t14-#{node.attr('referenceurlid')}" else node.attr("referenceurlid") end end |
#html_converter(node) ⇒ Object
151 152 153 |
# File 'lib/metanorma/ogc/converter.rb', line 151 def html_converter(node) IsoDoc::Ogc::HtmlConvert.new(html_extract_attributes(node)) end |
#init_toc(node) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/metanorma/ogc/converter.rb', line 15 def init_toc(node) super @tocfigures = true @toctables = true @tocrecommendations = true end |
#insert_security(xml, sect) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/metanorma/ogc/cleanup.rb', line 21 def insert_security(xml, sect) "document" "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
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/metanorma/ogc/cleanup.rb', line 50 def insert_submitters(xml, sect) if xml.at("//clause[@type = 'submitters' or @type = 'contributors']") p = sect.at("//preface") || sect.add_previous_sibling("<preface/>").first xml.xpath("//clause[@type = 'submitters' or @type = 'contributors']") .each do |s| s.xpath(".//table").each { |t| t["unnumbered"] = true } p.add_child s.remove end end end |
#log_messages ⇒ Object
rubocop:enable Naming/VariableNumber
63 64 65 |
# File 'lib/metanorma/ogc/log.rb', line 63 def super.merge(OGC_LOG_MESSAGES) end |
#make_preface(xml, sect) ⇒ Object
15 16 17 18 19 |
# File 'lib/metanorma/ogc/cleanup.rb', line 15 def make_preface(xml, sect) super insert_security(xml, sect) insert_submitters(xml, sect) end |
#metadata_attrs(node) ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'lib/metanorma/ogc/converter.rb', line 122 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_committee_prep(node) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/metanorma/ogc/front.rb', line 87 def (node) node.attr("committee") or node.set_attribute("committee", "technical") a = node.attr("workinggroup") and node.set_attribute("workgroup", a) true end |
#metadata_committee_types(_node) ⇒ Object
83 84 85 |
# File 'lib/metanorma/ogc/front.rb', line 83 def (_node) %w(committee subcommittee workgroup) end |
#metadata_copyright(node, xml) ⇒ Object
129 130 131 132 133 |
# File 'lib/metanorma/ogc/front.rb', line 129 def (node, xml) node.attr("copyrightyear") and node.set_attr("copyright-year", node.attr("copyrightyear")) super end |
#metadata_date(node, xml) ⇒ Object
135 136 137 138 139 140 |
# File 'lib/metanorma/ogc/front.rb', line 135 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
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/metanorma/ogc/front.rb', line 104 def (node, xml) add_noko_elem(xml, "docidentifier", externalid(node), type: "ogc-external") node.attr("referenceurlid") and add_noko_elem(xml, "docidentifier", externalurl(node), type: "ogc-external") id = node.attr("docidentifier") || node.attr("docnumber") || node.attr("docreference") add_noko_elem(xml, "docidentifier", id, type: "ogc-internal", primary: "true") end |
#metadata_source(node, xml) ⇒ Object
124 125 126 127 |
# File 'lib/metanorma/ogc/front.rb', line 124 def (node, xml) super add_noko_elem(xml, "uri", node.attr("previous-uri"), type: "previous") end |
#metadata_subdoctype(node, xml) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/metanorma/ogc/front.rb', line 156 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("OGC_17", nil, params: [s]) s = "implementation" end when "best-practice" unless %w{general encoding extension profile profile-with-extension}.include? s @log.add("OGC_18", nil, params: [s]) s = "general" end end s && !s.empty? and xml.subdoctype s end |
#metadata_version(node, xml) ⇒ Object
150 151 152 153 154 |
# File 'lib/metanorma/ogc/front.rb', line 150 def (node, xml) node.attr("version") and node.set_attr("edition", node.attr("version"), false) super end |
#norm_ref_validate(doc) ⇒ Object
134 135 136 137 138 139 |
# File 'lib/metanorma/ogc/validate.rb', line 134 def norm_ref_validate(doc) @doctype == "engineering-report" or return super doc.xpath("//references[@normative = 'true']").each do |b| @log.add("OGC_15", b) end end |
#normref_cleanup(xmldoc) ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/metanorma/ogc/cleanup.rb', line 104 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
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/metanorma/ogc/cleanup.rb', line 114 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
142 143 144 145 146 147 148 |
# File 'lib/metanorma/ogc/front.rb', line 142 def ogc_date(node, xml, ogcname, ) if node.attr(ogcname) xml.date type: do |d| add_noko_elem(d, "on", node.attr(ogcname)) end end end |
#ogc_editor(node, xml) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/metanorma/ogc/front.rb', line 43 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| add_noko_elem(n, "completename", node.attr("editor")) end end end end |
#org_abbrev ⇒ Object
79 80 81 |
# File 'lib/metanorma/ogc/front.rb', line 79 def org_abbrev { "Open Geospatial Consortium" => "OGC" } end |
#org_author(node, xml) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/metanorma/ogc/front.rb', line 8 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| add_noko_elem(a, "name", org) end end end end |
#outputs(node, ret) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/metanorma/ogc/converter.rb', line 77 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
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/metanorma/ogc/sections.rb', line 20 def override_style(node) s = node.attr("style") if %w(overview future_outlook value_proposition contributors).include?(s) node.set_attr("style", "preface") node.set_attr("type", s) end if %w(aims objectives topics outlook security).include?(s) node.set_attr("type", s) end end |
#parse_flexible_date(date_str) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/metanorma/ogc/converter.rb', line 65 def parse_flexible_date(date_str) case date_str when /^\d{4}$/ Date.new(date_str.to_i, 1, 1) when /^\d{4}-\d{2}$/ year, month = date_str.split("-").map(&:to_i) Date.new(year, month, 1) else Date.parse(date_str) end end |
#pdf_converter(node) ⇒ Object
155 156 157 158 159 |
# File 'lib/metanorma/ogc/converter.rb', line 155 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
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/metanorma/ogc/front.rb', line 21 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
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/metanorma/ogc/front.rb', line 55 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
66 67 68 69 70 71 72 73 |
# File 'lib/metanorma/ogc/front.rb', line 66 def (node, xml, suffix) if node.attr("fullname#{suffix}") add_noko_elem(xml, "completename", node.attr("fullname#{suffix}")) else add_noko_elem(xml, "forename", node.attr("givenname#{suffix}")) add_noko_elem(xml, "surname", node.attr("surname#{suffix}")) end end |
#personal_role(node, contrib, suffix) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/metanorma/ogc/front.rb', line 33 def personal_role(node, contrib, suffix) type = node.attr("role#{suffix}")&.downcase || "editor" if type == "contributor" contrib.role type: "author" do |r| add_noko_elem(r, "description", type) end else contrib.role type: type end end |
#preface_sequence_validate(root) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/metanorma/ogc/validate.rb', line 121 def preface_sequence_validate(root) @doctype == "engineering-report" and return root.at("//preface/abstract") or @log.add("OGC_10", nil) root.at("//bibdata/keyword | //bibdata/ext/keyword") or @log.add("OGC_11", nil) root.at("//foreword") or @log.add("OGC_12", nil) root.at("//bibdata/contributor[role/@type = 'author']/organization/" \ "name") or @log.add("OGC_13", nil) root.at("//clause[@type = 'submitters' or @type = 'contributors']") or @log.add("OGC_14", nil) end |
#presentation_xml_converter(node) ⇒ Object
145 146 147 148 149 |
# File 'lib/metanorma/ogc/converter.rb', line 145 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
149 150 151 152 153 154 155 156 157 |
# File 'lib/metanorma/ogc/cleanup.rb', line 149 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 |
#published?(status, _docxml) ⇒ Boolean
227 228 229 |
# File 'lib/metanorma/ogc/cleanup.rb', line 227 def published?(status, _docxml) %w(approved deprecated retired published).include?(status.downcase) end |
#published_date_scheme(date_str) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/metanorma/ogc/converter.rb', line 57 def published_date_scheme(date_str) published_date = parse_flexible_date(date_str) or return nil cutoff_date = Date.new(2021, 11, 8) published_date >= cutoff_date ? "2022" : "2018" rescue Date::Error, ArgumentError nil end |
#remove_security(xml) ⇒ Object
33 34 35 36 |
# File 'lib/metanorma/ogc/cleanup.rb', line 33 def remove_security(xml) a = xml.at("//clause[@type = 'security']") and a.delete("type") end |
#schema_file ⇒ Object
4 5 6 |
# File 'lib/metanorma/ogc/validate.rb', line 4 def schema_file "ogc.rng" end |
#section(node) ⇒ Object
15 16 17 18 |
# File 'lib/metanorma/ogc/sections.rb', line 15 def section(node) override_style(node) super end |
#section_names_terms1_cleanup(xml) ⇒ Object
as in standoc, but do not rename annex terms
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/metanorma/ogc/cleanup.rb', line 76 def section_names_terms1_cleanup(xml) auto_name_terms(xml) or return replace_title(xml, "//sections/terms#{SYM_NO_ABBR} | //sections/clause[@type = 'terms']#{SYM_NO_ABBR}", @i18n&.termsdefsymbols, true) replace_title(xml, "//sections/terms#{ABBR_NO_SYM} | //sections/clause[@type = 'terms']#{ABBR_NO_SYM}", @i18n&.termsdefabbrev, true) replace_title(xml, "//sections/terms#{SYMABBR} | //sections/clause[@type = 'terms']#{SYMABBR}", @i18n&.termsdefsymbolsabbrev, true) replace_title(xml, "//sections/terms#{NO_SYMABBR} | //sections/clause[@type = 'terms']#{NO_SYMABBR}", @i18n&.termsdefsymbolsabbrev, true) replace_title(xml, "//sections/terms[not(.//definitions)] | //sections/clause[@type = 'terms'][not(.//definitions)]", @i18n&.termsdef, true) end |
#section_validate(doc) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/metanorma/ogc/validate.rb', line 62 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
126 127 128 129 |
# File 'lib/metanorma/ogc/cleanup.rb', line 126 def sections_order_cleanup(xml) super sort_annexes(xml) end |
#sections_sequence_validate(root) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/metanorma/ogc/validate.rb', line 102 def sections_sequence_validate(root) STANDARDTYPE.include?(@doctype) or return 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("OGC_8", nil) return end root.at("//references | //clause[descendant::references]" \ "[not(parent::clause)]") or @log.add("OGC_9", nil) end |
#sectiontype(node, level = true) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/metanorma/ogc/sections.rb', line 7 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 |
#sectiontype1(node) ⇒ Object
legacy encoding
43 44 45 46 |
# File 'lib/metanorma/ogc/sections.rb', line 43 def sectiontype1(node) role_style(node, "executive_summary") and return "executivesummary" super end |
#sectiontype_streamline(ret) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/metanorma/ogc/sections.rb', line 32 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
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/metanorma/ogc/validate.rb', line 91 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("OGC_7", nil, params: [msg]) end names end |
#set_obligation(attrs, node) ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/metanorma/ogc/sections.rb', line 98 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
131 132 133 134 135 136 137 138 139 |
# File 'lib/metanorma/ogc/cleanup.rb', line 131 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
141 142 143 144 145 |
# File 'lib/metanorma/ogc/cleanup.rb', line 141 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
195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/metanorma/ogc/cleanup.rb', line 195 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 id (abbreviation)
then doc part number if present, numeric sort then doc id (not DOI &c) then title
167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/metanorma/ogc/cleanup.rb', line 167 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
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/metanorma/ogc/validate.rb', line 31 def stage_type_validate(stage, doctype) 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 and @log.add("OGC_2", nil, params: [stage, doctype]) end |
#stage_validate(xmldoc) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/metanorma/ogc/validate.rb', line 22 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("OGC_1", nil, params: [stage]) stage_type_validate(stage, @doctype) end |
#style(_node, _text) ⇒ Object
88 89 90 |
# File 'lib/metanorma/ogc/converter.rb', line 88 def style(_node, _text) nil end |
#submitters_parse(attrs, xml, node) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/metanorma/ogc/sections.rb', line 65 def submitters_parse(attrs, xml, node) title = @i18n.submitters doctype(node) == "engineering-report" || attrs[:type] == "contributors" and title = @i18n.contributors_clause xml.clause **attr_code(attrs) do |xml_section| section_title(xml_section, 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
209 210 211 212 213 |
# File 'lib/metanorma/ogc/cleanup.rb', line 209 def symbol_key(sym) @c.decode(asciimath_key(sym).text) .gsub(/[\[\]{}<>()]/, "").gsub(/\s/m, "") .gsub(/[[:punct:]]|[_^]/, ":\\0").delete("`") end |
#symbols_cleanup(docxml) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/metanorma/ogc/cleanup.rb', line 215 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
92 93 94 95 |
# File 'lib/metanorma/ogc/converter.rb', line 92 def table_cell(node, xml_tr, tblsec) node.set_attr("valign", "middle") super end |
#term_def_parse(attrs, xml, node, _toplevel) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/metanorma/ogc/sections.rb', line 76 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
62 |
# File 'lib/metanorma/ogc/cleanup.rb', line 62 def termdef_boilerplate_cleanup(xmldoc); end |
#termdef_cleanup(xmldoc) ⇒ Object
90 91 92 93 |
# File 'lib/metanorma/ogc/cleanup.rb', line 90 def termdef_cleanup(xmldoc) super termdef_subclause_cleanup(xmldoc) end |
#termdef_subclause_cleanup(xmldoc) ⇒ Object
skip annex/terms/terms, which is empty node
96 97 98 99 100 101 102 |
# File 'lib/metanorma/ogc/cleanup.rb', line 96 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
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/metanorma/ogc/sections.rb', line 84 def terms_annex_parse(attrs, xml, node) attrs1 = attrs.merge(id: "_#{UUIDTools::UUID.random_create}") xml.annex **attr_code(attrs1) do |xml_section| section_title(xml_section, node.title) attrs.delete(:anchor) 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
177 178 179 180 181 |
# File 'lib/metanorma/ogc/front.rb', line 177 def title(node, xml) super content = node.attr("abbrev") and add_title_xml(xml, content, @lang, "abbrev") end |
#title_key(bib) ⇒ Object
189 190 191 192 193 |
# File 'lib/metanorma/ogc/cleanup.rb', line 189 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
8 9 10 |
# File 'lib/metanorma/ogc/validate.rb', line 8 def title_validate(_root) nil end |
#toc(value) ⇒ Object
ignore, we generate ToC outside of asciidoctor
5 |
# File 'lib/metanorma/ogc/sections.rb', line 5 def toc(value); end |
#update_colors(node) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/metanorma/ogc/converter.rb', line 132 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 |
#version_validate(xmldoc) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/metanorma/ogc/validate.rb', line 45 def version_validate(xmldoc) version = xmldoc.at("//bibdata/edition")&.text if %w(engineering-report discussion-paper).include? @doctype version.nil? or @log.add("OGC_3", nil, params: [@doctype]) else version.nil? and @log.add("OGC_4", nil, params: [@doctype]) end end |