Class: IsoDoc::Ogc::PresentationXMLConvert

Inherits:
PresentationXMLConvert
  • Object
show all
Includes:
Init
Defined in:
lib/isodoc/ogc/presentation_sections.rb,
lib/isodoc/ogc/presentation_xml_convert.rb

Constant Summary collapse

UPDATE_RELATIONS =
<<~XPATH.freeze
  //bibdata/relation[@type = 'updatedBy' or @type = 'merges' or @type = 'splits' or @type = 'hasDraft']/bibitem
XPATH

Instance Method Summary collapse

Methods included from Init

#bibrenderer, #fileloc, #i18n_init, #metadata_init, #ogc_draft_ref?, #submittingorgs_path, #xref_init

Constructor Details

#initialize(options) ⇒ PresentationXMLConvert

Returns a new instance of PresentationXMLConvert.



8
9
10
11
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 8

def initialize(options)
  @libdir = File.dirname(__FILE__)
  super
end

Instance Method Details

#admits(elem) ⇒ Object



185
186
187
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 185

def admits(elem)
  elem << "&#xa0;<span class='AdmittedLabel'>#{@i18n.admitted}</span>"
end

#annex1(elem) ⇒ Object



90
91
92
93
94
95
# File 'lib/isodoc/ogc/presentation_sections.rb', line 90

def annex1(elem)
  lbl = @xrefs.anchor(elem["id"], :label)
  t = elem.at(ns("./title")) and
    t.children = "<strong>#{to_xml(t.children)}</strong>"
  prefix_name(elem, "<br/>", lbl, "title")
end

#annex_insert_point(docxml) ⇒ Object



48
49
50
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 48

def annex_insert_point(docxml)
  docxml.at(ns("//annex[last()]")) || docxml.at(ns("//sections"))
end

#bibdata(docxml) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 28

def bibdata(docxml)
  docxml.xpath(ns("//bibdata/contributor[@type = 'author']")).each do |a|
    a.at(ns("./description"))&.text == "contributor" and
      a["type"] = "contributor"
  end
  super
  dochistory_insert(docxml)
end

#bibdata_i18n(bib) ⇒ Object



118
119
120
121
122
123
124
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 118

def bibdata_i18n(bib)
  doctype = bib&.at(ns("./ext/doctype"))
  rename_stage(bib&.at(ns("./status/stage")), doctype, bib)
  rename_doctype(doctype, bib&.at(ns("./date[@type = 'published']")) ||
                 bib&.at(ns("./date[@type = 'issued']")))
  super
end

#biblio_ref_entry_code(ordinal, ids, _id, standard, datefn, _bib) ⇒ Object

if ids is just a number, only use that ([1] Non-Standard) else, use both ordinal, as prefix, and ids



175
176
177
178
179
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 175

def biblio_ref_entry_code(ordinal, ids, _id, standard, datefn, _bib)
  standard and return "[#{ordinal}]<tab/>"
  ret = ids[:ordinal] || ids[:metanorma] || "[#{ordinal}]"
  prefix_bracketed_ref("#{ret}#{datefn}")
end

#bibliography_bibitem_number_skip(bibitem) ⇒ Object



154
155
156
157
158
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 154

def bibliography_bibitem_number_skip(bibitem)
  @xrefs.klass.implicit_reference(bibitem) ||
    bibitem.at(ns(".//docidentifier[@type = 'metanorma-ordinal']")) ||
    bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
end

#bibrender_formattedref(formattedref, xml) ⇒ Object



160
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 160

def bibrender_formattedref(formattedref, xml); end

#bibrender_relaton(xml, renderings) ⇒ Object



162
163
164
165
166
167
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 162

def bibrender_relaton(xml, renderings)
  f = renderings[xml["id"]][:formattedref]
  f &&= "<formattedref>#{f}</formattedref>"
  keep = "./docidentifier | ./uri | ./note | ./status | ./biblio-tag"
  xml.children = "#{f}#{xml.xpath(ns(keep)).to_xml}"
end

#clause(docxml) ⇒ Object



97
98
99
100
101
102
# File 'lib/isodoc/ogc/presentation_sections.rb', line 97

def clause(docxml)
  super
  docxml.xpath(ns("//foreword | //preface/abstract | " \
                  "//submitters | //introduction | //acknowledgements"))
    .each { |f| clause1(f) }
end

#clause1(elem) ⇒ Object



104
105
106
107
108
109
# File 'lib/isodoc/ogc/presentation_sections.rb', line 104

def clause1(elem)
  elem.name == "terms" && elem.parent.name == "annex" &&
    elem.parent.xpath(ns("./terms")).size == 1 and return
  elem.name == "clause" && elem["type"] == "toc" and return
  super
end

#convert1(docxml, filename, dir) ⇒ Object



13
14
15
16
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 13

def convert1(docxml, filename, dir)
  info docxml, nil
  super
end

#deprecates(elem) ⇒ Object



181
182
183
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 181

def deprecates(elem)
  elem << "&#xa0;<span class='AdmittedLabel'>#{@i18n.deprecated}</span>"
end

#dochistory_contributor(contrib) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 88

def dochistory_contributor(contrib)
  ret = contrib.at("./organization/subdivision") ||
    contrib.at("./organization/name") ||
    contrib.at("./person/name/abbreviation") ||
    contrib.at("./person/name/completename")
  ret and return ret.text
  format_personalname(contrib)
end

#dochistory_contributors(item) ⇒ Object



82
83
84
85
86
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 82

def dochistory_contributors(item)
  item.xpath(ns("./contributor")).map do |c|
    dochistory_contributor(c)
  end.join(", ")
end

#dochistory_date(item) ⇒ Object



75
76
77
78
79
80
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 75

def dochistory_date(item)
  d = item.at(ns("./date[@type = 'updated']")) ||
    item.at(ns("./date[@type = 'published']")) ||
    item.at(ns("./date[@type = 'issued']")) or return ""
  d.text.strip
end

#dochistory_description(item) ⇒ Object



104
105
106
107
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 104

def dochistory_description(item)
  d = item.at(ns("./amend/description")) or return ""
  d.children.to_xml
end

#dochistory_insert(docxml) ⇒ Object



41
42
43
44
45
46
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 41

def dochistory_insert(docxml)
  updates = docxml.xpath(ns(UPDATE_RELATIONS))
  updates.empty? and return
  fwd = annex_insert_point(docxml)
  generate_dochistory(updates, fwd)
end

#dochistory_location(item) ⇒ Object



109
110
111
112
113
114
115
116
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 109

def dochistory_location(item)
  t = item.at(ns("./amend/location")) or return "All"
  xpath = "./amend/location/locality | ./amend/location/localityStack"
  r = eref_localities(item.xpath(ns(xpath)), nil, t)
  r.sub!(/^, /, "")
  r == @i18n.wholeoftext and r = "All"
  r
end

#example1(elem) ⇒ Object



22
23
24
25
26
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 22

def example1(elem)
  lbl = @xrefs.anchor(elem["id"], :label, false) or return
  prefix_name(elem, block_delim, l10n("#{@i18n.example} #{lbl}"),
              "name")
end

#format_personalname(contrib) ⇒ Object



97
98
99
100
101
102
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 97

def format_personalname(contrib)
  Relaton::Render::Ogc::General
    .new(template: { book: "{{ creatornames }}" })
    .render("<bibitem type='book'>#{contrib.to_xml}</bibitem>",
            embedded: true)
end

#generate_dochistory(updates, pref) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 52

def generate_dochistory(updates, pref)
  ret = updates.map { |u| generate_dochistory_row(u) }.flatten.join("\n")
  pref.next = <<~XML
    <annex id='_#{UUIDTools::UUID.random_create}' obligation='informative'>
    <title>#{@i18n.dochistory}</title>
    <table><thead>
    <tr><th>Date</th><th>Release</th><th>Author</th><th>Paragraph Modified</th><th>Description</th></tr>
    </thead><tbody>
    #{ret}
    </tbody></table></annex>
  XML
end

#generate_dochistory_row(item) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 65

def generate_dochistory_row(item)
  e = item.at(ns("./edition")) || item.at(ns("./version/draft"))
  date = dochistory_date(item)
  c = dochistory_contributors(item)
  l = dochistory_location(item)
  desc = dochistory_description(item)
  "<tr><td>#{date}</td><td>#{e&.text}</td><td>#{c}</td>" \
    "<td>#{l}</td><td>#{desc}</td></tr>"
end

#insert_keywords(docxml) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/isodoc/ogc/presentation_sections.rb', line 77

def insert_keywords(docxml)
  kw = @meta.get[:keywords]
  kw.empty? and return
  if abstract =
       docxml.at(ns("//preface/clause[@type = 'executivesummary']")) ||
       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(doc) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/isodoc/ogc/presentation_sections.rb', line 11

def insert_preface_sections(doc)
  preface_insert(doc.at(ns("//preface/clause" \
                           "[@type = 'executivesummary']")),
                 doc.at(ns("//preface/abstract")), doc)
  preface_insert(doc.at(ns("//preface//submitters")),
                 submit_orgs_append_pt(doc), doc)
  insert_submitting_orgs(doc)
  preface_insert(doc.at(ns("//preface/clause[@type = 'security']")),
                 submit_orgs_append_pt(doc), doc)
  insert_keywords(doc)
end

#insert_submitting_orgs(docxml) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/isodoc/ogc/presentation_sections.rb', line 46

def insert_submitting_orgs(docxml)
  orgs = docxml.xpath(ns(submittingorgs_path))
    .each_with_object([]) { |org, m| m << org.text }
  orgs.empty? and return
  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) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/isodoc/ogc/presentation_sections.rb', line 68

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

#middle_title(docxml) ⇒ Object



4
# File 'lib/isodoc/ogc/presentation_sections.rb', line 4

def middle_title(docxml); end

#norm_ref_entry_code(_ordinal, _idents, _ids, _standard, _datefn, _bib) ⇒ Object



169
170
171
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 169

def norm_ref_entry_code(_ordinal, _idents, _ids, _standard, _datefn, _bib)
  ""
end

#ol_depth(node) ⇒ Object



139
140
141
142
143
144
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 139

def ol_depth(node)
  node["class"] == "steps" ||
    node.at(".//ancestor::xmlns:ol[@class = 'steps']") or return super
  idx = node.xpath("./ancestor-or-self::xmlns:ol[@class = 'steps']").size
  %i(arabic alphabet roman alphabet_upper roman_upper)[(idx - 1) % 5]
end

#preface_init_insert_pt(docxml) ⇒ Object



23
24
25
26
27
# File 'lib/isodoc/ogc/presentation_sections.rb', line 23

def preface_init_insert_pt(docxml)
  docxml.at(ns("//preface")) ||
    docxml.at(ns("//sections"))
      .add_previous_sibling("<preface> </preface>").first
end

#preface_insert(clause, after, docxml) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/isodoc/ogc/presentation_sections.rb', line 29

def preface_insert(clause, after, docxml)
  clause or return
  clause.remove
  if after then after.next = clause
  else
    preface_init_insert_pt(docxml)&.children&.first
      &.add_previous_sibling(clause)
  end
end

#preface_rearrange(doc) ⇒ Object



6
7
8
9
# File 'lib/isodoc/ogc/presentation_sections.rb', line 6

def preface_rearrange(doc)
  super
  insert_preface_sections(doc)
end

#rename_doctype(doctype, date) ⇒ Object



133
134
135
136
137
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 133

def rename_doctype(doctype, date)
  (doctype&.text == "white-paper" && date) or return
  Date.iso8601(date.text) >= Date.iso8601("2021-12-16") and
    doctype.children = "technical-paper"
end

#rename_stage(stage, doctype, _bib) ⇒ Object



126
127
128
129
130
131
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 126

def rename_stage(stage, doctype, _bib)
  stage&.text == "approved" &&
    !%w(standard abstract-specification-topic draft-standard
        community-standard).include?(doctype&.text) and
    stage.children = "published"
end

#rouge_css_locationObject



18
19
20
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 18

def rouge_css_location
  File.read(File.join(@libdir, "html", "rouge.css"))
end

#submit_orgs_append_pt(docxml) ⇒ Object



39
40
41
42
43
44
# File 'lib/isodoc/ogc/presentation_sections.rb', line 39

def submit_orgs_append_pt(docxml)
  docxml.at(ns("//foreword")) ||
    docxml.at(ns("//preface/clause[@type = 'keywords']")) ||
    docxml.at(ns("//preface/clause[@type = 'executivesummary']")) ||
    docxml.at(ns("//preface/abstract"))
end

#submitting_orgs_clause(orgs) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/isodoc/ogc/presentation_sections.rb', line 58

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

#termsource1(elem) ⇒ Object



146
147
148
149
150
151
152
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 146

def termsource1(elem)
  while elem&.next_element&.name == "termsource"
    elem << "; #{to_xml(elem.next_element.remove.children)}"
  end
  elem.children = l10n("[<strong>#{@i18n.source}:</strong> " \
                       "#{to_xml(elem.children).strip}]")
end