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
|
#clause(docxml) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 15
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
|
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 117
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
7
8
9
10
11
12
13
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 7
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
|
#l10n_recursive(xml, lang) ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 131
def l10n_recursive(xml, lang)
script = Metanorma::Utils.default_script(lang)
c = HTMLEntities.new
xml.traverse do |x|
next unless x.text?
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
99
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 89
def merge_fr_into_en_term(docxml)
return unless @is_iev
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
101
102
103
104
105
106
107
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 101
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
143
144
145
146
147
148
149
150
151
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 143
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
|
172
173
174
175
176
177
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 172
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
109
110
111
112
113
114
115
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 109
def otherlang_designations(docxml)
return unless @is_iev
docxml.xpath(ns("//term")).each do |t|
otherlang_designations1(t, t["language"]&.split(/,/) || %w(en fr))
end
end
|
#otherlang_designations1(term, lgs) ⇒ Object
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 153
def otherlang_designations1(term, lgs)
pr = merge_otherlang_designations(
(term, lgs),
)
return if pr.empty?
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
|
167
168
169
170
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 167
def related(docxml)
docxml.xpath(ns("//term[related]")).each { |f| move_related(f) }
super
end
|
179
180
181
182
183
184
185
186
187
188
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 179
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
29
30
31
32
33
34
35
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 29
def termclause1(elem)
return clause1(elem) unless @is_iev
return if @suppressheadingnumbers || elem["unnumbered"]
lbl = @xrefs.anchor(elem["id"], :label, true) or return
prefix_name(elem, " ", "#{lbl}#{clausedelim}", "title")
end
|
#termexample(docxml) ⇒ Object
213
214
215
216
217
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 213
def termexample(docxml)
docxml.xpath(ns("//termexample")).each do |f|
termexample1(f)
end
end
|
#termexample1(elem) ⇒ Object
219
220
221
222
223
224
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 219
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
226
227
228
229
230
231
232
233
234
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 226
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
197
198
199
200
201
202
203
204
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 197
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
206
207
208
209
210
211
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 206
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
190
191
192
193
194
195
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 190
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
|