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_terms.rb,
lib/isodoc/iec/presentation_xml_convert.rb
Constant Summary
collapse
- DICT_PATHS =
{ doctype_dict: ["./ext/doctype",
"//presentation-metadata/doctype-alias"],
substage_dict: ["./status/substage", nil],
function_dict: ["./ext/function", nil],
horizontal_dict: ["./ext/horizontal", nil] }.freeze
Instance Method Summary
collapse
-
#bibdata_i18n(bib) ⇒ Object
-
#clause1(elem) ⇒ Object
-
#concept(docxml) ⇒ Object
-
#concept_iev(docxml) ⇒ Object
-
#concept_iev1(termref, docpart, labels) ⇒ Object
-
#extract_otherlang_designations(term, lgs) ⇒ Object
-
#i18n_init(lang, script, locale, i18nyaml = nil) ⇒ Object
-
#iev_termclause1(elem) ⇒ Object
-
#insert_foreword(docxml) ⇒ Object
-
#insert_foreword_boilerplate(elem, boilerplate) ⇒ Object
-
#insert_middle_title(docxml) ⇒ Object
-
#l10n_recursive(xml, lang) ⇒ Object
-
#merge_fr_into_en_term(docxml) ⇒ Object
-
#merge_fr_into_en_term1(en_term, fr_term) ⇒ Object
-
#merge_otherlang_designations(desgn) ⇒ Object
-
#middle_title_part(title1, title2) ⇒ Object
-
#middle_title_template ⇒ Object
-
#move_related(term) ⇒ Object
-
#otherlang_designations(docxml) ⇒ Object
-
#otherlang_designations1(term, lgs) ⇒ Object
-
#preface_title_template ⇒ Object
-
#rearrange_clauses(docxml) ⇒ Object
-
#related(docxml) ⇒ Object
-
#related1(node) ⇒ Object
-
#remove_otherlang_designations(docxml) ⇒ Object
-
#remove_otherlang_designations1(term, lgs) ⇒ Object
-
#termdomain(elem, fmt_defn) ⇒ Object
-
#termexample(docxml) ⇒ Object
-
#termexample1(elem) ⇒ Object
-
#termnote_label(elem) ⇒ Object
-
#terms(docxml) ⇒ Object
-
#termsource_label(elem, sources) ⇒ Object
-
#termsource_modification(node) ⇒ Object
-
#ul_label_list(_elem) ⇒ Object
Methods included from Init
#bibrenderer, #convert1, #metadata_init, #std_docid_semantic, #xref_init
Instance Method Details
#bibdata_i18n(bib) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 31
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[0], xpath[1],
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
|
#clause1(elem) ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 17
def clause1(elem)
if elem.name == "terms" && @is_iev then iev_termclause1(elem)
else
IsoDoc::PresentationXMLConvert.instance_method(:clause1).bind(self)
.call(elem)
end
end
|
#concept(docxml) ⇒ Object
14
15
16
17
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 14
def concept(docxml)
super
@is_iev and concept_iev(docxml)
end
|
#concept_iev(docxml) ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 19
def concept_iev(docxml)
labels = @xrefs.get_anchors.each_with_object({}) do |(k, v), m|
v[:label] and m[v[:label].gsub(%r{</?[^>]+>}, "")] = k
end
docpart = docxml.at(ns("//bibdata/ext/structuredidentifier/" \
"project-number/@part"))&.text or return
docxml.xpath(ns("//fmt-concept//termref[@base = 'IEV']")).each do |t|
concept_iev1(t, docpart, labels)
end
end
|
#concept_iev1(termref, docpart, labels) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 30
def concept_iev1(termref, docpart, labels)
/^#{docpart}-/.match?(termref["target"]) or return
newtarget = labels[termref["target"]] or return
termref.name = "fmt-xref"
termref.delete("base")
termref["target"] = newtarget
xref1(termref)
end
|
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 98
def (term, lgs)
term.xpath(ns(".//preferred/expression[@language]"))
.each_with_object([]) do |d, m|
lg = d["language"]
lgs.include?(lg) and next
p = semx_fmt_dup(d.parent)
e = p.at(ns("./expression"))
e.delete("language")
designation_annotate(p, p.at(ns(".//name")), d.parent)
m << { lang: lg, script: Metanorma::Utils.default_script(lg),
designation: to_xml(l10n_recursive(p, lg)).strip }
end
end
|
#i18n_init(lang, script, locale, i18nyaml = nil) ⇒ Object
9
10
11
12
13
14
15
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 9
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
|
#iev_termclause1(elem) ⇒ Object
4
5
6
7
8
9
10
11
12
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 4
def iev_termclause1(elem)
@suppressheadingnumbers || elem["unnumbered"] or
lbl = @xrefs.anchor(elem["id"], :label, true)
if lbl
prefix_name(elem, { caption: " " }, "#{lbl}#{clausedelim}", "title")
else
prefix_name(elem, {}, nil, "title")
end
end
|
#insert_foreword(docxml) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 50
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 #{add_id_text}> </foreword>
CLAUSE
end
insert_foreword_boilerplate(f, b)
end
|
#insert_foreword_boilerplate(elem, boilerplate) ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 62
def insert_foreword_boilerplate(elem, boilerplate)
elem.children.empty? and elem.children = " "
ins = elem.at(ns("./title")) || elem.children.first.before(" ").previous
ins.next = <<~CLAUSE
<clause type='boilerplate_legal' #{add_id_text}>#{to_xml(boilerplate.children)}</clause>
CLAUSE
end
|
#insert_middle_title(docxml) ⇒ Object
70
71
72
73
74
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 70
def insert_middle_title(docxml)
ins = docxml.at(ns("//preface/clause[@type = 'toc']")) or return
title = populate_template(preface_title_template, nil) or return
ins.next = title
end
|
#l10n_recursive(xml, lang) ⇒ Object
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 112
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
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 54
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/fmt-name | //term/fmt-xref-label"))
.each(&:remove)
term(docxml)
end
|
#merge_fr_into_en_term1(en_term, fr_term) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 67
def merge_fr_into_en_term1(en_term, fr_term)
dl = en_term&.at(ns("./dl[@type = 'other-lang']"))&.remove
dup = semx_fmt_dup(fr_term)
dup.xpath(ns("./fmt-name | ./fmt-xref-label")).each(&:remove)
en_term << dup
fr_term.xpath(ns(".//fmt-name | .//fmt-xref-label | " \
".//fmt-preferred | .//fmt-admitted | .//fmt-deprecates | " \
".//fmt-definition | .//fmt-related | .//fmt-termsource"))
.each(&:remove)
fr_term["unnumbered"] = "true"
en_term << dl if dl
en_term["language"] = "en,fr"
en_term.delete("tag")
end
|
#merge_otherlang_designations(desgn) ⇒ Object
123
124
125
126
127
128
129
130
131
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 123
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_part(title1, title2) ⇒ Object
90
91
92
93
94
95
96
97
98
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 90
def middle_title_part(title1, title2)
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
|
#middle_title_template ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 100
def middle_title_template
<<~OUTPUT
<p class='zzSTDTitle1'><strong>{% if doctitleintro %}{{ doctitleintro -}}
— {% endif %}{{ doctitlemain }}{% if doctitlepart %} —{% endif %}</strong></p>
{% if doctitlepart %}<p class='zzSTDTitle1'> </p>
<p class='zzSTDTitle2'><strong>{% if doctitlepartlabel %}{{ doctitlepartlabel }}: {% endif -%}
{{ doctitlepart }}</strong><p>
{% endif %}
<p class='zzSTDTitle1'> </p>
OUTPUT
end
|
162
163
164
165
166
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 162
def move_related(term)
defn = term.at(ns("./fmt-definition")) or return
rel = term.at(ns("./fmt-related")) or return
defn << rel.children
end
|
#otherlang_designations(docxml) ⇒ Object
83
84
85
86
87
88
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 83
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
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 133
def otherlang_designations1(term, lgs)
pr = merge_otherlang_designations(
(term, lgs),
)
pr.empty? and return
prefs = pr.map do |p|
<<~XML
<dt>#{p[:lang]}</dt>
<dd #{add_id_text} language='#{p[:lang]}' script='#{p[:script]}'>#{cleanup_entities(p[:designation])}</dd>
XML
end
term << "<dl #{add_id_text} type='other-lang'>#{prefs.join}</dl>"
end
|
#preface_title_template ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 76
def preface_title_template
<<~OUTPUT
<pagebreak/><p class="zzSTDTitle1">{{ labels["IEC"] }}</p>
<p class="zzSTDTitle1">____________</p><p class="zzSTDTitle1"> </p>
<p class='zzSTDTitle1'><strong>{% if doctitleintro %}{{ doctitleintro | upcase -}}
— {% endif %}{{ doctitlemain | upcase }}{% if doctitlepart %} —{% endif %}</strong></p>
{% if doctitlepart %}<p class='zzSTDTitle1'> </p>
<p class='zzSTDTitle2'><strong>{% if doctitlepartlabel %}{{ doctitlepartlabel }}: {% endif -%}
{{ doctitlepart }}</strong><p>
{% endif %}
<p class='zzSTDTitle1'> </p>
OUTPUT
end
|
#rearrange_clauses(docxml) ⇒ Object
44
45
46
47
48
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 44
def rearrange_clauses(docxml)
insert_foreword(docxml) super
insert_middle_title(docxml)
end
|
157
158
159
160
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 157
def related(docxml)
super
docxml.xpath(ns("//term[related]")).each { |f| move_related(f) }
end
|
168
169
170
171
172
173
174
175
176
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 168
def related1(node)
lg = node.at("./ancestor::xmlns:term/@language")&.text
@i18n = @i18n_lg[lg] if lg && @i18n_lg[lg]
p, ref, orig = related1_prep(node)
label = @i18n.relatedterms[orig["type"]].upcase
node.children = (l10n("<p>#{label}: " \
"#{to_xml(p)} (#{Common::to_xml(ref)})</p>"))
@i18n = @i18n_lg["default"]
end
|
#remove_otherlang_designations(docxml) ⇒ Object
90
91
92
93
94
95
96
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 90
def remove_otherlang_designations(docxml)
@is_iev or return
docxml.xpath(ns("//term")).each do |t|
remove_otherlang_designations1(t,
t["language"]&.split(",") || %w(en fr))
end
end
|
#remove_otherlang_designations1(term, lgs) ⇒ Object
147
148
149
150
151
152
153
154
155
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 147
def remove_otherlang_designations1(term, lgs)
term.xpath(ns(".//fmt-preferred/p/semx[@element = 'preferred']"))
.each do |s|
p = semx_orig(s, term)
lg = p.at(ns("./expression/@language"))&.text or next
lgs.include?(lg) and next
s.parent.remove
end
end
|
#termdomain(elem, fmt_defn) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 46
def termdomain(elem, fmt_defn)
if @is_iev
else super
end
end
|
#termexample(docxml) ⇒ Object
193
194
195
196
197
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 193
def termexample(docxml)
docxml.xpath(ns("//termexample")).each do |f|
termexample1(f)
end
end
|
#termexample1(elem) ⇒ Object
199
200
201
202
203
204
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 199
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
|
#termnote_label(elem) ⇒ Object
206
207
208
209
210
211
212
213
214
215
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 206
def termnote_label(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)
ret = @i18n.l10n lbl
@i18n = @i18n_lg["default"]
ret
end
|
#terms(docxml) ⇒ Object
39
40
41
42
43
44
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 39
def terms(docxml)
otherlang_designations(docxml)
super
remove_otherlang_designations(docxml)
merge_fr_into_en_term(docxml)
end
|
#termsource_label(elem, sources) ⇒ Object
185
186
187
188
189
190
191
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 185
def termsource_label(elem, sources)
@is_iev or return super
lg = elem&.at("./ancestor::xmlns:term/@language")&.text
@i18n = @i18n_lg[lg] if lg && @i18n_lg[lg]
elem.replace(l10n("#{@i18n.source}: #{sources}"))
@i18n = @i18n_lg["default"]
end
|
#termsource_modification(node) ⇒ Object
178
179
180
181
182
183
|
# File 'lib/isodoc/iec/presentation_terms.rb', line 178
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
|
#ul_label_list(_elem) ⇒ Object
112
113
114
|
# File 'lib/isodoc/iec/presentation_xml_convert.rb', line 112
def ul_label_list(_elem)
%w(• — o)
end
|