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 =
"//bibdata/relation[@type = 'updatedBy' or @type = 'merges' or @type = 'splits' or @type = 'hasDraft']/bibitem\n".freeze
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
-
#section(docxml) ⇒ 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
94
95
96
97
98
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 94
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
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
|
# 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
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
82
83
84
85
86
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 82
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
68
69
70
71
72
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 68
def bibliography_bibitem_number_skip(bibitem)
implicit_reference(bibitem) ||
bibitem.at(ns(".//docidentifier[@type = 'metanorma-ordinal']")) ||
bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
end
|
74
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 74
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
88
89
90
91
92
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 88
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
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
|
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 = " <annex \#{add_id_text} obligation='informative'>\n <title \#{add_id_text}>\#{@i18n.dochistory}</title>\n <table unnumbered=\"true\" \#{add_id_text}><thead>\n <tr \#{add_id_text}><th \#{add_id_text}>Date</th><th \#{add_id_text}>Release</th><th \#{add_id_text}>Author</th>\n <th \#{add_id_text}>Paragraph Modified</th><th \#{add_id_text}>Description</th></tr>\n </thead><tbody>\#{ret}</tbody></table></annex>\n XML\nend\n"
|
#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)
" <tr \#{add_id_text}><td \#{add_id_text}>\#{date}</td><td \#{add_id_text}>\#{e&.text}</td><td \#{add_id_text}>\#{c}</td>\n <td \#{add_id_text}>\#{l}</td><td \#{add_id_text}>\#{desc}</td></tr>\n XML\nend\n"
|
#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)
" <clause \#{add_id_text} type=\"keywords\">\n <title \#{add_id_text}>Keywords</title>\n <p>The following are keywords to be used by search engines and document catalogues.</p>\n <p>\#{kwords.join(', ')}</p></clause>\n KEYWORDS\nend\n"
|
#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
76
77
78
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 76
def norm_ref_entry_code(_ordinal, _idents, _ids, _standard, _datefn, _bib)
""
end
|
#note_delim(_elem) ⇒ Object
123
124
125
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 123
def note_delim(_elem)
":<tab/>"
end
|
#ogc_draft_ref?(ref) ⇒ Boolean
134
135
136
137
138
139
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 134
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
56
57
58
59
60
61
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 56
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
147
148
149
150
151
152
153
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 147
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
127
128
129
130
131
132
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 127
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
110
111
112
113
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 110
def references(docxml)
unnumber_biblio(docxml)
super
end
|
#rename_doctype(doctype, date) ⇒ Object
50
51
52
53
54
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 50
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
43
44
45
46
47
48
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 43
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
|
#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
def designation_boldface(desgn); end
102
103
104
105
106
107
108
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 102
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)
" <clause \#{add_id_text} type=\"submitting_orgs\">\n <title \#{add_id_text}>Submitting Organizations</title>\n <p>The following organizations submitted this Document to the Open Geospatial Consortium (OGC):</p>\n <ul \#{add_id_text}>\#{orgs.map { |m| \"<li \#{add_id_text}>\#{m}</li>\" }.join(\"\\n\")}</ul>\n </clause>\n SUBMITTING\nend\n"
|
#termsource_label(elem, sources) ⇒ Object
63
64
65
66
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 63
def termsource_label(elem, sources)
elem.replace(l10n("[<strong>#{@i18n.source}:</strong> " \
"#{sources}]"))
end
|
#ul_label_list(_elem) ⇒ Object
141
142
143
144
145
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 141
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
117
118
119
120
121
|
# File 'lib/isodoc/ogc/presentation_xml_convert.rb', line 117
def unnumber_biblio(docxml)
@doctype == "engineering-report" or return
b = docxml.at(ns(@xrefs.klass.bibliography_xpath)) or return
b["unnumbered"] = true
end
|