Class: IsoDoc::Iec::PresentationXMLConvert
- Inherits:
-
IsoDoc::Iso::PresentationXMLConvert
- Object
- IsoDoc::Iso::PresentationXMLConvert
- IsoDoc::Iec::PresentationXMLConvert
show all
- Includes:
- Init
- Defined in:
- lib/isodoc/iec/presentation_xml_convert.rb
Constant Summary
collapse
- DICT_PATHS =
{ doctype_dict: "./ext/doctype",
substage_dict: "./status/substage",
function_dict: "./ext/function",
horizontal_dict: "./ext/horizontal" }.freeze
Instance Method Summary
collapse
Methods included from Init
#convert1, #metadata_init, #std_docid_semantic, #xref_init
Instance Method Details
#bibdata_i18n(bib) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 47
def bibdata_i18n(bib)
[{ lang: "en", i18n: IsoDoc::Iec::I18n.new("en", "Latn") },
{ lang: "fr", i18n: IsoDoc::Iec::I18n.new("fr", "Latn") }].each do |v|
DICT_PATHS.each do |lbl, xpath|
hash_translate(bib, v[:i18n].get[lbl.to_s], xpath, v[:lang])
end
bibdata_i18n_stage(bib, bib.at(ns("./status/stage")),
bib.at(ns("./ext/doctype")),
lang: v[:lang], i18n: v[:i18n])
end
end
|
#bibrenderer ⇒ Object
232
233
234
235
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 232
def bibrenderer
::Relaton::Render::Iec::General.new(language: @lang,
i18nhash: @i18n.get)
end
|
#clause(docxml) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 16
def clause(docxml)
docxml.xpath(ns("//clause[not(ancestor::annex)] | " \
"//definitions | //references | " \
"//preface/introduction[clause]"))
.each do |f|
f.parent.name == "annex" &&
@xrefs.klass.single_term_clause?(f.parent) and next
clause1(f)
end
docxml.xpath(ns("//terms")).each do |f|
termclause1(f)
end
end
|
#clause1(elem) ⇒ Object
37
38
39
40
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 37
def clause1(elem)
IsoDoc::PresentationXMLConvert.instance_method(:clause1).bind(self)
.call(elem)
end
|
#concept(docxml) ⇒ Object
59
60
61
62
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 59
def concept(docxml)
@is_iev and concept_iev(docxml)
super
end
|
#concept_iev(docxml) ⇒ Object
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 64
def concept_iev(docxml)
labels = @xrefs.get_anchors.each_with_object({}) do |(k, v), m|
m[v[:label]] = k
end
docpart = docxml&.at(ns("//bibdata/ext/structuredidentifier/" \
"project-number/@part"))&.text or return
docxml.xpath(ns("//termref[@base = 'IEV']")).each do |t|
concept_iev1(t, docpart, labels)
end
end
|
#concept_iev1(termref, docpart, labels) ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 75
def concept_iev1(termref, docpart, labels)
/^#{docpart}-/.match?(termref["target"]) or return
newtarget = labels[termref["target"]] or return
termref.name = "xref"
termref.delete("base")
termref["target"] = newtarget
end
|
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 115
def (term, lgs)
term.xpath(ns(".//preferred/expression[@language]"))
.each_with_object([]) do |d, m|
lg = d["language"]
d.delete("language")
next if lgs.include?(lg)
p = d.parent
designation_annotate(p, d.at(ns("./name")))
m << { lang: lg, script: Metanorma::Utils.default_script(lg),
designation: to_xml(l10n_recursive(p.remove, lg)).strip }
end
end
|
#i18n_init(lang, script, locale, i18nyaml = nil) ⇒ Object
8
9
10
11
12
13
14
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 8
def i18n_init(lang, script, locale, i18nyaml = nil)
super
@i18n_lg = {}
@i18n_lg["en"] = I18n.new("en", "Latn", i18nyaml: i18nyaml || @i18nyaml)
@i18n_lg["fr"] = I18n.new("fr", "Latn", i18nyaml: i18nyaml || @i18nyaml)
@i18n_lg["default"] = @i18n
end
|
#insert_foreword(docxml) ⇒ Object
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 243
def insert_foreword(docxml)
@meta.get[:doctype] == "Amendment" and return
b = docxml.at(ns("//boilerplate/legal-statement")) or return
unless f = docxml.at(ns("//preface/foreword"))
ins = toc_title_insert_pt(docxml)
f = ins.before(<<~CLAUSE).previous_element
<foreword id='_#{UUIDTools::UUID.random_create}'> </foreword>
CLAUSE
end
f.children.empty? and f.children = " "
ins = f.at(ns("./title")) || f.children.first.before(" ").previous
ins.next =
"<clause type='boilerplate_legal'>#{to_xml(b.children)}</clause>"
end
|
#insert_middle_title(docxml) ⇒ Object
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 258
def insert_middle_title(docxml)
ins = docxml.at(ns("//preface/clause[@type = 'toc']")) or return
title1, title2 = middle_title_parts(nil)
title2out = ""
title2 and title2out = <<~OUTPUT
<p class="zzSTDTitle1"> </p>
<p class="zzSTDTitle2"><strong>#{title2}</strong></p>
OUTPUT
ins.next = <<~OUTPUT
<pagebreak/>
<p class="zzSTDTitle1">#{@i18n.get['IEC']}</p>
<p class="zzSTDTitle1">____________</p>
<p class="zzSTDTitle1"> </p>
<p class="zzSTDTitle1"><strong>#{title1.upcase}</strong></p>#{title2out}
<p class="zzSTDTitle1"> </p>
OUTPUT
end
|
#l10n_recursive(xml, lang) ⇒ Object
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 129
def l10n_recursive(xml, lang)
script = Metanorma::Utils.default_script(lang)
c = HTMLEntities.new
xml.traverse do |x|
x.text? or next
text = c.encode(c.decode(x.text), :hexadecimal)
x.replace(cleanup_entities(l10n(text, lang, script), is_xml: false))
end
xml
end
|
#merge_fr_into_en_term(docxml) ⇒ Object
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 89
def merge_fr_into_en_term(docxml)
@is_iev or return
docxml.xpath(ns("//term[@language = 'en'][@tag]")).each do |en|
fr = docxml.at(ns("//term[@language = 'fr'][@tag = '#{en['tag']}']"))
merge_fr_into_en_term1(en, fr) if fr
end
@xrefs.parse_inclusions(clauses: true).parse docxml
docxml.xpath(ns("//term/name")).each(&:remove)
term(docxml)
end
|
#merge_fr_into_en_term1(en_term, fr_term) ⇒ Object
100
101
102
103
104
105
106
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 100
def merge_fr_into_en_term1(en_term, fr_term)
dl = en_term&.at(ns("./dl[@type = 'other-lang']"))&.remove
en_term << fr_term.remove.children
en_term << dl if dl
en_term["language"] = "en,fr"
en_term.delete("tag")
end
|
#merge_otherlang_designations(desgn) ⇒ Object
140
141
142
143
144
145
146
147
148
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 140
def merge_otherlang_designations(desgn)
h = desgn.each_with_object({}) do |e, m|
if m[e[:lang]]
m[e[:lang]][:designation] += e[:designation]
else m[e[:lang]] = e
end
end
h.keys.sort.each_with_object([]) { |k, m| m << h[k] }
end
|
#middle_title_parts(_out) ⇒ Object
276
277
278
279
280
281
282
283
284
285
286
287
288
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 276
def middle_title_parts(_out)
title1 = @meta.get[:doctitlemain]&.sub(/\s+$/, "")
@meta.get[:doctitleintro] and
title1 = "#{@meta.get[:doctitleintro]} \u2014 #{title1}"
title2 = nil
if @meta.get[:doctitlepart]
title1 += " \u2014"
title2 = @meta.get[:doctitlepart]&.sub(/\s+$/, "")
@meta.get[:doctitlepartlabel] and
title2 = "#{@meta.get[:doctitlepartlabel]}: #{title2}"
end
[title1, title2]
end
|
168
169
170
171
172
173
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 168
def move_related(term)
defn = term.at(ns("./definition")) or return
term.xpath(ns("./related")).reverse.each do |r|
defn.next = r.remove
end
end
|
#otherlang_designations(docxml) ⇒ Object
108
109
110
111
112
113
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 108
def otherlang_designations(docxml)
@is_iev or return
docxml.xpath(ns("//term")).each do |t|
otherlang_designations1(t, t["language"]&.split(/,/) || %w(en fr))
end
end
|
#otherlang_designations1(term, lgs) ⇒ Object
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 150
def otherlang_designations1(term, lgs)
pr = merge_otherlang_designations(
(term, lgs),
)
pr.empty? and return
prefs = pr.map do |p|
"<dt>#{p[:lang]}</dt>" \
"<dd language='#{p[:lang]}' script='#{p[:script]}'>" \
"#{cleanup_entities(p[:designation])}</dd>"
end
term << "<dl type='other-lang'>#{prefs.join}</dl>"
end
|
#rearrange_clauses(docxml) ⇒ Object
237
238
239
240
241
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 237
def rearrange_clauses(docxml)
insert_foreword(docxml) super
insert_middle_title(docxml)
end
|
163
164
165
166
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 163
def related(docxml)
docxml.xpath(ns("//term[related]")).each { |f| move_related(f) }
super
end
|
175
176
177
178
179
180
181
182
183
184
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 175
def related1(node)
lg = node&.at("./ancestor::xmlns:term/@language")&.text
@i18n = @i18n_lg[lg] if lg && @i18n_lg[lg]
p = node.at(ns("./preferred"))
ref = node.at(ns("./xref | ./eref | ./termref"))
label = @i18n.relatedterms[node["type"]].upcase
node.replace(l10n("<p>#{label}: " \
"#{to_xml(p.children)} (#{to_xml(ref)})</p>"))
@i18n = @i18n_lg["default"]
end
|
#termclause1(elem) ⇒ Object
30
31
32
33
34
35
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 30
def termclause1(elem)
@is_iev or return clause1(elem)
@suppressheadingnumbers || elem["unnumbered"] and return
lbl = @xrefs.anchor(elem["id"], :label, true) or return
prefix_name(elem, " ", "#{lbl}#{clausedelim}", "title")
end
|
#termexample(docxml) ⇒ Object
209
210
211
212
213
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 209
def termexample(docxml)
docxml.xpath(ns("//termexample")).each do |f|
termexample1(f)
end
end
|
#termexample1(elem) ⇒ Object
215
216
217
218
219
220
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 215
def termexample1(elem)
lg = elem&.at("./ancestor::xmlns:term/@language")&.text
@i18n = @i18n_lg[lg] if lg && @i18n_lg[lg]
example1(elem)
@i18n = @i18n_lg["default"]
end
|
#termnote1(elem) ⇒ Object
222
223
224
225
226
227
228
229
230
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 222
def termnote1(elem)
lg = elem&.at("./ancestor::xmlns:term/@language")&.text
@i18n = @i18n_lg[lg] if lg && @i18n_lg[lg]
val = @xrefs.anchor(elem["id"], :value) || "???"
lbl = @i18n.termnote.gsub(/%/, val)
prefix_name(elem, "", lower2cap(lbl), "name")
@i18n = @i18n_lg["default"]
end
|
#terms(docxml) ⇒ Object
83
84
85
86
87
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 83
def terms(docxml)
otherlang_designations(docxml)
super
merge_fr_into_en_term(docxml)
end
|
#termsource1(node) ⇒ Object
193
194
195
196
197
198
199
200
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 193
def termsource1(node)
lg = node&.at("./ancestor::xmlns:term/@language")&.text
@i18n = @i18n_lg[lg] if lg && @i18n_lg[lg]
if @is_iev then termsource1_iev(node)
else super
end
@i18n = @i18n_lg["default"]
end
|
#termsource1_iev(elem) ⇒ Object
202
203
204
205
206
207
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 202
def termsource1_iev(elem)
while elem&.next_element&.name == "termsource"
elem << "; #{to_xml(elem.next_element.remove.children)}"
end
elem.children = l10n("#{@i18n.source}: #{to_xml(elem.children).strip}")
end
|
#termsource_modification(node) ⇒ Object
186
187
188
189
190
191
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 186
def termsource_modification(node)
lg = node&.at("./ancestor::xmlns:term/@language")&.text
@i18n = @i18n_lg[lg] if lg && @i18n_lg[lg]
super
@i18n = @i18n_lg["default"]
end
|