Class: IsoDoc::Ogc::PresentationXMLConvert
- Inherits:
-
PresentationXMLConvert
- Object
- PresentationXMLConvert
- IsoDoc::Ogc::PresentationXMLConvert
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
-
#admits(elem) ⇒ Object
-
#annex1(elem) ⇒ Object
-
#annex_insert_point(docxml) ⇒ Object
-
#bibdata(docxml) ⇒ Object
-
#bibdata_i18n(bib) ⇒ Object
-
#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.
-
#bibliography_bibitem_number_skip(bibitem) ⇒ Object
-
#bibrender_formattedref(formattedref, xml) ⇒ Object
-
#bibrender_relaton(xml, renderings) ⇒ Object
-
#clause(docxml) ⇒ Object
-
#clause1(elem) ⇒ Object
-
#convert1(docxml, filename, dir) ⇒ Object
-
#deprecates(elem) ⇒ Object
-
#dochistory_contributor(contrib) ⇒ Object
-
#dochistory_contributors(item) ⇒ Object
-
#dochistory_date(item) ⇒ Object
-
#dochistory_description(item) ⇒ Object
-
#dochistory_insert(docxml) ⇒ Object
-
#dochistory_location(item) ⇒ Object
-
#example1(elem) ⇒ Object
-
#format_personalname(contrib) ⇒ Object
-
#generate_dochistory(updates, pref) ⇒ Object
-
#generate_dochistory_row(item) ⇒ Object
-
#initialize(options) ⇒ PresentationXMLConvert
constructor
A new instance of PresentationXMLConvert.
-
#insert_keywords(docxml) ⇒ Object
-
#insert_preface_sections(doc) ⇒ Object
-
#insert_submitting_orgs(docxml) ⇒ Object
-
#keyword_clause(kwords) ⇒ Object
-
#middle_title(docxml) ⇒ Object
-
#norm_ref_entry_code(_ordinal, _idents, _ids, _standard, _datefn, _bib) ⇒ Object
-
#note_delim(_elem) ⇒ Object
-
#ogc_draft_ref?(ref) ⇒ Boolean
-
#ol_depth(node) ⇒ Object
-
#preface_init_insert_pt(docxml) ⇒ Object
-
#preface_insert(clause, after, docxml) ⇒ Object
-
#preface_rearrange(doc) ⇒ Object
-
#reference_name(ref) ⇒ Object
-
#references(docxml) ⇒ Object
-
#rename_doctype(doctype, date) ⇒ Object
-
#rename_stage(stage, doctype, _bib) ⇒ Object
-
#rouge_css_location ⇒ Object
-
#source_label(elem) ⇒ Object
-
#submit_orgs_append_pt(docxml) ⇒ Object
-
#submitting_orgs_clause(orgs) ⇒ Object
-
#termsource1(elem) ⇒ Object
-
#unnumber_biblio(docxml) ⇒ Object
prevent Eng Rept Biblio, which appears before Annexes, being numbered needs to happen before xrefs first invoked.
Methods included from Init
#bibrenderer, #fileloc, #i18n_init, #metadata_init, #submittingorgs_path, #xref_init
Constructor Details
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
186
187
188
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 186
def admits(elem)
elem << " <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
49
50
51
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 49
def annex_insert_point(docxml)
docxml.at(ns("//annex[last()]")) || docxml.at(ns("//sections"))
end
|
#bibdata(docxml) ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 29
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
119
120
121
122
123
124
125
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 119
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
176
177
178
179
180
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 176
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
155
156
157
158
159
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 155
def bibliography_bibitem_number_skip(bibitem)
implicit_reference(bibitem) ||
bibitem.at(ns(".//docidentifier[@type = 'metanorma-ordinal']")) ||
bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
end
|
161
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 161
def bibrender_formattedref(formattedref, xml); end
|
#bibrender_relaton(xml, renderings) ⇒ Object
163
164
165
166
167
168
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 163
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
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
182
183
184
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 182
def deprecates(elem)
elem << " <span class='DeprecatedLabel'>#{@i18n.deprecated}</span>"
end
|
#dochistory_contributor(contrib) ⇒ Object
89
90
91
92
93
94
95
96
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 89
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
83
84
85
86
87
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 83
def dochistory_contributors(item)
item.xpath(ns("./contributor")).map do |c|
dochistory_contributor(c)
end.join(", ")
end
|
#dochistory_date(item) ⇒ Object
76
77
78
79
80
81
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 76
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
105
106
107
108
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 105
def dochistory_description(item)
d = item.at(ns("./amend/description")) or return ""
d.children.to_xml
end
|
#dochistory_insert(docxml) ⇒ Object
42
43
44
45
46
47
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 42
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
110
111
112
113
114
115
116
117
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 110
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
23
24
25
26
27
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 23
def example1(elem)
lbl = @xrefs.anchor(elem["id"], :label, false) or return
prefix_name(elem, block_delim, l10n("#{@i18n.example} #{lbl}"),
"name")
end
|
98
99
100
101
102
103
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 98
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
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 53
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
66
67
68
69
70
71
72
73
74
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 66
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
170
171
172
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 170
def norm_ref_entry_code(_ordinal, _idents, _ids, _standard, _datefn, _bib)
""
end
|
#note_delim(_elem) ⇒ Object
210
211
212
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 210
def note_delim(_elem)
":<tab/>"
end
|
#ogc_draft_ref?(ref) ⇒ Boolean
221
222
223
224
225
226
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 221
def ogc_draft_ref?(ref)
ref.at(ns("./docidentifier[@type = 'OGC']")) or return
status = ref.at(ns("./status/stage"))&.text or return
%w(approved published deprecated retired).include? status and return
true
end
|
#ol_depth(node) ⇒ Object
140
141
142
143
144
145
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 140
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
|
#reference_name(ref) ⇒ Object
214
215
216
217
218
219
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 214
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
197
198
199
200
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 197
def references(docxml)
unnumber_biblio(docxml)
super
end
|
#rename_doctype(doctype, date) ⇒ Object
134
135
136
137
138
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 134
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
127
128
129
130
131
132
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 127
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_location ⇒ Object
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
|
#source_label(elem) ⇒ Object
190
191
192
193
194
195
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 190
def source_label(elem)
labelled_ancestor(elem) and return
lbl = @xrefs.anchor(elem["id"], :label, false) or return
prefix_name(elem, block_delim,
l10n("#{lower2cap @i18n.sourcecode} #{lbl}"), "name")
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
147
148
149
150
151
152
153
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 147
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
|
#unnumber_biblio(docxml) ⇒ Object
prevent Eng Rept Biblio, which appears before Annexes, being numbered needs to happen before xrefs first invoked
204
205
206
207
208
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 204
def unnumber_biblio(docxml)
@doctype == "engineering-report" or return
b = docxml.at(ns(@xrefs.klass.bibliography_xpath)) or return
b["unnumbered"] = true
end
|