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, #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



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

def admits(elem)
  elem.xpath(ns(".//semx[@element = 'admitted']")).each do |s|
    s.next = "&#xa0;<span class='AdmittedLabel'>#{@i18n.admitted}</span>"
  end
end

#annex_delim(_elem) ⇒ Object



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

def annex_delim(_elem)
  "<br/>"
end

#annex_insert_point(docxml) ⇒ Object



46
47
48
# File 'lib/isodoc/ogc/presentation_sections.rb', line 46

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

#bibdata(docxml) ⇒ Object



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

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
end

#bibdata_i18n(bib) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 35

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
  bibdata_logos(bib)
end

#bibdata_logos(bibdata) ⇒ Object



44
45
46
47
48
49
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 44

def bibdata_logos(bibdata)
  ogc = bibdata.at(ns("./contributor[role/@type = 'publisher']/" \
                      "organization[abbreviation = 'OGC']")) or return
  date = bibdata.document.at(ns("//presentation-metadata/document-scheme"))
  ogc << logo_select(date&.text)
end

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

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



113
114
115
116
117
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 113

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

#bibliography_bibitem_number_skip(bibitem) ⇒ Object



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

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

#bibrender_formattedref(formattedref, xml) ⇒ Object



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

def bibrender_formattedref(formattedref, xml); end

#clause1(elem) ⇒ Object



189
190
191
192
193
194
# File 'lib/isodoc/ogc/presentation_sections.rb', line 189

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
17
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 13

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

#deprecates(elem) ⇒ Object



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

def deprecates(elem)
  elem.xpath(ns(".//semx[@element = 'deprecates']")).each do |s|
    s.next = "&#xa0;<span class='DeprecatedLabel'>#{@i18n.deprecated}</span>"
  end
end

#dochistory_contributor(contrib) ⇒ Object



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

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



81
82
83
84
85
# File 'lib/isodoc/ogc/presentation_sections.rb', line 81

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

#dochistory_date(item) ⇒ Object



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

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



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

def dochistory_description(item)
  d = item.xpath(ns("./amend/description"))
  d.empty? and return ""
  d.map { |d1| semx_fmt_dup(d1).to_xml }.join("\n")
end

#dochistory_insert(docxml) ⇒ Object



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

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_sections.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

#format_personalname(contrib) ⇒ Object



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

def format_personalname(contrib)
  ret = Relaton::Render::Ogc::General
    .new(template: { book: "{{ creatornames }}" })
    .render_all("<references><bibitem type='book'>#{contrib.to_xml}</bibitem></references>")
  ret[nil][:citation][:author]
end

#generate_dochistory(updates, pref) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/isodoc/ogc/presentation_sections.rb', line 50

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

#generate_dochistory_row(item) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/isodoc/ogc/presentation_sections.rb', line 62

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)
  <<~XML
    <tr #{add_id_text}><td #{add_id_text}>#{date}</td><td #{add_id_text}>#{e&.text}</td><td #{add_id_text}>#{c}</td>
      <td #{add_id_text}>#{l}</td><td #{add_id_text}>#{desc}</td></tr>
  XML
end

#insert_keywords(docxml) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/isodoc/ogc/presentation_sections.rb', line 172

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



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

def insert_preface_sections(doc)
  preface_insert(doc.at(ns("//preface//clause[@type = 'submitters' or " \
                           "@type = 'contributors']")),
                 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



141
142
143
144
145
146
147
148
149
150
151
# File 'lib/isodoc/ogc/presentation_sections.rb', line 141

def insert_submitting_orgs(docxml)
  orgs = docxml.xpath(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



163
164
165
166
167
168
169
170
# File 'lib/isodoc/ogc/presentation_sections.rb', line 163

def keyword_clause(kwords)
  <<~KEYWORDS
    <clause #{add_id_text} type="keywords">
    <title #{add_id_text}>Keywords</title>
    <p>The following are keywords to be used by search engines and document catalogues.</p>
    <p>#{kwords.join(', ')}</p></clause>
  KEYWORDS
end

#logo_select(date) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 51

def logo_select(date)
  case date
  when "2018"
    <<~XML
      <logo type="html-blue"><image src="#{File.join(@libdir, 'html', 'logo.2018.png')}" mimetype="image/png"/></logo>
      <logo type="html-white"><image src="#{File.join(@libdir, 'html', 'logo.2018-white.png')}" mimetype="image/png"/></logo>
      <logo type="word"><image src="#{File.join(@libdir, 'html', 'logo.2018.png')}" mimetype="image/png"/></logo>
    XML
  when "2022"
    <<~XML
      <logo type="html-blue"><image src="" mimetype="image/svg+xml">#{svg_load('', 'logo.2021.svg')}</image></logo>
      <logo type="html-white"><image src="" mimetype="image/svg+xml">#{svg_load('', 'logo.2021-white.svg')}</image></logo>
      <logo type="word"><image src="#{File.join(@libdir, 'html', 'logo.2021.png')}" mimetype="image/png"/></logo>
    XML
  else # "2026"
    <<~XML
      <logo type="html-blue"><image src="" mimetype="image/svg+xml">#{svg_load(%w(Logos_2026 1_Blue_Logos), 'OGC-new-logo.svg')}</image></logo>
      <logo type="html-white"><image src="" mimetype="image/svg+xml">#{svg_load(%w(Logos_2026 3_Reverse_Logos), 'OGC-new-logo-white.svg')}</image></logo>
      <logo type="word"><image src="#{File.join(@libdir, 'html', 'Logos_2026', '1_Blue_Logos', 'OGC-new-logo.png')}" mimetype="image/png"/></logo>
    XML
  end
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, _standard, _datefn, _bib) ⇒ Object



107
108
109
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 107

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

#note_delim(_elem) ⇒ Object



152
153
154
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 152

def note_delim(_elem)
  ":<tab/>"
end

#ogc_draft_ref?(ref) ⇒ Boolean

Returns:

  • (Boolean)


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

def ogc_draft_ref?(ref)
  ref.at(ns("./docidentifier[@type = 'OGC']")) or return false
  status = ref.at(ns("./status/stage"))&.text or return false
  !%w(approved published deprecated retired).include?(status)
end

#ol_depth(node) ⇒ Object



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

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

#ol_label_template(_elem) ⇒ Object



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

def ol_label_template(_elem)
  super
    .merge({
             alphabet_upper: %{%<span class="fmt-label-delim">)</span>},
             arabic: %{%<span class="fmt-label-delim">.</span>},
           })
end

#preface_init_insert_pt(docxml) ⇒ Object



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

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



124
125
126
127
128
129
130
131
132
# File 'lib/isodoc/ogc/presentation_sections.rb', line 124

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
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/isodoc/ogc/presentation_sections.rb', line 6

def preface_rearrange(doc)
  [
    ["//preface/abstract",
     %w(executivesummary foreword introduction clause acknowledgements)],
    ["//preface/executivesummary",
     %w(foreword introduction clause acknowledgements)],
    ["//preface/foreword",
     %w(introduction clause acknowledgements)],
    ["//preface/introduction",
     %w(clause acknowledgements)],
    ["//preface/acknowledgements", %w()],
  ].each do |x|
    preface_move(doc.xpath(ns(x[0])), x[1], doc)
  end
  insert_preface_sections(doc)
end

#reference_name(ref) ⇒ Object



156
157
158
159
160
161
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 156

def reference_name(ref)
  super
  ogc_draft_ref?(ref) or return
  @xrefs.get[ref["id"]] =
    { xref: "#{@xrefs.get[ref['id']][:xref]} (draft)" }
end

#references(docxml) ⇒ Object



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

def references(docxml)
  unnumber_biblio(docxml)
  super
end

#rename_doctype(doctype, date) ⇒ Object



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

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



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

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



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

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

#section(docxml) ⇒ Object



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

def section(docxml)
  dochistory_insert(docxml)
  @xrefs.parse docxml
  super
end

#source_label(elem) ⇒ Object



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

def source_label(elem)
  labelled_ancestor(elem) and return
  n = @xrefs.get[elem["id"]]
  lbl = labelled_autonum(lower2cap(@i18n.sourcecode), elem["id"],
                         n&.dig(:label))
  prefix_name(elem, { caption: block_delim }, lbl, "name")
end

#submit_orgs_append_pt(docxml) ⇒ Object



134
135
136
137
138
139
# File 'lib/isodoc/ogc/presentation_sections.rb', line 134

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

#submitting_orgs_clause(orgs) ⇒ Object



153
154
155
156
157
158
159
160
161
# File 'lib/isodoc/ogc/presentation_sections.rb', line 153

def submitting_orgs_clause(orgs)
  <<~SUBMITTING
    <clause #{add_id_text} type="submitting_orgs">
    <title #{add_id_text}>Submitting Organizations</title>
    <p>The following organizations submitted this Document to the Open Geospatial Consortium (OGC):</p>
     <ul #{add_id_text}>#{orgs.map { |m| "<li #{add_id_text}>#{m}</li>" }.join("\n")}</ul>
     </clause>
  SUBMITTING
end

#termsource_label(elem, sources) ⇒ Object



94
95
96
97
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 94

def termsource_label(elem, sources)
  elem.replace(l10n("[<strong>#{@i18n.source}:</strong> " \
                    "#{sources}]"))
end

#ul_label_list(_elem) ⇒ Object



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

def ul_label_list(_elem)
  if @doctype == "white-paper" then %w(&#x2014;)
  else %w(&#x2022;)
  end
end

#unnumber_biblio(docxml) ⇒ Object

prevent Eng Rept Biblio, which appears before Annexes, being numbered needs to happen before xrefs first invoked



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

def unnumber_biblio(docxml)
  @doctype == "engineering-report" or return
  b = docxml.at(ns(@xrefs.klass.bibliography_xpath)) or return
  b["unnumbered"] = true
end