Class: IsoDoc::IEEE::PresentationXMLConvert
- Inherits:
-
PresentationXMLConvert
- Object
- PresentationXMLConvert
- IsoDoc::IEEE::PresentationXMLConvert
show all
- Includes:
- Init
- Defined in:
- lib/isodoc/ieee/presentation_ref.rb,
lib/isodoc/ieee/presentation_terms.rb,
lib/isodoc/ieee/presentation_bibdata.rb,
lib/isodoc/ieee/presentation_xml_convert.rb
Instance Method Summary
collapse
-
#admitted_to_related(docxml) ⇒ Object
-
#admitted_to_related1(adm, pref) ⇒ Object
-
#affiliation_header(clause) ⇒ Object
-
#amend1(elem) ⇒ Object
-
#amend_format(para) ⇒ Object
-
#anchor_linkend(node, linkend) ⇒ Object
-
#anchor_linkend1(node) ⇒ Object
-
#annex1(elem) ⇒ Object
-
#annex1_default(elem) ⇒ Object
-
#annex1_whitepaper(elem) ⇒ Object
-
#asciimath_dup(node) ⇒ Object
-
#bibdata_dates(bib) ⇒ Object
-
#bibdata_i18n(bib) ⇒ Object
-
#biblio_anchor_linkend(node, bib) ⇒ Object
-
#biblio_ids_titles(xmldoc) ⇒ Object
-
#bibliography_bibitem_number1(bibitem, idx) ⇒ Object
-
#bibrender_relaton(xml, renderings) ⇒ Object
-
#bibrenderer ⇒ Object
-
#block_delim ⇒ Object
-
#boilerplate(docxml) ⇒ Object
-
#citestyle ⇒ Object
-
#collapse_multidef(elem) ⇒ Object
-
#collapse_term(docxml) ⇒ Object
-
#collapse_term1(term) ⇒ Object
-
#collapse_term_related(rels) ⇒ Object
-
#collapse_term_template(opt) ⇒ Object
-
#collapse_unwrap_definition(defn) ⇒ Object
-
#concept1(node) ⇒ Object
-
#creatornames(bibitem) ⇒ Object
-
#ddMMMyyyy(isodate) ⇒ Object
-
#designation_field(desgn, name) ⇒ Object
-
#eref_localities1(opt) ⇒ Object
-
#eref_localities_conflated(refs, target, node) ⇒ Object
-
#expand_citeas(text) ⇒ Object
-
#formula_where(dlist) ⇒ Object
-
#initialize(options) ⇒ PresentationXMLConvert
constructor
A new instance of PresentationXMLConvert.
-
#merge_second_preferred(term) ⇒ Object
-
#middle_title(docxml) ⇒ Object
-
#middle_title_body ⇒ Object
-
#middle_title_insert(docxml) ⇒ Object
-
#move_abstract(doc) ⇒ Object
-
#multidef(elem) ⇒ Object
-
#note1(elem) ⇒ Object
-
#number_multidef(elem) ⇒ Object
-
#ol(docxml) ⇒ Object
-
#ol_depth_rotate(node, idx) ⇒ Object
-
#ol_numbering(docxml) ⇒ Object
-
#ol_numbering1(elem, idx) ⇒ Object
-
#participant_member_para(map, name, _idx) ⇒ Object
-
#participant_name(map) ⇒ Object
-
#participant_officeholder_para(map, name, idx) ⇒ Object
-
#participant_para(map, idx) ⇒ Object
-
#participants(clause) ⇒ Object
-
#participants1(list, idx) ⇒ Object
-
#preface_rearrange(doc) ⇒ Object
-
#prefix_clause(target, loc) ⇒ Object
-
#references_render(docxml) ⇒ Object
-
#related(docxml) ⇒ Object
-
#related_term(term) ⇒ Object
-
#section(docxml) ⇒ Object
-
#sort_related(coll) ⇒ Object
-
#sort_related_key(related) ⇒ Object
-
#sort_terms(terms) ⇒ Object
-
#sort_terms_key(term) ⇒ Object
-
#sort_terms_key1(elem) ⇒ Object
-
#subclause?(target, type, from) ⇒ Boolean
-
#term(docxml) ⇒ Object
-
#term_related_collapse(coll) ⇒ Object
-
#term_related_reorder(coll) ⇒ Object
-
#term_reorder(xmldoc) ⇒ Object
-
#term_reorder1(terms) ⇒ Object
-
#termnote1(elem) ⇒ Object
-
#terms(docxml) ⇒ Object
-
#termsource1(elem) ⇒ Object
-
#termsource_adapt(status) ⇒ Object
-
#unwrap_definition(docxml) ⇒ Object
-
#unwrap_multidef(coll) ⇒ Object
Methods included from Init
#fileloc, #i18n_init, #metadata_init, #std_docid_sdo, #std_docid_semantic, #std_docid_semantic1, #std_docid_semantic_full, #xref_init
Constructor Details
Returns a new instance of PresentationXMLConvert.
10
11
12
13
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 10
def initialize(options)
@hierarchical_assets = options[:hierarchicalassets]
super
end
|
Instance Method Details
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 117
def admitted_to_related(docxml)
docxml.xpath(ns("//term")).each do |t|
t.xpath(ns("./admitted | ./preferred")).each_with_index do |a, i|
(i.zero? ||
a.at(ns("./abbreviation-type | ./graphical-symbol"))) and next
admitted_to_related1(a, t.at(ns("./preferred")))
end
end
term_reorder(docxml)
end
|
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 128
def admitted_to_related1(adm, pref)
new = adm.dup
adm["type"] = "equivalent"
adm.name = "related"
adm.children = "<preferred>#{to_xml(adm.children)}</preferred>"
adm.parent.next = <<~TERM
<term><preferred>#{to_xml(new.children)}</preferred>
<related type='see'><preferred>#{to_xml(pref.children)}</preferred></related></term>
TERM
end
|
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/isodoc/ieee/presentation_bibdata.rb', line 49
def (clause)
clause.xpath(ns(".//p[@type = 'officeorgrepmember']")).each do |p|
prev = p.previous_element
prev && prev.name == "p" &&
prev["type"] == "officeorgrepmember" and next
p.previous = <<~HDR
<p type='officeorgrepmemberhdr'><em>Organization
Represented</em><tab/><em>Name of Representative</em></p>
HDR
end
end
|
#amend1(elem) ⇒ Object
105
106
107
108
109
110
111
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 105
def amend1(elem)
elem.xpath(ns("./description/p")).each do |p|
p.children = to_xml(p.children).strip
amend_format(p)
end
super
end
|
113
114
115
116
117
118
119
120
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 113
def amend_format(para)
2.times do
para.children.size == 1 &&
%(em strong).include?(para.children.first.name) and
para.children = para.elements.first.children
end
para.children = "<strong><em>#{to_xml(para.children)}</em></strong>"
end
|
#anchor_linkend(node, linkend) ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/isodoc/ieee/presentation_ref.rb', line 7
def anchor_linkend(node, linkend)
@bibanchors ||= biblio_ids_titles(node.document)
if node["citeas"] && i = @bibanchors[node["bibitemid"]]
biblio_anchor_linkend(node, i)
else super
end
end
|
#anchor_linkend1(node) ⇒ Object
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 55
def anchor_linkend1(node)
linkend = @xrefs.anchor(node["target"], :xref)
@xrefs.anchor(node["target"], :type) == "clause" &&
@xrefs.anchor(node["target"], :level) > 1 &&
!start_of_sentence(node) and
linkend = linkend.sub(/^Clause /, "")
container = @xrefs.anchor(node["target"], :container, false)
linkend = prefix_container(container, linkend, node, node["target"])
capitalise_xref(node, linkend, anchor_value(node["target"]))
end
|
#annex1(elem) ⇒ Object
80
81
82
83
84
85
86
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 80
def annex1(elem)
if @doctype == "whitepaper"
annex1_whitepaper(elem)
else
annex1_default(elem)
end
end
|
#annex1_default(elem) ⇒ Object
97
98
99
100
101
102
103
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 97
def annex1_default(elem)
lbl = @xrefs.anchor(elem["id"], :label)
if t = elem.at(ns("./title"))
t.children = "<strong>#{to_xml(t.children)}</strong>"
end
prefix_name(elem, "<br/>", lbl, "title")
end
|
#annex1_whitepaper(elem) ⇒ Object
88
89
90
91
92
93
94
95
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 88
def annex1_whitepaper(elem)
lbl = @xrefs.anchor(elem["id"], :label)
if t = elem.at(ns("./title"))
t.name = "variant-title"
t["type"] = "sub"
end
elem.children.first.previous = "<title>#{lbl}</title>"
end
|
#asciimath_dup(node) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 127
def asciimath_dup(node)
@suppressasciimathdup and return
super
node.parent.at(ns("./latexmath")) and return
math = node.to_xml.gsub(/ xmlns=["'][^"']+["']/, "")
.gsub(%r{<[^:/]+:}, "<").gsub(%r{</[^:/]+:}, "</")
ret = Plurimath::Math.parse(math, "mathml").to_latex
ret = HTMLEntities.new.encode(ret, :basic)
node.next = "<latexmath>#{ret}</latexmath>"
rescue StandardError => e
warn "Failure to convert MathML to LaTeX\n#{node.parent.to_xml}\n#{e}"
end
|
#bibdata_dates(bib) ⇒ Object
9
10
11
12
13
14
15
16
17
|
# File 'lib/isodoc/ieee/presentation_bibdata.rb', line 9
def bibdata_dates(bib)
bib.xpath(ns("./date")).each do |d|
d.next = d.dup
d.next["format"] = "ddMMMyyyy"
d.next.xpath(ns("./from | ./to | ./on")).each do |x|
x.children = ddMMMyyyy(x.text)
end
end
end
|
#bibdata_i18n(bib) ⇒ Object
4
5
6
7
|
# File 'lib/isodoc/ieee/presentation_bibdata.rb', line 4
def bibdata_i18n(bib)
super
bibdata_dates(bib)
end
|
#biblio_anchor_linkend(node, bib) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/isodoc/ieee/presentation_ref.rb', line 15
def biblio_anchor_linkend(node, bib)
if %w(techreport standard).include?(bib[:type])
[node["citeas"], bib[:ord]].compact.join(" ")
else
"#{bib[:author]} " + node["citeas"]
end
end
|
#biblio_ids_titles(xmldoc) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/isodoc/ieee/presentation_ref.rb', line 23
def biblio_ids_titles(xmldoc)
xmldoc.xpath(ns("//references[@normative = 'false']/bibitem"))
.each_with_object({}) do |b, m|
m[b["id"]] =
{ docid: pref_ref_code(b), type: b["type"],
title: (b.at(ns("./title")) ||
b.at(ns("./formattedref")))&.text,
author: @author[b["id"]] || (b.at(ns("./title")) ||
b.at(ns("./formattedref")))&.text,
ord: b.at(ns("./docidentifier[@type = 'metanorma' or " \
"@type = 'metanorma-ordinal']"))&.text }
end
end
|
#bibliography_bibitem_number1(bibitem, idx) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/isodoc/ieee/presentation_ref.rb', line 68
def bibliography_bibitem_number1(bibitem, idx)
if mn = bibitem.at(ns(".//docidentifier[@type = 'metanorma']"))
/^\[?\d\]?$/.match?(mn&.text) and
idx = mn.text.sub(/^\[B?/, "").sub(/\]$/, "").to_i
end
unless bibliography_bibitem_number_skip(bibitem)
idx += 1
bibitem.at(ns(".//docidentifier")).previous =
"<docidentifier type='metanorma-ordinal'>[B#{idx}]</docidentifier>"
end
idx
end
|
#bibrender_relaton(xml, renderings) ⇒ Object
51
52
53
54
55
56
57
58
|
# File 'lib/isodoc/ieee/presentation_ref.rb', line 51
def bibrender_relaton(xml, renderings)
f = renderings[xml["id"]][:formattedref]
f &&= "<formattedref>#{f}</formattedref>"
keep = "./docidentifier | ./uri | ./note | ./title | ./biblio-tag"
xml.children =
"#{f}#{xml.xpath(ns(keep)).to_xml}"
@author[xml["id"]] = renderings[xml["id"]][:author]
end
|
#bibrenderer ⇒ Object
37
38
39
40
|
# File 'lib/isodoc/ieee/presentation_ref.rb', line 37
def bibrenderer
::Relaton::Render::IEEE::General.new(language: @lang,
i18nhash: @i18n.get)
end
|
#block_delim ⇒ Object
66
67
68
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 66
def block_delim
"—"
end
|
#boilerplate(docxml) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/isodoc/ieee/presentation_bibdata.rb', line 32
def boilerplate(docxml)
docxml.xpath(ns("//clause[@id = 'boilerplate-participants']/" \
"clause/title")).each(&:remove)
docxml.xpath(ns("//clause[@id = 'boilerplate-participants']/clause"))
.each do |clause|
participants(clause)
end
end
|
#citestyle ⇒ Object
42
43
44
|
# File 'lib/isodoc/ieee/presentation_ref.rb', line 42
def citestyle
"author-date"
end
|
#collapse_multidef(elem) ⇒ Object
18
19
20
21
22
23
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 18
def collapse_multidef(elem)
ins = elem.at(ns("./definition")).previous_element
coll = elem.xpath(ns("./definition"))
coll.each(&:remove)
ins.next = "<definition>#{unwrap_multidef(coll)}</definition>"
end
|
#collapse_term(docxml) ⇒ Object
157
158
159
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 157
def collapse_term(docxml)
docxml.xpath(ns("//term")).each { |t| collapse_term1(t) }
end
|
#collapse_term1(term) ⇒ Object
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 161
def collapse_term1(term)
ret = collapse_term_template(
pref: term.at(ns("./preferred"))&.remove,
def: term.at(ns("./definition")),
rels: term.xpath(ns("./related")).map(&:remove),
source: term.at(ns("./termsource")),
)
(ins = term.elements.first and ins.previous = ret) or
term << ret
end
|
172
173
174
175
176
177
178
179
180
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 172
def collapse_term_related(rels)
ret = rels.map do |r|
p = r.at(ns("./preferred"))
rel = p ? to_xml(p.children) : "**RELATED TERM NOT FOUND**"
"<em>#{@i18n.relatedterms[r['type']]}:</em> #{rel}"
end.join(". ")
ret += "." unless ret.empty?
ret
end
|
#collapse_term_template(opt) ⇒ Object
182
183
184
185
186
187
188
189
190
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 182
def collapse_term_template(opt)
defn = collapse_unwrap_definition(opt[:def])
src = nil
opt[:source] and src = "(#{to_xml(opt[:source].remove.children).strip})"
t = opt[:pref] ? to_xml(opt[:pref].children) : "**TERM NOT FOUND**"
<<~TERM
<p>#{t}: #{defn} #{collapse_term_related(opt[:rels])} #{src}</p>
TERM
end
|
#collapse_unwrap_definition(defn) ⇒ Object
192
193
194
195
196
197
198
199
200
201
202
203
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 192
def collapse_unwrap_definition(defn)
return nil if defn.nil?
s = defn.remove.xpath(ns("./termsource"))
p = defn.at(ns("./p"))
!s.empty? && p and p << s.map(&:remove).map(&:children)
.map { |x| to_xml(x) }.join
if defn.elements.size == 1 && defn.elements.first.name == "p"
defn.elements.first.children
else defn.elements
end
end
|
#concept1(node) ⇒ Object
247
248
249
250
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 247
def concept1(node)
concept_render(node, ital: "false", ref: "false", bold: "false",
linkref: "false", linkmention: "false")
end
|
#creatornames(bibitem) ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/isodoc/ieee/presentation_ref.rb', line 60
def creatornames(bibitem)
::Relaton::Render::IEEE::General
.new(language: @lang, i18nhash: @i18n.get,
template: { (bibitem["type"] || "misc").to_sym =>
"{{ creatornames }}" })
.parse1(RelatonBib::XMLParser.from_xml(bibitem.to_xml))
end
|
#ddMMMyyyy(isodate) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/isodoc/ieee/presentation_bibdata.rb', line 19
def ddMMMyyyy(isodate)
return nil if isodate.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
|
#designation_field(desgn, name) ⇒ Object
219
220
221
222
223
224
225
226
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 219
def designation_field(desgn, name)
if desgn.name == "preferred"
f = desgn.xpath(ns("./../domain | ./../subject")).map(&:remove)
.map { |u| to_xml(u.children) }.join(", ")
name << ", <#{f}>" unless f.empty?
end
super
end
|
#eref_localities1(opt) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 41
def eref_localities1(opt)
opt[:type] == "anchor" and return nil
opt[:type].downcase!
opt[:lang] == "zh" and return l10n(eref_localities1_zh(opt))
ret = ""
opt[:node]["droploc"] != "true" &&
!subclause?(opt[:target], opt[:type], opt[:from]) and
ret = eref_locality_populate(opt[:type], opt[:node], opt[:number])
ret += " #{opt[:from]}" if opt[:from]
ret += "–#{opt[:upto]}" if opt[:upto]
ret += ")" if opt[:type] == "list"
l10n(ret)
end
|
#eref_localities_conflated(refs, target, node) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 15
def eref_localities_conflated(refs, target, node)
droploc = node["droploc"]
node["droploc"] = true
ret = resolve_eref_connectives(eref_locality_stacks(refs, target,
node))
node["droploc"] = droploc
eref_localities1({ target: target, number: "pl",
type: prefix_clause(target, refs.first.at(ns("./locality"))),
from: l10n(ret[1..-1].join), node: node,
lang: @lang })
end
|
#expand_citeas(text) ⇒ Object
82
83
84
|
# File 'lib/isodoc/ieee/presentation_ref.rb', line 82
def expand_citeas(text)
std_docid_semantic(super)
end
|
140
141
142
143
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 140
def formula_where(dlist)
dlist or return
dlist["class"] = "formula_dl"
end
|
#merge_second_preferred(term) ⇒ Object
228
229
230
231
232
233
234
235
236
237
238
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 228
def merge_second_preferred(term)
pref =
term.at(ns("./preferred[not(abbreviation-type)]/expression/name"))
x = term.xpath(ns("./preferred[expression/name][abbreviation-type] | " \
"./admitted[expression/name][abbreviation-type]"))
(pref && !x.empty?) or return
tail = x.map do |p|
to_xml(p.remove.at(ns("./expression/name")).children).strip
end.join(", ")
pref << " (#{tail})"
end
|
#middle_title(docxml) ⇒ Object
181
182
183
184
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 181
def middle_title(docxml)
s = middle_title_insert(docxml) or return
s.previous = middle_title_body
end
|
#middle_title_body ⇒ Object
186
187
188
189
190
191
192
193
194
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 186
def middle_title_body
ret = "<p class='zzSTDTitle1'>#{@meta.get[:full_doctitle]}"
@meta.get[:amd] || @meta.get[:corr] and ret += "<br/>"
@meta.get[:amd] and ret += "Amendment #{@meta.get[:amd]}"
@meta.get[:amd] && @meta.get[:corr] and ret += " "
@meta.get[:corr] and ret += "Corrigenda #{@meta.get[:corr]}"
ret += "</p>"
ret
end
|
#middle_title_insert(docxml) ⇒ Object
196
197
198
199
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 196
def middle_title_insert(docxml)
s = docxml.at(ns("//sections")) or return
s.children.first
end
|
#move_abstract(doc) ⇒ Object
206
207
208
209
210
211
212
213
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 206
def move_abstract(doc)
doc.at(ns("//bibdata/ext/doctype"))&.text == "whitepaper" or return
source = doc.at(ns("//preface/abstract")) or return
dest = doc.at(ns("//sections")) ||
doc.at(ns("//preface")).after("<sections> </sections>").next_element
dest.children.empty? and dest.children = " "
dest.children.first.next = source
end
|
#multidef(elem) ⇒ Object
4
5
6
7
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 4
def multidef(elem)
number_multidef(elem)
collapse_multidef(elem)
end
|
#note1(elem) ⇒ Object
70
71
72
73
74
75
76
77
78
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 70
def note1(elem)
return if elem.parent.name == "bibitem" || elem["notag"] == "true"
n = @xrefs.get[elem["id"]]
lbl = if n.nil? || n[:label].nil? || n[:label].empty? then @i18n.note
else l10n("#{@i18n.note} #{n[:label]}")
end
prefix_name(elem, block_delim, lbl, "name")
end
|
#number_multidef(elem) ⇒ Object
9
10
11
12
13
14
15
16
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 9
def number_multidef(elem)
c = IsoDoc::XrefGen::Counter.new("@")
elem.xpath(ns("./definition")).each do |d|
c.increment(d)
d.elements.first.children.first.previous =
"<strong>(#{c.print})</strong> "
end
end
|
#ol(docxml) ⇒ Object
145
146
147
148
149
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 145
def ol(docxml)
ol_numbering(docxml)
@xrefs.list_anchor_names(docxml.xpath(ns(@xrefs.sections_xpath)))
docxml.xpath(ns("//ol/li")).each { |f| ol_label(f) }
end
|
#ol_depth_rotate(node, idx) ⇒ Object
173
174
175
176
177
178
179
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 173
def ol_depth_rotate(node, idx)
depth = node.ancestors("ol").size + idx
type = :alphabet
type = :arabic if [2, 5, 8].include? depth
type = :roman if [3, 6, 9].include? depth
type
end
|
#ol_numbering(docxml) ⇒ Object
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 151
def ol_numbering(docxml)
p = "//clause | //annex | //foreword | //acknowledgements | " \
"//introduction | //preface/abstract | //appendix | //terms | " \
"//term | //definitions | //references | //colophon"
docxml.xpath(ns(p)).each do |c|
(c.xpath(ns(".//ol")) -
c.xpath(ns("./clause//ol | ./appendix//ol | ./term//ol | " \
"./terms//ol | ./definitions//ol | " \
"/references//ol | ./colophon//ol")))
.each_with_index do |o, i|
ol_numbering1(o, i)
end
end
end
|
#ol_numbering1(elem, idx) ⇒ Object
166
167
168
169
170
171
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 166
def ol_numbering1(elem, idx)
elem["type"] = ol_depth_rotate(elem, idx).to_s
elem.xpath(ns("./li")).each do |li|
li["id"] ||= "_#{UUIDTools::UUID.random_create}"
end
end
|
#participant_member_para(map, name, _idx) ⇒ Object
79
80
81
82
83
84
85
86
|
# File 'lib/isodoc/ieee/presentation_bibdata.rb', line 79
def participant_member_para(map, name, _idx)
if map["company"] && (map["name"] || map["surname"])
pers = map["name"] || "#{map['given']} #{map['surname']}"
"<p type='officeorgrepmember'>#{name}<tab/>#{pers}</p>"
elsif map["company"] then "<p type='officeorgmember'>#{name}</p>"
else "<p type='officemember'>#{name}</p>"
end
end
|
#participant_name(map) ⇒ Object
95
96
97
|
# File 'lib/isodoc/ieee/presentation_bibdata.rb', line 95
def participant_name(map)
map["company"] || map["name"] || "#{map['given']} #{map['surname']}"
end
|
#participant_officeholder_para(map, name, idx) ⇒ Object
88
89
90
91
92
93
|
# File 'lib/isodoc/ieee/presentation_bibdata.rb', line 88
def participant_officeholder_para(map, name, idx)
name = "<strong>#{name}</strong>" if idx.zero?
br = map["role"].size > 30 ? "<br/>" : ""
"<p type='officeholder' align='center'>#{name}, #{br}" \
"<em>#{map['role']}</em></p>"
end
|
#participant_para(map, idx) ⇒ Object
70
71
72
73
74
75
76
77
|
# File 'lib/isodoc/ieee/presentation_bibdata.rb', line 70
def participant_para(map, idx)
name = participant_name(map)
if map["role"]&.casecmp("member")&.zero?
participant_member_para(map, name, idx)
else
participant_officeholder_para(map, name, idx)
end
end
|
#participants(clause) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/isodoc/ieee/presentation_bibdata.rb', line 41
def participants(clause)
clause.xpath(ns(".//ul")).each_with_index do |ulist, idx|
ulist.xpath(ns("./li")).each { |list| participants1(list, idx) }
ulist.replace(ulist.children)
end
(clause)
end
|
#participants1(list, idx) ⇒ Object
61
62
63
64
65
66
67
68
|
# File 'lib/isodoc/ieee/presentation_bibdata.rb', line 61
def participants1(list, idx)
key = ""
map = list.xpath(ns(".//dt | .//dd")).each_with_object({}) do |dtd, m|
(dtd.name == "dt" and key = dtd.text) or
m[key] = @c.encode(dtd.text.strip, :hexadecimal)
end
list.replace(participant_para(map, idx))
end
|
#preface_rearrange(doc) ⇒ Object
201
202
203
204
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 201
def preface_rearrange(doc)
move_abstract(doc)
super
end
|
#prefix_clause(target, loc) ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 27
def prefix_clause(target, loc)
loc["type"] == "clause" or return loc["type"]
if subclause?(target, loc["type"],
loc&.at(ns("./referenceFrom"))&.text)
""
else "clause"
end
end
|
#references_render(docxml) ⇒ Object
46
47
48
49
|
# File 'lib/isodoc/ieee/presentation_ref.rb', line 46
def references_render(docxml)
@author = {}
super
end
|
47
48
49
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 47
def related(docxml)
docxml.xpath(ns("//term[related]")).each { |f| related_term(f) }
end
|
51
52
53
54
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 51
def related_term(term)
coll = term_related_reorder(term.xpath(ns("./related")))
term_related_collapse(coll)
end
|
#section(docxml) ⇒ Object
122
123
124
125
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 122
def section(docxml)
boilerplate(docxml)
super
end
|
94
95
96
97
98
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 94
def sort_related(coll)
coll.sort do |a, b|
sort_related_key(a) <=> sort_related_key(b)
end
end
|
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 100
def sort_related_key(related)
type = case related["type"]
when "contrast" then 1
when "equivalent" then 2
when "see" then 3
when "seealso" then 4
else "5-#{related['type']}"
end
"#{type} :: #{sort_terms_key(related)}"
end
|
#sort_terms(terms) ⇒ Object
151
152
153
154
155
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 151
def sort_terms(terms)
terms.sort do |a, b|
sort_terms_key(a) <=> sort_terms_key(b)
end
end
|
#sort_terms_key(term) ⇒ Object
69
70
71
72
73
74
75
76
77
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 69
def sort_terms_key(term)
d = term.at(ns("./preferred/expression/name | " \
"./preferred/letter-symbol/name | " \
"./preferred/graphical-symbol/figure/name | " \
"./preferred/graphical-symbol/figure/@id | " \
"./preferred"))
f = term.at(ns("./field-of-application")) || term.at(ns("./domain"))
HTMLEntities.new.decode("#{sort_terms_key1(d)} :: #{sort_terms_key1(f)}")
end
|
#sort_terms_key1(elem) ⇒ Object
79
80
81
82
83
84
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 79
def sort_terms_key1(elem)
elem.nil? and return "zzzz"
dup = elem.dup
dup.xpath(ns(".//asciimath | .//latexmath")).each(&:remove)
dup.text&.strip&.downcase || "zzzz"
end
|
#subclause?(target, type, from) ⇒ Boolean
36
37
38
39
|
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 36
def subclause?(target, type, from)
(from&.match?(/\./) && type == "clause") ||
target&.gsub(/<[^>]+>/, "")&.match(/^IEV$|^IEC 60050-/)
end
|
#term(docxml) ⇒ Object
245
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 245
def term(docxml); end
|
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 56
def term_related_collapse(coll)
prev = 0
coll[1..-1].each_with_index do |r, i|
if coll[prev]["type"] != r["type"]
prev = i and next
end
coll[prev].at(ns("./preferred")) << "; #{to_xml(r.at(ns('./preferred'))
.children)}"
r.remove
end
end
|
86
87
88
89
90
91
92
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 86
def term_related_reorder(coll)
ins = coll.first.previous_element
ret = sort_related(coll)
coll.each(&:remove)
ret.reverse.each { |t| ins.next = t }
ins.parent.xpath(ns("./related"))
end
|
#term_reorder(xmldoc) ⇒ Object
139
140
141
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 139
def term_reorder(xmldoc)
xmldoc.xpath(ns("//terms")).each { |t| term_reorder1(t) }
end
|
#term_reorder1(terms) ⇒ Object
143
144
145
146
147
148
149
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 143
def term_reorder1(terms)
ins = terms.at(ns("./term"))&.previous_element or return
coll = terms.xpath(ns("./term"))
ret = sort_terms(coll)
coll.each(&:remove)
ret.reverse.each { |t| ins.next = t }
end
|
#termnote1(elem) ⇒ Object
240
241
242
243
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 240
def termnote1(elem)
lbl = l10n(@xrefs.anchor(elem["id"], :label)&.strip || "???")
prefix_name(elem, block_delim, lower2cap(lbl), "name")
end
|
#terms(docxml) ⇒ Object
111
112
113
114
115
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 111
def terms(docxml)
admitted_to_related docxml
super
collapse_term docxml
end
|
#termsource1(elem) ⇒ Object
205
206
207
208
209
210
211
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 205
def termsource1(elem)
while elem&.next_element&.name == "termsource"
elem << "; #{to_xml(elem.next_element.remove.children)}"
end
adapt = termsource_adapt(elem["status"]) and
elem.children = l10n("#{adapt}#{to_xml(elem.children).strip}")
end
|
#termsource_adapt(status) ⇒ Object
213
214
215
216
217
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 213
def termsource_adapt(status)
case status
when "adapted" then @i18n.adapted_from
end
end
|
#unwrap_definition(docxml) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 35
def unwrap_definition(docxml)
docxml.xpath(ns(".//definition/verbal-definition")).each do |v|
next unless v.elements.all? { |e| %w(termsource p).include?(e.name) }
p = v.xpath(ns("./p"))
v.children =
"<p>#{p.map(&:children).map { |x| to_xml(x) }.join("\n")}</p>" \
"#{v.xpath(ns('./termsource')).to_xml}"
end
super
end
|
#unwrap_multidef(coll) ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/isodoc/ieee/presentation_terms.rb', line 25
def unwrap_multidef(coll)
if coll.all? do |c|
c.elements.size == 1 && c.elements.first.name == "p"
end
ret = coll.map { |c| to_xml(c.elements.first.children) }
return "<p>#{ret.join}</p>"
end
coll.map { |c| to_xml(c.children) }.join
end
|