Class: IsoDoc::Iho::PresentationXMLConvert
- Inherits:
-
Generic::PresentationXMLConvert
- Object
- Generic::PresentationXMLConvert
- IsoDoc::Iho::PresentationXMLConvert
show all
- Includes:
- Init
- Defined in:
- lib/isodoc/iho/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
-
#bibdata_i18n(bibdata) ⇒ Object
-
#bibdata_logos(bibdata) ⇒ Object
-
#biblio_ref_entry_code(ordinal, _idents, _standard, _datefn, _bib) ⇒ Object
-
#bibliography_bibitem_tag1(ref, idx, norm) ⇒ Object
-
#clausedelim ⇒ Object
-
#collapse_term(docxml) ⇒ Object
-
#collapse_term1(term) ⇒ Object
-
#ddMMMyyyy(isodate) ⇒ Object
-
#dochistory(docxml) ⇒ Object
-
#dochistory_boilerplate(docxml) ⇒ Object
-
#dochistory_contributor(contrib) ⇒ Object
-
#dochistory_contributors(item) ⇒ Object
-
#dochistory_date(item) ⇒ Object
-
#dochistory_description(item) ⇒ Object
-
#format_personalname(contrib) ⇒ Object
-
#generate_dochistory(updates, ins, boilerplate) ⇒ Object
-
#generate_dochistory_row(item) ⇒ Object
-
#initialize(options) ⇒ PresentationXMLConvert
constructor
A new instance of PresentationXMLConvert.
-
#middle_title(docxml) ⇒ Object
-
#norm_ref_entry_code(ordinal, _idents, _standard, _datefn, _bib) ⇒ Object
-
#omit_docid_prefix(prefix) ⇒ Object
-
#preface_insert_point(docxml) ⇒ Object
-
#section(docxml) ⇒ Object
-
#term1(elem) ⇒ Object
-
#termcleanup(docxml) ⇒ Object
-
#termsource1(elem) ⇒ Object
-
#termsource_label(elem, sources) ⇒ Object
-
#ul_label_list(_elem) ⇒ Object
Methods included from Init
#bibrenderer, #i18n_init, #info, #metadata_init, #xref_init
Constructor Details
Returns a new instance of PresentationXMLConvert.
9
10
11
12
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 9
def initialize(options)
super
@libdir = File.dirname(__FILE__)
end
|
Instance Method Details
#bibdata_i18n(bibdata) ⇒ Object
176
177
178
179
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 176
def bibdata_i18n(bibdata)
super
bibdata_logos(bibdata)
end
|
#bibdata_logos(bibdata) ⇒ Object
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 181
def bibdata_logos(bibdata)
iho = bibdata.at(ns("./contributor[role/@type = 'publisher']/" \
"organization[abbreviation = 'IHO']")) or return
lang = %w(en fr es).include?(@lang) ? @lang : "en"
svgs = { full: svg_load("logo", "iho-logo_iho-#{lang}.svg"),
desc: svg_load("logo", "iho-logo_iho-tile-desc-#{lang}.svg"),
mark: svg_load("logo", "iho-logo_iho-tile-mark-#{lang}.svg"),
sign: svg_load("logo", "iho-logo_iho-tile-sign.svg") }
svgs.each do |k, v|
iho << <<~XML
<logo type="#{k}"><image src="" mimetype="image/svg+xml">#{v}</image></logo>
XML
end
end
|
#biblio_ref_entry_code(ordinal, _idents, _standard, _datefn, _bib) ⇒ Object
18
19
20
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 18
def biblio_ref_entry_code(ordinal, _idents, _standard, _datefn, _bib)
"[#{ordinal}]<tab/>"
end
|
#bibliography_bibitem_tag1(ref, idx, norm) ⇒ Object
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 165
def bibliography_bibitem_tag1(ref, idx, norm)
ref.xpath(ns("./bibitem")).each do |b|
implicit_reference(b) and next
idx += 1 unless b["hidden"]
insert_biblio_tag(b, idx, !norm, standard?(b))
end
idx
end
|
#clausedelim ⇒ Object
157
158
159
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 157
def clausedelim
""
end
|
#collapse_term(docxml) ⇒ Object
146
147
148
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 146
def collapse_term(docxml)
docxml.xpath(ns("//term")).each { |t| collapse_term1(t) }
end
|
#collapse_term1(term) ⇒ Object
150
151
152
153
154
155
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 150
def collapse_term1(term)
defn = term.at(ns("./fmt-definition")) or return
source = term.at(ns("./fmt-termsource")) or return
defn.elements.last << source.children
source.remove
end
|
#ddMMMyyyy(isodate) ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 112
def ddMMMyyyy(isodate)
isodate.nil? and return nil
arr = isodate.split("-")
if arr.size == 1 && (/^\d+$/.match isodate)
Date.new(*arr.map(&:to_i)).strftime("%Y")
elsif arr.size == 2
Date.new(*arr.map(&:to_i)).strftime("%B %Y")
else
Date.parse(isodate).strftime("%d %B %Y")
end
end
|
#dochistory(docxml) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 34
def dochistory(docxml)
updates = docxml.xpath(ns(UPDATE_RELATIONS))
updates.empty? and return
ins = preface_insert_point(docxml)
boilerplate = dochistory_boilerplate(docxml)
generate_dochistory(updates, ins, boilerplate)
end
|
#dochistory_boilerplate(docxml) ⇒ Object
42
43
44
45
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 42
def dochistory_boilerplate(docxml)
docxml.at(ns("//metanorma-extension/clause" \
"[title[text() = 'document history']]/note[@type = 'boilerplate']"))
end
|
#dochistory_contributor(contrib) ⇒ Object
90
91
92
93
94
95
96
97
98
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 90
def dochistory_contributor(contrib)
ret = contrib.at(ns("./organization/abbreviation")) ||
contrib.at(ns("./organization/subdivision")) ||
contrib.at(ns("./organization/name")) ||
contrib.at(ns("./person/name/abbreviation")) ||
contrib.at(ns("./person/name/completename"))
ret and return ret.text
format_personalname(contrib)
end
|
#dochistory_contributors(item) ⇒ Object
84
85
86
87
88
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 84
def dochistory_contributors(item)
item.xpath(ns("./contributor")).map do |c|
dochistory_contributor(c)
end.join(", ")
end
|
#dochistory_date(item) ⇒ Object
77
78
79
80
81
82
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 77
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 ""
ddMMMyyyy(d.text.strip)
end
|
#dochistory_description(item) ⇒ Object
106
107
108
109
110
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 106
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
|
100
101
102
103
104
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 100
def format_personalname(contrib)
Relaton::Render::General.new(template: { book: "{{ creatornames }}" })
.render("<bibitem type='book'>#{contrib.to_xml}</bibitem>",
embedded: true)
end
|
#generate_dochistory(updates, ins, boilerplate) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 52
def generate_dochistory(updates, ins, boilerplate)
ret = updates.map { |u| generate_dochistory_row(u) }.flatten.join("\n")
b = boilerplate&.children
ins << <<~XML
<clause #{add_id_text}>
<title #{add_id_text}>#{@i18n.dochistory}</title>
#{to_xml(b)}
<table #{add_id_text} unnumbered="true"><thead>
<tr #{add_id_text}><th #{add_id_text}>Version Number</th><th #{add_id_text}>Date</th><th #{add_id_text}>Author</th><th #{add_id_text}>Description</th></tr>
</thead><tbody>
#{ret}
</tbody></table></clause>
XML
end
|
#generate_dochistory_row(item) ⇒ Object
67
68
69
70
71
72
73
74
75
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 67
def generate_dochistory_row(item)
e = item.at(ns("./edition"))&.text
date = dochistory_date(item)
c = dochistory_contributors(item)
desc = dochistory_description(item)
<<~XML
<tr #{add_id_text}><td #{add_id_text}>#{e}</td><td #{add_id_text}>#{date}</td><td #{add_id_text}>#{c}</td><td #{add_id_text}>#{desc}</td></tr>
XML
end
|
#middle_title(docxml) ⇒ Object
22
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 22
def middle_title(docxml); end
|
#norm_ref_entry_code(ordinal, _idents, _standard, _datefn, _bib) ⇒ Object
14
15
16
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 14
def norm_ref_entry_code(ordinal, _idents, _standard, _datefn, _bib)
"[#{ordinal}]<tab/>"
end
|
#omit_docid_prefix(prefix) ⇒ Object
124
125
126
127
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 124
def omit_docid_prefix(prefix)
prefix == "IHO" and return true
super
end
|
#preface_insert_point(docxml) ⇒ Object
47
48
49
50
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 47
def preface_insert_point(docxml)
docxml.at(ns("//preface")) || docxml.at(ns("//sections"))
.add_previous_sibling("<preface> </preface>").first
end
|
#section(docxml) ⇒ Object
24
25
26
27
28
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 24
def section(docxml)
dochistory(docxml)
@xrefs.parse docxml
super
end
|
#term1(elem) ⇒ Object
129
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 129
def term1(elem); end
|
#termcleanup(docxml) ⇒ Object
141
142
143
144
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 141
def termcleanup(docxml)
collapse_term docxml
super
end
|
#termsource1(elem) ⇒ Object
131
132
133
134
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 131
def termsource1(elem)
elem.parent.nil? and return
super
end
|
#termsource_label(elem, sources) ⇒ Object
136
137
138
139
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 136
def termsource_label(elem, sources)
elem.at("./ancestor::xmlns:term") or return
elem.replace(l10n("[#{sources}]"))
end
|
#ul_label_list(_elem) ⇒ Object
161
162
163
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 161
def ul_label_list(_elem)
%w(• — o)
end
|