class IsoDoc::Ogc::PresentationXMLConvert
Public Instance Methods
annex1(elem)
click to toggle source
# File lib/isodoc/ogc/presentation_xml_convert.rb, line 133 def annex1(elem) lbl = @xrefs.anchor(elem["id"], :label) if t = elem.at(ns("./title")) t.children = "<strong>#{t.children.to_xml}</strong>" end prefix_name(elem, "<br/>", lbl, "title") end
block(docxml)
click to toggle source
Calls superclass method
# File lib/isodoc/ogc/presentation_xml_convert.rb, line 157 def block(docxml) super recommendation_to_table(docxml) end
clause(docxml)
click to toggle source
Calls superclass method
# File lib/isodoc/ogc/presentation_xml_convert.rb, line 141 def clause(docxml) super docxml.xpath(ns("//foreword | //preface/abstract | "\ "//submitters | //introduction | //acknowledgements")) .each do |f| clause1(f) end end
clause1(elem)
click to toggle source
Calls superclass method
# File lib/isodoc/ogc/presentation_xml_convert.rb, line 150 def clause1(elem) return if elem.name == "terms" && elem.parent.name == "annex" && elem.parent.xpath(ns("./terms")).size == 1 super end
convert1(docxml, filename, dir)
click to toggle source
Calls superclass method
# File lib/isodoc/ogc/presentation_xml_convert.rb, line 9 def convert1(docxml, filename, dir) info docxml, nil insert_preface_sections(docxml) super end
example1(elem)
click to toggle source
# File lib/isodoc/ogc/presentation_xml_convert.rb, line 92 def example1(elem) lbl = @xrefs.anchor(elem["id"], :label, false) or return prefix_name(elem, " — ", l10n("#{@i18n.example} #{lbl}"), "name") end
inject_crossreference_reqt?(node, label)
click to toggle source
embedded reqts xref to top level reqts via label lookup
# File lib/isodoc/ogc/presentation_xml_convert.rb, line 113 def inject_crossreference_reqt?(node, label) !node.ancestors("requirement, recommendation, permission").empty? && @xrefs.reqtlabels[label] end
insert_keywords(docxml)
click to toggle source
# File lib/isodoc/ogc/presentation_xml_convert.rb, line 81 def insert_keywords(docxml) kw = @meta.get[:keywords] kw.empty? and return if abstract = docxml.at(ns("//preface/abstract")) abstract.next = keyword_clause(kw) else preface_init_insert_pt(docxml)&.children&.first &.add_previous_sibling(keyword_clause(kw)) end end
insert_preface_sections(docxml)
click to toggle source
# File lib/isodoc/ogc/presentation_xml_convert.rb, line 15 def insert_preface_sections(docxml) insert_keywords(docxml) insert_submitting_orgs(docxml) insert_security(docxml) end
insert_security(docxml)
click to toggle source
# File lib/isodoc/ogc/presentation_xml_convert.rb, line 34 def insert_security(docxml) s = docxml&.at(ns("//preface/clause[@type = 'security']"))&.remove or return if a = submit_orgs_append_pt(docxml) a.next = s else preface_init_insert_pt(docxml)&.children&.first &.add_previous_sibling(s) end end
insert_submitting_orgs(docxml)
click to toggle source
# File lib/isodoc/ogc/presentation_xml_convert.rb, line 45 def insert_submitting_orgs(docxml) orgs = docxml.xpath(ns(submittingorgs_path)) .each_with_object([]) do |org, m| m << org.text end return if orgs.empty? if a = submit_orgs_append_pt(docxml) a.next = submitting_orgs_clause(orgs) else preface_init_insert_pt(docxml)&.children&.first &.add_previous_sibling(submitting_orgs_clause(orgs)) end end
keyword_clause(kwords)
click to toggle source
# File lib/isodoc/ogc/presentation_xml_convert.rb, line 71 def keyword_clause(kwords) <<~KEYWORDS <clause id="_#{UUIDTools::UUID.random_create}" type="keywords"> <title>Keywords</title> <p>The following are keywords to be used by search engines and document catalogues.</p> <p>#{kwords.join(', ')}</p></clause> KEYWORDS end
preface_init_insert_pt(docxml)
click to toggle source
# File lib/isodoc/ogc/presentation_xml_convert.rb, line 21 def preface_init_insert_pt(docxml) docxml.at(ns("//preface")) || docxml.at(ns("//sections")) .add_previous_sibling("<preface> </preface>").first end
preserve_in_nested_table?(node)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 114 def preserve_in_nested_table?(node) return true if %w(recommendation requirement permission table).include?(node.name) false end
rec_subj(node)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 90 def rec_subj(node) case node["type_original"] when "class" then "Target type" when "conformanceclass" then "Requirements class" when "verification", "abstracttest" then "Requirement" else "Subject" end end
recommend_class(node)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 7 def recommend_class(node) return "recommendtest" if node["type"] == "verification" return "recommendtest" if node["type"] == "abstracttest" return "recommendclass" if node["type"] == "class" return "recommendclass" if node["type"] == "conformanceclass" "recommend" end
recommend_class?(node)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 16 def recommend_class?(node) %w(recommendtest recommendclass recommend).include? node["type"] end
recommend_title(node, out)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 45 def recommend_title(node, out) label = node&.at(ns("./label"))&.remove or return label.xpath(ns(".//xref | .//eref | .//quote/source")) .each { |f| xref1(f) } label.xpath(ns(".//concept")).each { |f| concept1(f) } b = out.add_child("<tr><td colspan='2'><p></p></td></tr>") p = b.at(ns(".//p")) p << label.text end
recommendation1(elem, _type)
click to toggle source
# File lib/isodoc/ogc/presentation_xml_convert.rb, line 98 def recommendation1(elem, _type) type = recommendation_class_label(elem) label = elem&.at(ns("./label"))&.text if inject_crossreference_reqt?(elem, label) n = @xrefs.anchor(@xrefs.reqtlabels[label], :xref, false) lbl = (n.nil? ? type : n) elem&.at(ns("./title"))&.remove # suppress from display if embedded else n = @xrefs.anchor(elem["id"], :label, false) lbl = (n.nil? ? type : l10n("#{type} #{n}")) end prefix_name(elem, "", lbl, "name") end
recommendation_attr_keyvalue(node, key, value)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 99 def recommendation_attr_keyvalue(node, key, value) tag = node&.at(ns("./#{key}"))&.remove value = node.at(ns("./#{value}"))&.remove tag && value or return nil node.remove [tag.text.capitalize, value.children] end
recommendation_attributes(node, out)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 107 def recommendation_attributes(node, out) recommend_title(node, out) recommendation_attributes1(node).each do |i| out.add_child("<tr><td>#{i[0]}</td><td>#{i[1]}</td></tr>") end end
recommendation_attributes1(node)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 55 def recommendation_attributes1(node) out = recommendation_attributes1_head(node, []) node.xpath(ns("./classification")).each do |c| line = recommendation_attr_keyvalue(c, "tag", "value") and out << line end out end
recommendation_attributes1_component(node, out)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 85 def recommendation_attributes1_component(node, out) node = recommendation_steps(node) out << "<tr><td>#{node['label']}</td><td>#{node.children}</td></tr>" end
recommendation_attributes1_head(node, out)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 63 def recommendation_attributes1_head(node, out) oblig = node["obligation"] and out << ["Obligation", oblig] subj = node&.at(ns("./subject"))&.remove&.children and out << [rec_subj(node), subj] node.xpath(ns("./inherit")).each do |i| out << ["Dependency", i.remove.children] end out end
recommendation_base(node, klass)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 145 def recommendation_base(node, klass) node.name = "table" node["class"] = klass node["type_original"] = node["type"] node["type"] = recommend_class(node) recommendation_component_labels(node) end
recommendation_class(node)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 20 def recommendation_class(node) if node["type"] == "recommendtest" "RecommendationTestTitle" else "RecommendationTitle" end end
recommendation_class_label(node)
click to toggle source
# File lib/isodoc/ogc/presentation_xml_convert.rb, line 118 def recommendation_class_label(node) case node["type"] when "verification" then @i18n.get["#{node.name}test"] when "class" then @i18n.get["#{node.name}class"] when "abstracttest" then @i18n.get["abstracttest"] when "conformanceclass" then @i18n.get["conformanceclass"] else case node.name when "recommendation" then @i18n.recommendation when "requirement" then @i18n.requirement when "permission" then @i18n.permission end end end
recommendation_component_labels(node)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 153 def recommendation_component_labels(node) node.xpath(ns("./component[@class = 'part']")).each_with_index do |c, i| c["label"] = (i + "A".ord).chr.to_s end node.xpath(ns("./component[not(@class = 'part')]")).each do |c| c["label"] = case c["class"] when "test-purpose" then "Test purpose" when "test-method" then "Test method" else Metanorma::Utils.strict_capitalize_first(c["class"]) end end end
recommendation_header(recommend)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 28 def recommendation_header(recommend) h = recommend.add_child("<thead><tr><th scope='colgroup' colspan='2'>"\ "</th></tr></thead>") recommendation_name(recommend, h.at(ns(".//th"))) end
recommendation_name(node, out)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 34 def recommendation_name(node, out) b = out.add_child("<p class='#{recommendation_class(node)}'></p>").first if name = node&.at(ns("./name"))&.remove name.children.each { |n| b << n } end if title = node&.at(ns("./title"))&.remove b << l10n(": ") if name title.children.each { |n| b << n } end end
recommendation_parse1(node, klass)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 166 def recommendation_parse1(node, klass) recommendation_base(node, klass) recommendation_header(node) b = node.add_child("<tbody></tbody>").first recommendation_attributes(node, b) node.elements.reject do |n| %w(thead tbody classification subject inherit).include?(n.name) end.each { |n| requirement_component_parse(n, b) } node.delete("type_original") end
recommendation_steps(node)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 73 def recommendation_steps(node) node.elements.each { |e| recommendation_steps(e) } return node unless node.at(ns("./component[@class = 'step']")) d = node.at(ns("./component[@class = 'step']")) d = d.replace("<ol><li>#{d.children.to_xml}</li></ol>").first node.xpath(ns("./component[@class = 'step']")).each do |f| f = f.replace("<li>#{f.children.to_xml}</li>").first d << f end end
recommendation_to_table(docxml)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 178 def recommendation_to_table(docxml) docxml.xpath(ns("//recommendation")).each do |r| recommendation_parse1(r, "recommendation") end docxml.xpath(ns("//requirement")).each do |r| recommendation_parse1(r, "requirement") end docxml.xpath(ns("//permission")).each do |r| recommendation_parse1(r, "permission") end requirement_table_cleanup(docxml) end
references(docxml)
click to toggle source
Calls superclass method
# File lib/isodoc/ogc/presentation_xml_convert.rb, line 167 def references(docxml) super docxml.xpath(ns("//bibitem/date")).each do |d| d.xpath(ns("./on | ./from | ./to")).each do |d1| d1.children = d1.text.sub(/^(\d\d\d\d).*$/, "\\1") end end end
reqt_dl(node, out)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 134 def reqt_dl(node, out) node.xpath(ns("./dt")).each do |dt| dd = dt&.next_element dt.remove dd&.name == "dd" or next b = out.add_child("<tr><td></td><td></td></tr>") b.at(ns(".//td[1]")) << dt.children b.at(ns(".//td[2]")) << dd.remove.children end end
requirement_component_parse(node, out)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 121 def requirement_component_parse(node, out) node.remove return if node["exclude"] == "true" node.elements.size == 1 && node.first_element_child.name == "dl" and return reqt_dl(node.first_element_child, out) node.name == "component" and return recommendation_attributes1_component(node, out) b = out.add_child("<tr><td colspan='2'></td></tr>").first b.at(ns(".//td")) << (preserve_in_nested_table?(node) ? node : node.children) end
requirement_table_cleanup(docxml)
click to toggle source
# File lib/isodoc/ogc/reqt.rb, line 204 def requirement_table_cleanup(docxml) docxml.xpath(ns("//table[@type = 'recommendclass']/tbody/tr/td/table")) .each do |t| t.xpath(ns("./thead | ./tbody |./tfoot")).each do |x| x.replace(x.children) end (x = t.at(ns("./tr/th[@colspan = '2']"))) && (y = t.at(ns("./tr/td[@colspan = '2']"))) and requirement_table_cleanup1(x, y) t.parent.parent.replace(t.children) end end
requirement_table_cleanup1(outer, inner)
click to toggle source
table nested in table: merge label and caption into a single row
# File lib/isodoc/ogc/reqt.rb, line 192 def requirement_table_cleanup1(outer, inner) outer.delete("colspan") outer.delete("scope") inner.delete("colspan") inner.delete("scope") outer.name = "td" p = outer.at(ns("./p[@class = 'RecommendationTitle']")) and p.delete("class") outer.parent << inner.dup inner.parent.remove end
section(docxml)
click to toggle source
Calls superclass method
# File lib/isodoc/ogc/presentation_xml_convert.rb, line 162 def section(docxml) super references(docxml) end
submit_orgs_append_pt(docxml)
click to toggle source
# File lib/isodoc/ogc/presentation_xml_convert.rb, line 27 def submit_orgs_append_pt(docxml) docxml.at(ns("//introduction")) || docxml.at(ns("//foreword")) || docxml.at(ns("//preface/clause[@type = 'keywords']")) || docxml.at(ns("//preface/abstract")) end
submitting_orgs_clause(orgs)
click to toggle source
# File lib/isodoc/ogc/presentation_xml_convert.rb, line 60 def submitting_orgs_clause(orgs) <<~SUBMITTING <clause id="_#{UUIDTools::UUID.random_create}" type="submitting_orgs"> <title>Submitting Organizations</title> <p>The following organizations submitted this Document to the Open Geospatial Consortium (OGC):</p> <ul>#{orgs.map { |m| "<li>#{m}</li>" }.join("\n")}</ul> </clause> SUBMITTING end