Class: IsoDoc::Bipm::PresentationXMLConvert
- Inherits:
-
Generic::PresentationXMLConvert
- Object
- Generic::PresentationXMLConvert
- IsoDoc::Bipm::PresentationXMLConvert
show all
- Includes:
- Init
- Defined in:
- lib/isodoc/bipm/presentation_biblio.rb,
lib/isodoc/bipm/presentation_blocks.rb,
lib/isodoc/bipm/presentation_footnotes.rb,
lib/isodoc/bipm/presentation_doccontrol.rb,
lib/isodoc/bipm/presentation_xml_convert.rb
Constant Summary
collapse
- COCHAIR =
"xmlns:role[contains(text(),'co-chair')]".freeze
- CHAIR =
"[xmlns:role[contains(text(),'chair')]" \
"[not(contains(text(),'co-chair'))]]".freeze
- BLACKSQUARE =
'<span style="font-size:130%">■</span>  '.freeze
Instance Method Summary
collapse
-
#annex_delim(elem) ⇒ Object
-
#bibdata_dates(bibdata) ⇒ Object
-
#bibdata_depictions(bibdata) ⇒ Object
-
#bibdata_i18n(bibdata) ⇒ Object
-
#bibdata_id(bibdata) ⇒ Object
-
#bibdata_id1(lang, id, parts, alt) ⇒ Object
-
#bibdata_logo_committee(bibdata) ⇒ Object
-
#bibdata_logo_publisher(bibdata) ⇒ Object
-
#bibdata_logos(bibdata) ⇒ Object
-
#bibdata_part_titles(bibdata, num) ⇒ Object
-
#bibdata_subpart_titles(bibdata, num) ⇒ Object
-
#bibdata_titles(bibdata) ⇒ Object
-
#biblio_ref_entry_code(ordinal, ids, _standard, datefn, _bib) ⇒ Object
-
#clause(docxml) ⇒ Object
-
#clause1(elem) ⇒ Object
-
#conversions(docxml) ⇒ Object
-
#convert1(docxml, filename, dir) ⇒ Object
-
#convert_i18n_init(docxml) ⇒ Object
-
#doccontrol(doc) ⇒ Object
-
#doccontrol_row1(doc) ⇒ Object
-
#doccontrol_row2(docxml) ⇒ Object
-
#document_footnotes(docxml) ⇒ Object
-
#eref(docxml) ⇒ Object
-
#eref_localities1(opt) ⇒ Object
-
#explode_subclauses(clause) ⇒ Object
-
#extract_brackets(node) ⇒ Object
-
#figure1(elem) ⇒ Object
-
#filter_document_footnotes(sects, excl) ⇒ Object
-
#fn_body_label(fnote) ⇒ Object
-
#fn_label_brackets(fnote) ⇒ Object
-
#fn_ref_label(fnote) ⇒ Object
-
#i18n_conditional_set(i18n, old, new) ⇒ Object
-
#implicit_reference(bib) ⇒ Object
-
#index1(docxml, indexsect, index) ⇒ Object
-
#initialize(options) ⇒ PresentationXMLConvert
constructor
A new instance of PresentationXMLConvert.
-
#iso_fn_ref_label(fnote) ⇒ Object
-
#iso_processor(docxml) ⇒ Object
-
#jcgm_eref(docxml, xpath) ⇒ Object
-
#list_authors(xml) ⇒ Object
-
#list_chairs(xml) ⇒ Object
-
#list_cochairs(xml) ⇒ Object
-
#list_draft(xml, idx) ⇒ Object
-
#list_drafts(xml) ⇒ Object
-
#list_people(xml, xpath) ⇒ Object
-
#localize_maths(node, locale) ⇒ Object
-
#mathml1(node, locale) ⇒ Object
-
#middle_title(docxml) ⇒ Object
-
#norm_ref_entry_code(_ordinal, identifiers, _standard, datefn, _bib) ⇒ Object
-
#note1(elem) ⇒ Object
notes and remarques (list notes) are not numbered.
-
#note_delim(_elem) ⇒ Object
-
#note_label(elem) ⇒ Object
-
#ol_label_template(_elem) ⇒ Object
-
#omit_docid_prefix(prefix) ⇒ Object
-
#origin(docxml) ⇒ Object
-
#prefix_name(node, delims, number, elem, fmt_xref_label: true) ⇒ Object
-
#quoted_title_render(node, elem, variant_title) ⇒ Object
-
#reference_name(ref) ⇒ Object
-
#render_identifier(ident) ⇒ Object
-
#renumber_document_footnote(fnote, idx, seen) ⇒ Object
-
#renumber_document_footnote_key(fnote) ⇒ Object
quote/table/fn references are not unique within quote if there are multiple tables.
-
#renumber_document_footnotes(fns, idx) ⇒ Object
-
#sort_footnote_sections(docxml) ⇒ Object
explode out all the subclauses into separate entries assume no hanging clauses.
-
#table_delim ⇒ Object
-
#table_fn(elem) ⇒ Object
-
#table_footnotes(docxml) ⇒ Object
-
#termsource(docxml) ⇒ Object
-
#termsource_adapt(status) ⇒ Object
-
#termsource_insert_empty_modification(docxml) ⇒ Object
-
#termsource_label(elem, sources) ⇒ Object
-
#termsource_modification(elem) ⇒ Object
-
#twitter_cldr_localiser_symbols ⇒ Object
-
#ul_label_list(_elem) ⇒ Object
-
#update_i18n(i18n) ⇒ Object
-
#wrap_brackets(txt) ⇒ Object
Methods included from Init
#amd?, #bibrenderer, #i18n_init, #metadata_init, #xref_init
Constructor Details
Returns a new instance of PresentationXMLConvert.
14
15
16
17
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 14
def initialize(options)
super
@libdir = File.dirname(__FILE__)
end
|
Instance Method Details
#annex_delim(elem) ⇒ Object
64
65
66
67
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 64
def annex_delim(elem)
@jcgm and return super
".<tab/>"
end
|
#bibdata_dates(bibdata) ⇒ Object
78
79
80
81
82
83
84
85
|
# File 'lib/isodoc/bipm/presentation_biblio.rb', line 78
def bibdata_dates(bibdata)
pubdate = bibdata.at(ns("./date[not(@format)][@type = 'published']"))
pubdate or return
meta = metadata_init(@lang, @script, @locale, @i18n)
pubdate.next = pubdate.dup
pubdate.next["format"] = "ddMMMyyyy"
pubdate.next.children = meta.monthyr(pubdate.text)
end
|
#bibdata_depictions(bibdata) ⇒ Object
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/isodoc/bipm/presentation_biblio.rb', line 43
def bibdata_depictions(bibdata)
s = bibdata.at(ns("./ext/si-aspect"))&.text or return
ins = bibdata.at(ns("./ext"))
name = "si-circle-constants_#{s}.svg"
s.start_with?("units") and name = "si-circle-#{s}.svg"
file = svg_load("si-aspect", name) or return
ins.previous = <<~XML
<depiction type='si-aspect'><image src="" mimetype="image/svg+xml">#{file}</image></depiction>
XML
end
|
#bibdata_i18n(bibdata) ⇒ Object
4
5
6
7
8
9
10
11
|
# File 'lib/isodoc/bipm/presentation_biblio.rb', line 4
def bibdata_i18n(bibdata)
super
bibdata_id(bibdata)
bibdata_dates(bibdata)
bibdata_titles(bibdata)
bibdata_depictions(bibdata)
bibdata_logos(bibdata)
end
|
#bibdata_id(bibdata) ⇒ Object
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/isodoc/bipm/presentation_biblio.rb', line 54
def bibdata_id(bibdata)
id = bibdata.at(ns("./docidentifier[@type = 'BIPM-parent-document']")) or
return
parts = %w(appendix annexid part subpart).each_with_object([]) do |w, m|
dn = bibdata.at(ns("./ext/structuredidentifier/#{w}"))
m << dn&.text
end
id.next = bibdata_id1(@lang, id.dup, parts, false)
id.next = bibdata_id1(@lang == "en" ? "fr" : "en", id.dup, parts, true)
end
|
#bibdata_id1(lang, id, parts, alt) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/isodoc/bipm/presentation_biblio.rb', line 65
def bibdata_id1(lang, id, parts, alt)
id["type"] = "BIPM"
id["language"] = lang
m = []
parts.each_with_index do |p, i|
p.nil? and next
lbl = @i18n.get["level#{i + 2}_ancillary#{alt ? '_alt' : ''}"]
m << "#{lbl} #{p}"
end
id.children = "#{id.text} #{m.join(' ')}"
id
end
|
#bibdata_logo_committee(bibdata) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/isodoc/bipm/presentation_biblio.rb', line 29
def bibdata_logo_committee(bibdata)
bibdata.xpath(ns("./contributor[role/@type = 'author']" \
"[role/description = 'committee']/organization/" \
"subdivision[@type = 'Committee']")).each do |com|
com.xpath(ns("./identifier[not(@type = 'full')]")).each do |a|
filename = "bipm-logo_#{a.text.downcase}.svg"
file = svg_load("logo", filename) or next
com << <<~XML
<logo><image src="" mimetype="image/svg+xml">#{file}</image></logo>
XML
end
end
end
|
#bibdata_logo_publisher(bibdata) ⇒ Object
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/isodoc/bipm/presentation_biblio.rb', line 18
def bibdata_logo_publisher(bibdata)
bipm = bibdata.at(ns("./contributor[role/@type = 'publisher']/" \
"organization[abbreviation = 'BIPM']")) or return
logo_full = svg_load("logo", "bipm-logo_full.svg")
logo_small = svg_load("logo", "bipm-logo_bipm.svg")
bipm << <<~XML
<logo type="full"><image src="" mimetype="image/svg+xml">#{logo_full}</image></logo>
<logo type="small"><image src="" mimetype="image/svg+xml">#{logo_small}</image></logo>
XML
end
|
#bibdata_logos(bibdata) ⇒ Object
13
14
15
16
|
# File 'lib/isodoc/bipm/presentation_biblio.rb', line 13
def bibdata_logos(bibdata)
bibdata_logo_publisher(bibdata)
bibdata_logo_committee(bibdata)
end
|
#bibdata_part_titles(bibdata, num) ⇒ Object
94
95
96
97
98
99
100
101
102
|
# File 'lib/isodoc/bipm/presentation_biblio.rb', line 94
def bibdata_part_titles(bibdata, num)
bibdata.xpath(ns("//bibdata/title[@type = 'title-part']")).each do |t|
t.previous = t.dup
t["type"] = "title-part-with-numbering"
alt = t["language"] == @lang ? "" : "_alt"
t.children = l10n("#{@i18n.get["level4_ancillary#{alt}"]} #{num}: #{to_xml(t.children)}",
t["language"])
end
end
|
#bibdata_subpart_titles(bibdata, num) ⇒ Object
104
105
106
107
108
109
110
111
112
|
# File 'lib/isodoc/bipm/presentation_biblio.rb', line 104
def bibdata_subpart_titles(bibdata, num)
bibdata.xpath(ns("//bibdata/title[@type = 'title-subpart']")).each do |t|
t.previous = t.dup
t["type"] = "title-subpart-with-numbering"
alt = t["language"] == @lang ? "" : "_alt"
t.children = l10n("#{@i18n.get["level5_ancillary#{alt}"]} #{num}: #{to_xml(t.children)}",
t["language"])
end
end
|
#bibdata_titles(bibdata) ⇒ Object
87
88
89
90
91
92
|
# File 'lib/isodoc/bipm/presentation_biblio.rb', line 87
def bibdata_titles(bibdata)
app = bibdata.at(ns("//bibdata/ext/structuredidentifier/part")) or
return
bibdata_part_titles(bibdata, app.text.sub(/\.\d+/, ""))
bibdata_subpart_titles(bibdata, app.text.sub(/\d+\./, ""))
end
|
#biblio_ref_entry_code(ordinal, ids, _standard, datefn, _bib) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/isodoc/bipm/presentation_biblio.rb', line 120
def biblio_ref_entry_code(ordinal, ids, _standard, datefn, _bib)
ret = ids[:ordinal] || ids[:content] || ids[:metanorma] || "[#{ordinal}]"
if ids[:sdo]
ret = prefix_bracketed_ref(ret)
ret += "#{ids[:sdo]}#{datefn} "
else
ret = prefix_bracketed_ref("#{ret}#{datefn}")
end
ret
end
|
#clause(docxml) ⇒ Object
69
70
71
72
73
74
75
76
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 69
def clause(docxml)
super
@jcgm and
docxml.xpath(ns("//preface/introduction[clause]")).each do |f|
clause1(f)
end
end
|
#clause1(elem) ⇒ Object
78
79
80
81
82
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 78
def clause1(elem)
elem.at("./ancestor::*[@unnumbered = 'true']") and
elem["unnumbered"] = "true"
super
end
|
#conversions(docxml) ⇒ Object
108
109
110
111
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 108
def conversions(docxml)
doccontrol docxml
super
end
|
#convert1(docxml, filename, dir) ⇒ Object
19
20
21
22
23
24
25
26
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 19
def convert1(docxml, filename, dir)
@jcgm = docxml.at(ns(<<~XPATH))&.text == "JCGM"
//bibdata/contributor[role/description = 'committee']/organization/subdivision[@type = 'Committee']/identifier[not(@type = 'full')]
XPATH
@xrefs.klass.jcgm = @jcgm
@jcgm and @iso = iso_processor(docxml)
super
end
|
#convert_i18n_init(docxml) ⇒ Object
39
40
41
42
43
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 39
def convert_i18n_init(docxml)
@docscheme ||= "2021"
super
update_i18n(@i18n)
end
|
#doccontrol(doc) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/isodoc/bipm/presentation_doccontrol.rb', line 4
def doccontrol(doc)
doc.at(ns("//bibdata/relation[@type = 'supersedes']")) or return
clause = <<~DOCCONTROL
<clause class="doccontrol" #{add_id_text}>
<fmt-title #{add_id_text}>Document Control</fmt-title>
<table #{add_id_text} unnumbered="true"><tbody>
<tr #{add_id_text}><th #{add_id_text}>Authors:</th><td #{add_id_text}/><td #{add_id_text}>#{list_authors(doc)}</td></tr>
#{doccontrol_row1(doc)} #{doccontrol_row2(doc)} #{list_drafts(doc)}
</tbody></table></clause>
DOCCONTROL
ins = doc.root.at(ns("./colophon")) ||
doc.root.add_child("<colophon/>").first
ins << clause
end
|
#doccontrol_row1(doc) ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'lib/isodoc/bipm/presentation_doccontrol.rb', line 19
def doccontrol_row1(doc)
return "" if list_draft(doc,
1) == ["", ""] && list_cochairs(doc).empty?
<<~ROW
<tr #{add_id_text}>#{list_draft(doc, 1)&.map { |x| "<td #{add_id_text}>#{x}</td>" }&.join}
<td #{add_id_text}>#{list_cochairs(doc)}</td></tr>
ROW
end
|
#doccontrol_row2(docxml) ⇒ Object
29
30
31
32
33
34
35
36
37
|
# File 'lib/isodoc/bipm/presentation_doccontrol.rb', line 29
def doccontrol_row2(docxml)
list_draft(docxml, 2) == ["", ""] && list_chairs(docxml).empty? and
return ""
<<~ROW
<tr #{add_id_text}>#{list_draft(docxml, 2)&.map { |x| "<td>#{x}</td>" }&.join}
<td #{add_id_text}>#{list_chairs(docxml)}</td></tr>
ROW
end
|
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/isodoc/bipm/presentation_footnotes.rb', line 71
def (docxml)
@jcgm and return super
sects = (docxml)
excl = (docxml)
fns = (sects, excl)
sects.each_with_index do |s, i|
ret = ((fns[i], 1))
f = (fns[i], ret) and s << f
end
end
|
#eref(docxml) ⇒ Object
142
143
144
145
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 142
def eref(docxml)
super
jcgm_eref(docxml, "//fmt-eref")
end
|
#eref_localities1(opt) ⇒ Object
59
60
61
62
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 59
def eref_localities1(opt)
@jcgm and return @iso.eref_localities1(opt)
super
end
|
#explode_subclauses(clause) ⇒ Object
42
43
44
45
46
47
|
# File 'lib/isodoc/bipm/presentation_footnotes.rb', line 42
def explode_subclauses(clause)
clause.at(ns(".//clause")) or return [clause]
(clause.xpath(ns(".//clause")) - clause.xpath(ns(".//clause//clause")))
.map { |x| explode_subclauses(x) }
.flatten.unshift(clause)
end
|
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 166
def (node)
start = node.at("./text()[1]")
finish = node.at("./text()[last()]")
(/^\[/.match?(start&.text) && /\]$/.match?(finish&.text)) or return
start.replace(start.text[1..-1])
node.previous = "["
finish = node.at("./text()[last()]")
finish.replace(finish.text[0..-2])
node.next = "]"
end
|
13
14
15
16
17
18
19
|
# File 'lib/isodoc/bipm/presentation_blocks.rb', line 13
def figure1(elem)
if @jcgm
@iso.xrefs = @xrefs
@iso.figure1(elem)
else super
end
end
|
82
83
84
85
86
87
|
# File 'lib/isodoc/bipm/presentation_footnotes.rb', line 82
def (sects, excl)
sects.each_with_object([]) do |s, m|
docfns = s.xpath(ns(".//fn")) - excl - s.xpath(ns(".//clause//fn"))
m << docfns
end
end
|
#fn_body_label(fnote) ⇒ Object
27
28
29
30
31
|
# File 'lib/isodoc/bipm/presentation_footnotes.rb', line 27
def fn_body_label(fnote)
if @jcgm then super
else fn_label_brackets(fnote)
end
end
|
#fn_label_brackets(fnote) ⇒ Object
4
5
6
7
8
|
# File 'lib/isodoc/bipm/presentation_footnotes.rb', line 4
def fn_label_brackets(fnote)
"<sup><span class='fmt-label-delim'>(</span>" \
"#{fn_label(fnote)}" \
"<span class='fmt-label-delim'>)</span></sup>"
end
|
#fn_ref_label(fnote) ⇒ Object
10
11
12
13
14
|
# File 'lib/isodoc/bipm/presentation_footnotes.rb', line 10
def fn_ref_label(fnote)
if @jcgm then iso_fn_ref_label(fnote)
else fn_label_brackets(fnote)
end
end
|
#i18n_conditional_set(i18n, old, new) ⇒ Object
45
46
47
48
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 45
def i18n_conditional_set(i18n, old, new)
i18n.get[new] or return
i18n.set(old, i18n.get[new])
end
|
#implicit_reference(bib) ⇒ Object
132
133
134
135
136
137
138
139
|
# File 'lib/isodoc/bipm/presentation_biblio.rb', line 132
def implicit_reference(bib)
b = bib.at(ns("./docidentifier[@primary = 'true'][@type = 'BIPM']"))
return true if @doctype == "brochure" && /^(CGPM|CIPM|CCDS|CCTF)[ ]
(Resolution|Recommendation|Declaration|Decision|Recommendation|Meeting)/x
.match?(b&.text)
super
end
|
#index1(docxml, indexsect, index) ⇒ Object
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 177
def index1(docxml, indexsect, index)
index.keys.sort.each do |k|
c = indexsect
.add_child "<clause #{add_id_text}><title #{add_id_text}>#{k}</title><ul></ul></clause>"
words = index[k].keys.each_with_object({}) do |w, v|
v[sortable(w).downcase] = w
end
words.keys.localize(@lang.to_sym).sort.to_a.each do |w|
c.first.at(ns("./ul")).add_child index_entries(words, index[k], w)
end
end
docxml.xpath(ns("//indexsect//xref")).each { |x| x.children.remove }
@xrefs.bookmark_anchor_names(docxml)
end
|
#iso_fn_ref_label(fnote) ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/isodoc/bipm/presentation_footnotes.rb', line 17
def iso_fn_ref_label(fnote)
if fnote.ancestors("table, figure").empty? ||
!fnote.ancestors("name, fmt-name").empty?
"<sup>#{fn_label(fnote)}" \
"<span class='fmt-label-delim'>)</span></sup>"
else
"<sup>#{fn_label(fnote)}</sup>"
end
end
|
#iso_processor(docxml) ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 50
def iso_processor(docxml)
iso = IsoDoc::Iso::PresentationXMLConvert
.new({ language: @lang, script: @script })
i18n = iso.i18n_init(@lang, @script, @locale, nil)
iso.metadata_init(@lang, @script, @locale, i18n)
iso.info(docxml, nil)
iso
end
|
#jcgm_eref(docxml, xpath) ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 152
def jcgm_eref(docxml, xpath)
@jcgm or return
docxml.xpath(ns(xpath)).each { |x| (x) }
docxml.root.replace(Nokogiri::XML(docxml.root.to_xml).root)
docxml.xpath(ns(xpath)).each do |x| if x.parent.next&.text? && /^\],\s+\[$/.match?(x.parent.next.text) &&
%w(eref origin fmt-eref
fmt-origin).include?(x.parent.next.next&.name)
x.parent.next.replace(", ")
end
end
end
|
#list_authors(xml) ⇒ Object
60
61
62
63
64
65
|
# File 'lib/isodoc/bipm/presentation_doccontrol.rb', line 60
def list_authors(xml)
ret = list_people(
xml, "//bibdata/contributor[xmlns:role/@type = 'author']/person"
)
connectives_spans(@i18n.boolean_conj(ret, "and"))
end
|
#list_chairs(xml) ⇒ Object
79
80
81
82
83
84
85
|
# File 'lib/isodoc/bipm/presentation_doccontrol.rb', line 79
def list_chairs(xml)
ret = list_people(xml, "//bibdata/contributor#{CHAIR}/person")
ret.empty? and return ""
role = xml&.at(ns("//bibdata/contributor#{CHAIR}/role"))&.text
label = ret.size > 1 && role ? "#{role}s" : role
"#{label}: #{connectives_spans(@i18n.boolean_conj(ret, 'and'))}"
end
|
#list_cochairs(xml) ⇒ Object
71
72
73
74
75
76
77
|
# File 'lib/isodoc/bipm/presentation_doccontrol.rb', line 71
def list_cochairs(xml)
ret = list_people(xml, "//bibdata/contributor[#{COCHAIR}]/person")
ret.empty? and return ""
role = xml&.at(ns("//bibdata/contributor[#{COCHAIR}]/role"))&.text
label = ret.size > 1 && role ? "#{role}s" : role
"#{label}: #{connectives_spans(@i18n.boolean_conj(ret, 'and'))}"
end
|
#list_draft(xml, idx) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/isodoc/bipm/presentation_doccontrol.rb', line 52
def list_draft(xml, idx)
d = xml.at(ns("//bibdata/relation[@type = 'supersedes'][#{idx}]" \
"/bibitem")) or return ["", ""]
draft = d.at(ns("./version/draft"))&.text and draft = "Draft #{draft}"
edn = d.at(ns("./edition"))&.text and edn = "Version #{edn}"
[[draft, edn].join(" "), d.at(ns("./date"))&.text]
end
|
#list_drafts(xml) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/isodoc/bipm/presentation_doccontrol.rb', line 39
def list_drafts(xml)
ret = ""
i = 3
while list_draft(xml, i) != ["", ""]
ret += "<tr #{add_id_text}>#{list_draft(xml, i).map do |x|
"<td #{add_id_text}>#{x}</td>"
end.join} " \
"<td/></tr>"
i += 1
end
ret
end
|
#list_people(xml, xpath) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/isodoc/bipm/presentation_doccontrol.rb', line 87
def list_people(xml, xpath)
ret = []
xml.xpath(ns(xpath)).each do |p|
name = p.at(ns("./name/completename"))&.text
aff = p.at(ns("./affiliation/organization/abbreviation"))&.text ||
p.at(ns("./affiliation/organization/name"))&.text
c = name || ""
aff and c += " (#{aff})"
ret << c
end
ret
end
|
#localize_maths(node, locale) ⇒ Object
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 118
def localize_maths(node, locale)
super
node.xpath(".//m:mn", MATHML).each do |x|
x.children = x.text
.sub(/^(\d)#{@cldr[:g]}(\d) (?= \d\d$ | \d\d#{@cldr[:d]} )/x,
"\\1\\2")
.sub(/(?<= ^\d\d | #{@cldr[:d]}\d\d ) (\d)#{@cldr[:f]}(\d) $/x,
"\\1\\2")
end
end
|
#mathml1(node, locale) ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 129
def mathml1(node, locale)
unless @cldr
r = @numfmt.(locale: locale)
.transform_values { |v| @c.decode(v) }
@cldr = {
g: Regexp.quote(r[:group]),
f: Regexp.quote(r[:fraction_group]),
d: Regexp.quote(r[:decimal]),
}
end
super
end
|
#middle_title(docxml) ⇒ Object
4
5
6
7
|
# File 'lib/isodoc/bipm/presentation_blocks.rb', line 4
def middle_title(docxml)
@jcgm or return nil
@iso.middle_title(docxml)
end
|
#norm_ref_entry_code(_ordinal, identifiers, _standard, datefn, _bib) ⇒ Object
114
115
116
117
118
|
# File 'lib/isodoc/bipm/presentation_biblio.rb', line 114
def norm_ref_entry_code(_ordinal, identifiers, _standard, datefn, _bib)
ret = unbracket1(identifiers[:metanorma]) || identifiers[:sdo]
ret += " #{identifiers[:sdo]}" if identifiers[:metanorma] && identifiers[:sdo]
"#{ret}#{datefn} "
end
|
#note1(elem) ⇒ Object
notes and remarques (list notes) are not numbered
26
27
28
29
30
|
# File 'lib/isodoc/bipm/presentation_blocks.rb', line 26
def note1(elem)
elem.parent.name == "bibitem" || elem["notag"] == "true" and return
lbl = l10n(note_label(elem))
prefix_name(elem, { label: note_delim(elem) }, lbl, "name")
end
|
#note_delim(_elem) ⇒ Object
21
22
23
|
# File 'lib/isodoc/bipm/presentation_blocks.rb', line 21
def note_delim(_elem)
l10n("x:<tab/>").sub("x", "") end
|
#note_label(elem) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/isodoc/bipm/presentation_blocks.rb', line 32
def note_label(elem)
if elem.ancestors("preface").empty?
if elem.ancestors("ul, ol, dl").empty?
@i18n.note
else @i18n.listnote end
else @i18n.prefacenote
end
end
|
#ol_label_template(_elem) ⇒ Object
73
74
75
76
77
78
79
|
# File 'lib/isodoc/bipm/presentation_blocks.rb', line 73
def ol_label_template(_elem)
super.merge({
roman: %{<span class="fmt-label-delim">(</span>% \
<span class="fmt-label-delim">)</span>},
arabic: %{%<span class="fmt-label-delim">.</span>},
})
end
|
#omit_docid_prefix(prefix) ⇒ Object
141
142
143
144
|
# File 'lib/isodoc/bipm/presentation_biblio.rb', line 141
def omit_docid_prefix(prefix)
%w(BIPM BIPM-long).include? prefix and return true
super
end
|
#origin(docxml) ⇒ Object
147
148
149
150
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 147
def origin(docxml)
super
jcgm_eref(docxml, "//fmt-origin[not(.//termref)]")
end
|
#prefix_name(node, delims, number, elem, fmt_xref_label: true) ⇒ Object
84
85
86
87
88
89
90
91
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 84
def prefix_name(node, delims, number, elem, fmt_xref_label: true)
if elem == "title" &&
n = node.at(ns("./variant-#{elem}[@type = 'quoted']"))
quoted_title_render(node, elem, n)
else
super
end
end
|
#quoted_title_render(node, elem, variant_title) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 96
def quoted_title_render(node, elem, variant_title)
add_id(variant_title)
variant_title.next =
fmt_caption(BLACKSQUARE, elem, variant_title, {}, {})
if s = variant_title.next.at(ns("./semx[@element='title']"))
s["source"] = variant_title["id"]
end
variant_title.name = "title"
prefix_name_postprocess(node, elem)
end
|
#reference_name(ref) ⇒ Object
157
158
159
160
161
|
# File 'lib/isodoc/bipm/presentation_biblio.rb', line 157
def reference_name(ref)
super
@jcgm and @xrefs.get[ref["id"]][:xref] =
wrap_brackets(@xrefs.get[ref["id"]][:xref])
end
|
#render_identifier(ident) ⇒ Object
146
147
148
149
150
151
|
# File 'lib/isodoc/bipm/presentation_biblio.rb', line 146
def render_identifier(ident)
ret = super
ret[:sdo] = ret[:sdo]&.sub(/^(BIPM)([ ])(PV|CR)([ ])(\d.*)$/,
"\\1\\2<strong>\\3</strong>,\\4\\5")
ret
end
|
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/isodoc/bipm/presentation_footnotes.rb', line 58
def (fnote, idx, seen)
fnote["original-reference"] = fnote["reference"]
key = (fnote)
if seen[key]
fnote["reference"] = seen[key]
else
seen[key] = idx
fnote["reference"] = idx
idx += 1
end
idx
end
|
quote/table/fn references are not unique within quote if there are multiple tables
51
52
53
54
55
56
|
# File 'lib/isodoc/bipm/presentation_footnotes.rb', line 51
def (fnote)
key = fnote["reference"]
!@jcgm && (t = fnote.at("./ancestor::xmlns:table")) and
key = "#{t['id']} #{key}"
key
end
|
89
90
91
92
93
94
95
|
# File 'lib/isodoc/bipm/presentation_footnotes.rb', line 89
def (fns, idx)
@jcgm and return super
fns.each_with_object({}) do |f, seen|
idx = (f, idx, seen)
end
fns
end
|
explode out all the subclauses into separate entries assume no hanging clauses
35
36
37
38
39
40
|
# File 'lib/isodoc/bipm/presentation_footnotes.rb', line 35
def (docxml)
ret = super
ret.flat_map do |x|
explode_subclauses(x)
end
end
|
#table_delim ⇒ Object
9
10
11
|
# File 'lib/isodoc/bipm/presentation_blocks.rb', line 9
def table_delim
l10n("x.<tab/>").sub("x", "") end
|
#table_fn(elem) ⇒ Object
97
98
99
100
|
# File 'lib/isodoc/bipm/presentation_footnotes.rb', line 97
def table_fn(elem)
!@jcgm && !elem.ancestors("quote").empty? and return
super
end
|
102
103
104
105
106
107
108
|
# File 'lib/isodoc/bipm/presentation_footnotes.rb', line 102
def (docxml)
table_fns = docxml.xpath(ns("//table//fn")) -
docxml.xpath(ns("//table/name//fn")) -
docxml.xpath(ns("//table/fmt-name//fn"))
@jcgm or table_fns -= docxml.xpath(ns("//quote//table//fn"))
table_fns
end
|
#termsource(docxml) ⇒ Object
53
54
55
56
|
# File 'lib/isodoc/bipm/presentation_blocks.rb', line 53
def termsource(docxml)
termsource_insert_empty_modification(docxml)
super
end
|
#termsource_adapt(status) ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/isodoc/bipm/presentation_blocks.rb', line 45
def termsource_adapt(status)
case status
when "adapted" then @i18n.adapted_from
when "modified" then @i18n.modified_from
else ""
end
end
|
#termsource_insert_empty_modification(docxml) ⇒ Object
58
59
60
61
62
63
|
# File 'lib/isodoc/bipm/presentation_blocks.rb', line 58
def termsource_insert_empty_modification(docxml)
docxml.xpath("//xmlns:term//xmlns:source[@status = 'modified']" \
"[not(xmlns:modification)]").each do |f|
f << "<modification/>"
end
end
|
#termsource_label(elem, sources) ⇒ Object
41
42
43
|
# File 'lib/isodoc/bipm/presentation_blocks.rb', line 41
def termsource_label(elem, sources)
elem.replace(l10n("[#{termsource_adapt(elem['status'])} #{sources}]"))
end
|
#termsource_modification(elem) ⇒ Object
65
66
67
|
# File 'lib/isodoc/bipm/presentation_blocks.rb', line 65
def termsource_modification(elem)
termsource_add_modification_text(elem.at(ns("./modification")))
end
|
113
114
115
116
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 113
def
{ group: " ", fraction_group: " ",
fraction_group_digits: 3 }
end
|
#ul_label_list(_elem) ⇒ Object
69
70
71
|
# File 'lib/isodoc/bipm/presentation_blocks.rb', line 69
def ul_label_list(_elem)
%w(• − o)
end
|
#update_i18n(i18n) ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/isodoc/bipm/presentation_xml_convert.rb', line 28
def update_i18n(i18n)
if %w(2019).include?(@docscheme)
%w(level2_ancillary level3_ancillary level2_ancillary_alt
level3_ancillary_alt).each do |w|
i18n_conditional_set(i18n, w, "#{w}_2019")
end
end
i18n.set("annex", i18n.get["level2_ancillary"])
i18n.set("appendix", i18n.get["level3_ancillary"])
end
|
#wrap_brackets(txt) ⇒ Object
153
154
155
|
# File 'lib/isodoc/bipm/presentation_biblio.rb', line 153
def wrap_brackets(txt)
/^\[.*\]$/.match?(txt) ? txt : "[#{txt}]"
end
|