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
-
#annex_delim(_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
-
#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
-
#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
-
#ol_label_template(_elem) ⇒ 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
def designation_boldface(desgn); end.
-
#submit_orgs_append_pt(docxml) ⇒ Object
-
#submitting_orgs_clause(orgs) ⇒ Object
-
#termsource_label(elem, sources) ⇒ Object
-
#ul_label_list(_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
170
171
172
173
174
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 170
def admits(elem)
elem.xpath(ns(".//semx[@element = 'admitted']")).each do |s|
s.next = " <span class='AdmittedLabel'>#{@i18n.admitted}</span>"
end
end
|
#annex_delim(_elem) ⇒ Object
99
100
101
|
# File 'lib/isodoc/ogc/presentation_sections.rb', line 99
def annex_delim(_elem)
"<br/>"
end
|
#annex_insert_point(docxml) ⇒ Object
43
44
45
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 43
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
30
|
# 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
dochistory_insert(docxml)
end
|
#bibdata_i18n(bib) ⇒ Object
111
112
113
114
115
116
117
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 111
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
158
159
160
161
162
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 158
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
144
145
146
147
148
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 144
def bibliography_bibitem_number_skip(bibitem)
implicit_reference(bibitem) ||
bibitem.at(ns(".//docidentifier[@type = 'metanorma-ordinal']")) ||
bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
end
|
150
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 150
def bibrender_formattedref(formattedref, xml); end
|
#clause1(elem) ⇒ Object
103
104
105
106
107
108
|
# File 'lib/isodoc/ogc/presentation_sections.rb', line 103
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
164
165
166
167
168
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 164
def deprecates(elem)
elem.xpath(ns(".//semx[@element = 'deprecates']")).each do |s|
s.next = " <span class='DeprecatedLabel'>#{@i18n.deprecated}</span>"
end
end
|
#dochistory_contributor(contrib) ⇒ Object
81
82
83
84
85
86
87
88
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 81
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
75
76
77
78
79
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 75
def dochistory_contributors(item)
item.xpath(ns("./contributor")).map do |c|
dochistory_contributor(c)
end.join(", ")
end
|
#dochistory_date(item) ⇒ Object
68
69
70
71
72
73
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 68
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
97
98
99
100
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 97
def dochistory_description(item)
d = item.at(ns("./amend/description")) or return ""
d.children.to_xml
end
|
#dochistory_insert(docxml) ⇒ Object
36
37
38
39
40
41
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 36
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
102
103
104
105
106
107
108
109
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 102
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
|
90
91
92
93
94
95
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 90
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
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 47
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
58
59
60
61
62
63
64
65
66
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 58
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
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/isodoc/ogc/presentation_sections.rb', line 86
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
23
24
25
26
27
28
29
30
|
# File 'lib/isodoc/ogc/presentation_sections.rb', line 23
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
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/isodoc/ogc/presentation_sections.rb', line 55
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
77
78
79
80
81
82
83
84
|
# File 'lib/isodoc/ogc/presentation_sections.rb', line 77
def keyword_clause(kwords)
<<~KEYWORDS
<clause id="_#{UUIDTools::UUID.random_create}" type="keywords">
<title>Keywords</fmt>
<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
152
153
154
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 152
def norm_ref_entry_code(_ordinal, _idents, _ids, _standard, _datefn, _bib)
""
end
|
#note_delim(_elem) ⇒ Object
199
200
201
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 199
def note_delim(_elem)
":<tab/>"
end
|
#ogc_draft_ref?(ref) ⇒ Boolean
210
211
212
213
214
215
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 210
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
132
133
134
135
136
137
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 132
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
223
224
225
226
227
228
229
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 223
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
32
33
34
35
36
|
# File 'lib/isodoc/ogc/presentation_sections.rb', line 32
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
38
39
40
41
42
43
44
45
46
|
# File 'lib/isodoc/ogc/presentation_sections.rb', line 38
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
203
204
205
206
207
208
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 203
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
186
187
188
189
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 186
def references(docxml)
unnumber_biblio(docxml)
super
end
|
#rename_doctype(doctype, date) ⇒ Object
126
127
128
129
130
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 126
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
119
120
121
122
123
124
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 119
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
def designation_boldface(desgn); end
178
179
180
181
182
183
184
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 178
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
48
49
50
51
52
53
|
# File 'lib/isodoc/ogc/presentation_sections.rb', line 48
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
67
68
69
70
71
72
73
74
75
|
# File 'lib/isodoc/ogc/presentation_sections.rb', line 67
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
|
#termsource_label(elem, sources) ⇒ Object
139
140
141
142
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 139
def termsource_label(elem, sources)
elem.replace(l10n("[<strong>#{@i18n.source}:</strong> " \
"#{sources}]"))
end
|
#ul_label_list(_elem) ⇒ Object
217
218
219
220
221
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 217
def ul_label_list(_elem)
if @doctype == "white-paper" then %w(—)
else %w(•)
end
end
|
#unnumber_biblio(docxml) ⇒ Object
prevent Eng Rept Biblio, which appears before Annexes, being numbered needs to happen before xrefs first invoked
193
194
195
196
197
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 193
def unnumber_biblio(docxml)
@doctype == "engineering-report" or return
b = docxml.at(ns(@xrefs.klass.bibliography_xpath)) or return
b["unnumbered"] = true
end
|