Class: IsoDoc::Itu::PresentationXMLConvert
- Inherits:
-
PresentationXMLConvert
- Object
- PresentationXMLConvert
- IsoDoc::Itu::PresentationXMLConvert
show all
- Includes:
- Init
- Defined in:
- lib/isodoc/itu/presentation_ref.rb,
lib/isodoc/itu/presentation_bibdata.rb,
lib/isodoc/itu/presentation_preface.rb,
lib/isodoc/itu/presentation_section.rb,
lib/isodoc/itu/presentation_xml_convert.rb,
lib/isodoc/itu/presentation_contribution.rb
Instance Method Summary
collapse
-
#abstract_render(abstract) ⇒ Object
-
#amendment_id(bib) ⇒ Object
-
#annex1(elem) ⇒ Object
-
#annex1_non_resolution(elem) ⇒ Object
-
#annex1_resolution(elem) ⇒ Object
-
#annex1_supertitle(elem) ⇒ Object
-
#bibdata_dates(bib) ⇒ Object
-
#bibdata_i18n(bib) ⇒ Object
-
#bibdata_title(bib) ⇒ Object
-
#bibdata_title_resolution(bib) ⇒ Object
-
#bibdata_title_resolution_name(bib, place, year) ⇒ Object
-
#bibdata_title_service_population(bib) ⇒ Object
-
#biblio_ref_entry_code(_ordinal, idents, _id, _standard, datefn, _bib) ⇒ Object
-
#bibliography_bibitem_number1(bib, idx, normative) ⇒ Object
-
#bibliography_bibitem_number_skip(bibitem) ⇒ Object
-
#bibrender_formattedref(formattedref, _xml) ⇒ Object
-
#bibrender_relaton(xml, renderings) ⇒ Object
-
#bold_and_upcase(xml) ⇒ Object
-
#bracket_if_num(num) ⇒ Object
-
#bracket_opt(text) ⇒ Object
-
#capitalise_unless_text_transform(elem) ⇒ Object
-
#clause1(elem) ⇒ Object
-
#clause1_super?(elem) ⇒ Boolean
-
#colon_i18n(text) ⇒ Object
-
#contrib_justification_contacts ⇒ Object
-
#contribution_justification(doc) ⇒ Object
-
#contribution_justification_auths ⇒ Object
-
#contribution_justification_contact(idx) ⇒ Object
-
#contribution_justification_title(_doc) ⇒ Object
-
#contribution_table(_doc) ⇒ Object
-
#contribution_table_contact(idx) ⇒ Object
-
#contribution_table_contacts ⇒ Object
-
#contribution_table_insert_pt(docxml) ⇒ Object
-
#ddmmmmyyyy(date) ⇒ Object
-
#ddMMMyyyy(date) ⇒ Object
-
#designation(docxml) ⇒ Object
-
#designation1(desgn) ⇒ Object
-
#dl(xml) ⇒ Object
-
#dl2(dlist) ⇒ Object
-
#doctype_title(id, bib) ⇒ Object
-
#editor_table_entries(eds, ed_lbl, mail_lbl) ⇒ Object
-
#editors_clause(eds) ⇒ Object
-
#editors_insert_pt(docxml) ⇒ Object
-
#eref(docxml) ⇒ Object
-
#eref1(elem) ⇒ Object
-
#extract_clause_data(clause, type) ⇒ Object
-
#extract_editors(doc) ⇒ Object
-
#fn_body_label(fnote) ⇒ Object
-
#fn_ref_label(fnote) ⇒ Object
-
#get_eref_linkend(node) ⇒ Object
-
#initialize(options) ⇒ PresentationXMLConvert
constructor
A new instance of PresentationXMLConvert.
-
#insert_editors_clause(doc) ⇒ Object
-
#insert_preface_sections(docxml) ⇒ Object
-
#keywords(_docxml) ⇒ Object
-
#keywords_abstract_swap(abstract, keywords, docxml) ⇒ Object
-
#middle_title(isoxml) ⇒ Object
-
#middle_title_recommendation(isoxml, out) ⇒ Object
-
#middle_title_resolution(isoxml, out) ⇒ Object
-
#middle_title_resolution_subtitle(isoxml, out) ⇒ Object
-
#multi_bibitem_ref_code(bib) ⇒ Object
-
#norm_ref_entry_code(_ordinal, idents, _ids, _standard, datefn, _bib) ⇒ Object
-
#note1(elem) ⇒ Object
-
#note_delim(elem) ⇒ Object
-
#origin(docxml) ⇒ Object
-
#pref_ref_code(bibitem) ⇒ Object
-
#rearrange_clauses(docxml) ⇒ Object
-
#reference_format_start(bib) ⇒ Object
-
#reference_name(ref) ⇒ Object
-
#render_multi_identifiers(ids, bib) ⇒ Object
-
#table1(elem) ⇒ Object
-
#termnote_delim(_elem) ⇒ Object
-
#termsource_label(elem, sources) ⇒ Object
-
#title_footnotes(isoxml) ⇒ Object
-
#titlecase(str) ⇒ Object
-
#toc_title(docxml) ⇒ Object
-
#twitter_cldr_localiser_symbols ⇒ Object
-
#ul_label_list(_elem) ⇒ Object
-
#unbracket(ident) ⇒ Object
Methods included from Init
#bibrenderer, #fileloc, #i18n_init, #metadata_init, #xref_init
Constructor Details
Returns a new instance of PresentationXMLConvert.
15
16
17
18
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 15
def initialize(options)
@hierarchical_assets = options[:hierarchicalassets]
super
end
|
Instance Method Details
#abstract_render(abstract) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/isodoc/itu/presentation_preface.rb', line 84
def abstract_render(abstract)
abstract or return
@doctype == "contribution" or return
abstract.at(ns("./title"))&.remove
abstract.at(ns("./fmt-title"))&.remove
abstract.children = <<~TABLE
<table class="abstract" unnumbered="true" width="100%">
<colgroup><col width="11.8%"/><col width="78.2%"/></colgroup>
<tbody>
<tr><th align="left" width="95"><p>#{colon_i18n(@i18n.abstract)}</p></th>
<td>#{abstract.children.to_xml}</td></tr>
</tbody></table>
TABLE
end
|
#amendment_id(bib) ⇒ Object
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/isodoc/itu/presentation_bibdata.rb', line 79
def amendment_id(bib)
%w(amendment corrigendum).each do |w|
if dn = bib.at(ns("./ext/structuredidentifier/#{w}"))
dn["language"] = ""
dn.next = dn.dup
dn.next["language"] = @lang
dn.next.children = @i18n.l10n("#{@i18n.get[w]} #{dn.text}")
end
end
end
|
#annex1(elem) ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/isodoc/itu/presentation_section.rb', line 24
def annex1(elem)
if @doctype == "resolution"
annex1_resolution(elem)
else
super
annex1_non_resolution(elem)
end
end
|
#annex1_non_resolution(elem) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/isodoc/itu/presentation_section.rb', line 41
def annex1_non_resolution(elem)
info = elem["obligation"] == "informative"
ins = elem.at(ns("./fmt-xref-label")) || elem.at(ns("./fmt-title"))
p = (info ? @i18n.inform_annex : @i18n.norm_annex)
.gsub("%", @i18n.doctype_dict[@meta.get[:doctype_original]] || "")
ins.next = %(<p class="annex_obligation"><span class='fmt-obligation'>#{p}</span></p>)
end
|
#annex1_resolution(elem) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/isodoc/itu/presentation_section.rb', line 33
def annex1_resolution(elem)
elem.elements.first.previous = annex1_supertitle(elem)
t = elem.at(ns("./title")) and
t.children = "<strong>#{to_xml(t.children)}</strong>"
prefix_name(elem, {}, nil, "title")
end
|
#annex1_supertitle(elem) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/isodoc/itu/presentation_section.rb', line 49
def annex1_supertitle(elem)
lbl = @xrefs.anchor(elem["id"], :label)
res = elem.at(ns("//bibdata/title[@type = 'resolution']"))
subhead = @i18n.l10n("(#{@i18n.get['to']} #{to_xml(res.children)})")
"<p class='supertitle'>#{autonum(elem['id'],
lbl)}<br/>#{subhead}</p>"
end
|
#bibdata_dates(bib) ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/isodoc/itu/presentation_bibdata.rb', line 11
def bibdata_dates(bib)
bib.xpath(ns("./date")).each do |d|
d.next = d.dup
d.next["format"] = "ddMMMyyyy"
d.next.children = ddMMMyyyy(d.text)
end
end
|
#bibdata_i18n(bib) ⇒ Object
4
5
6
7
8
9
|
# File 'lib/isodoc/itu/presentation_bibdata.rb', line 4
def bibdata_i18n(bib)
super
bibdata_dates(bib)
bibdata_title(bib)
amendment_id(bib)
end
|
#bibdata_title(bib) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/isodoc/itu/presentation_bibdata.rb', line 19
def bibdata_title(bib)
case bib.at(ns("./ext/doctype"))&.text
when "service-publication" then bibdata_title_service_population(bib)
when "resolution" then bibdata_title_resolution(bib)
end
end
|
#bibdata_title_resolution(bib) ⇒ Object
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/isodoc/itu/presentation_bibdata.rb', line 26
def bibdata_title_resolution(bib)
place = bib.at(ns("./ext/meeting-place"))&.text
year = bib.at(ns("./ext/meeting-date/from | ./ext/meeting-date/on"))
&.text&.gsub(/-.*$/, "")
text = bibdata_title_resolution_name(bib, place, year)
bib.at(ns("./title")).next = <<~INS
<title language="#{@lang}" format="text/plain" type="resolution">#{text}</title>
<title language="#{@lang}" format="text/plain" type="resolution-placedate">#{place}, #{year}</title>
INS
end
|
#bibdata_title_resolution_name(bib, place, year) ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/isodoc/itu/presentation_bibdata.rb', line 37
def bibdata_title_resolution_name(bib, place, year)
ed = bib.at(ns("./edition"))&.text
rev = ed && ed != "1" ? "#{@i18n.get['revision_abbreviation']} " : ""
num = bib.at(ns("./docnumber"))
@i18n.l10n("#{@i18n.get['doctype_dict']['resolution'].upcase} " \
"#{num&.text} (#{rev}#{place}, #{year})")
end
|
#bibdata_title_service_population(bib) ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/isodoc/itu/presentation_bibdata.rb', line 45
def bibdata_title_service_population(bib)
date = bib&.at(ns("./date[@type = 'published']"))&.text or return
text = l10n(@i18n.get["position_on"].sub("%", ddmmmmyyyy(date)))
ins = bib.at(ns("./title"))
ins.next = <<~INS
<title language="#{@lang}" format="text/plain" type="position-sp">#{text}</title>
INS
end
|
#biblio_ref_entry_code(_ordinal, idents, _id, _standard, datefn, _bib) ⇒ Object
93
94
95
96
97
98
99
|
# File 'lib/isodoc/itu/presentation_ref.rb', line 93
def biblio_ref_entry_code(_ordinal, idents, _id, _standard, datefn, _bib)
ret = (idents[:metanorma] || idents[:ordinal] || idents[:sdo]).to_s
/^\[.+\]$/.match?(ret) or ret = "[#{ret}]"
ret += datefn
ret.empty? and return ret
ret.gsub("-", "‑").gsub(/ /, " ")
end
|
#bibliography_bibitem_number1(bib, idx, normative) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/isodoc/itu/presentation_ref.rb', line 68
def bibliography_bibitem_number1(bib, idx, normative)
mn = bib.at(ns(".//docidentifier[@type = 'metanorma']")) and
/^\[?\d+\]?$/.match?(mn.text) and
mn["type"] = "metanorma-ordinal"
if (mn = bib.at(ns(".//docidentifier[@type = 'metanorma-ordinal']"))) &&
!bibliography_bibitem_number_skip(bib)
idx += 1
mn.children = "[#{idx}]"
end
idx
end
|
#bibliography_bibitem_number_skip(bibitem) ⇒ Object
80
81
82
83
|
# File 'lib/isodoc/itu/presentation_ref.rb', line 80
def bibliography_bibitem_number_skip(bibitem)
implicit_reference(bibitem) ||
bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
end
|
11
12
13
14
15
|
# File 'lib/isodoc/itu/presentation_ref.rb', line 11
def bibrender_formattedref(formattedref, _xml)
formattedref << "." unless /\.$/.match?(formattedref.text)
id = reference_format_start(formattedref.parent) and
formattedref.add_first_child id
end
|
#bibrender_relaton(xml, renderings) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/isodoc/itu/presentation_ref.rb', line 17
def bibrender_relaton(xml, renderings)
f = renderings[xml["id"]][:formattedref] or return
ids = reference_format_start(xml)
f &&= "<formattedref>#{ids}#{f}</formattedref>"
if x = xml.at(ns("./formattedref"))
x.replace(f)
elsif xml.children.empty?
xml << f
else
xml.children.first.previous = f
end
end
|
#bold_and_upcase(xml) ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/isodoc/itu/presentation_contribution.rb', line 43
def bold_and_upcase(xml)
x = Nokogiri::XML("<root>#{xml}</root>")
x.traverse do |e|
e.text? or next
e.replace("<strong>#{e.text.upcase}</strong>")
end
x.root.children.to_xml
end
|
#bracket_if_num(num) ⇒ Object
101
102
103
104
105
106
|
# File 'lib/isodoc/itu/presentation_ref.rb', line 101
def bracket_if_num(num)
return nil if num.nil? || num.text.strip.empty?
num = num.text.sub(/^\[/, "").sub(/\]$/, "")
"[#{num}]"
end
|
#bracket_opt(text) ⇒ Object
31
32
33
34
35
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 31
def bracket_opt(text)
text.nil? and return
/^\[.+\]$/.match?(text) and return text
"[#{text}]"
end
|
#capitalise_unless_text_transform(elem) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 84
def capitalise_unless_text_transform(elem)
css = nil
elem.traverse_topdown do |n|
n.name == "span" && /text-transform:/.match?(n["style"]) and
css = n
n.text? && /\S/.match?(n.text) or next
css && n.ancestors.include?(css) or
n.replace(::Metanorma::Utils.strict_capitalize_first(n.text))
break
end
end
|
#clause1(elem) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/isodoc/itu/presentation_section.rb', line 4
def clause1(elem)
clause1_super?(elem) and return super
lbl = @xrefs.anchor(elem["id"], :label, false)
oldsuppressheadingnumbers = @suppressheadingnumbers
@suppressheadingnumbers = true
super
@suppressheadingnumbers = oldsuppressheadingnumbers
lbl.blank? || elem["unnumbered"] and return
elem.previous =
"<p keep-with-next='true' class='supertitle'>" \
"#{labelled_autonum(@i18n.get['section'].upcase, elem['id'],
lbl)}</p>"
end
|
#clause1_super?(elem) ⇒ Boolean
19
20
21
22
|
# File 'lib/isodoc/itu/presentation_section.rb', line 19
def clause1_super?(elem)
@doctype != "resolution" ||
!%w(sections bibliography).include?(elem.parent.name)
end
|
#colon_i18n(text) ⇒ Object
39
40
41
|
# File 'lib/isodoc/itu/presentation_contribution.rb', line 39
def colon_i18n(text)
@i18n.l10n("#{text}:")
end
|
91
92
93
94
95
|
# File 'lib/isodoc/itu/presentation_contribution.rb', line 91
def contrib_justification_contacts
(0..@meta.get[:authors]&.size).each_with_object([]) do |i, ret|
ret << contribution_justification_contact(i)
end
end
|
#contribution_justification(doc) ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/isodoc/itu/presentation_contribution.rb', line 116
def contribution_justification(doc)
@doctype == "contribution" or return
annex = doc.at(ns("//annex[@type = 'justification']")) or return
auths, auths_tail = contribution_justification_auths
annex.children = <<~TABLE
<title>#{contribution_justification_title(doc)}</title>
<table class="contribution-metadata" unnumbered="true" width="100%">
<colgroup><col width="15.9%"/><col width="6.1%"/><col width="45.5%"/><col width="17.4%"/><col width="15.1%"/></colgroup>
<tbody>
<tr>
<th align="left">#{colon_i18n(@i18n.questions)}</th><td>#{@meta.get[:questions]}</td>
<th align="left">Proposed new ITU-T #{@meta.get[:subdoctype]}</th>
<td colspan="2">#{@i18n.l10n("#{@meta.get[:meeting_place]}, #{@meta.get[:meeting_date]}")}</td>
</tr>
<tr><th align="left">Reference and title:</th>
<td colspan="4">Draft new #{@meta.get[:subdoctype]} on “#{@meta.get[:doctitle_en]}”</td>
</tr>
<tr>
<th align="left">Base text:</th><td colspan="2">#{(annex, 'basetext')}</td>
<th align="left">Timing:</th><td>#{@meta.get[:timing]}</td>
</tr>
<tr><th align="left" rowspan="#{auths.size - 1}">Editor(s):</th>
<td colspan="2">#{auths[0]}</td>
<th align="left" rowspan="#{auths.size - 1}">Approval process:</th>
<td rowspan="#{auths.size - 1}">#{@meta.get[:approval_process]}</td>
</tr>
#{auths_tail}
<tr><td colspan="5"><p><strong>Scope</strong> (defines the intent or object of the Recommendation and the aspects covered, thereby indicating the limits of its applicability):</p>#{(annex, 'scope')}</td></tr>
<tr><td colspan="5"><p><strong>Summary</strong> (provides a brief overview of the purpose and contents of the Recommendation, thus permitting readers to judge its usefulness for their work):</p>#{(annex, 'summary')}</td></tr>
<tr><td colspan="5"><p><strong>Relations to ITU-T Recommendations or to other standards</strong> (approved or under development):</p>#{(annex, 'relatedstandards')}</td></tr>
<tr><td colspan="5"><p><strong>Liaisons with other study groups or with other standards bodies:</strong></p>#{(annex, 'liaisons')}</td></tr>
<tr><td colspan="5"><p><strong>Supporting members that are committing to contributing actively to the work item:</strong></p>#{(annex, 'supportingmembers')}</td></tr>
</tbody>
</table>
TABLE
end
|
#contribution_justification_auths ⇒ Object
108
109
110
111
112
113
114
|
# File 'lib/isodoc/itu/presentation_contribution.rb', line 108
def contribution_justification_auths
auths = contrib_justification_contacts
auths_tail = auths[1..auths.size].map do |x|
"<tr><td colspan='2'>#{x}</td></td>"
end.join("\n")
[auths, auths_tail]
end
|
81
82
83
84
85
86
87
88
89
|
# File 'lib/isodoc/itu/presentation_contribution.rb', line 81
def contribution_justification_contact(idx)
@meta.get[:emails][idx] and
e = ", #{@i18n.email}<tab/>#{@meta.get[:emails][idx]}"
<<~CELL
#{@meta.get[:authors][idx]}<br/>
#{@meta.get[:affiliations][idx]}<br/>
#{@meta.get[:addresses][idx]}#{e}
CELL
end
|
#contribution_justification_title(_doc) ⇒ Object
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/isodoc/itu/presentation_contribution.rb', line 97
def contribution_justification_title(_doc)
n = @meta.get[:docnumber]
if @meta.get[:subdoctype] == "recommendation"
"A.1 justification for proposed draft new Recommendation #{n}"
else
s = @meta.get[:subdoctype]
"A.13 justification for proposed draft new #{s} "\
"#{n} “#{@meta.get[:doctitle_en]}”"
end
end
|
#contribution_table(_doc) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/isodoc/itu/presentation_contribution.rb', line 10
def contribution_table(_doc)
@doctype == "contribution" or return
bureau = bold_and_upcase(@meta.get[:bureau_full])
<<~TABLE
<clause unnumbered="true" type="contribution-metadata">
<table class="contribution-metadata" unnumbered="true" width="100%">
<colgroup><col width="11.8%"/><col width="41.2%"/><col width="47.0%"/></colgroup>
<thead>
<tr><th rowspan="3"><image height="56" width="56" src="#{@meta.get[:logo_small]}"/></th>
<td rowspan="3"><p style="font-size:8pt;margin-top:6pt;margin-bottom:0pt;">#{@i18n.international_telecommunication_union.upcase}</p>
<p class="bureau_big" style="font-size:13pt;margin-top:6pt;margin-bottom:0pt;">#{bureau}</p>
<p style="font-size:10pt;margin-top:6pt;margin-bottom:0pt;">#{@i18n.studyperiod.sub('%', @meta.get[:study_group_period]).upcase}</p></th>
<th align="right"><p style="font-size:16pt;">#{@meta.get[:docnumber]}</p></th></tr>
<tr><th align="right"><p style="font-size:14pt;">#{@meta.get[:group].upcase}</p></th></tr>
<tr>
<th align="right"><p style="font-size:14pt;">#{@i18n.l10n("#{@i18n.original}: #{@i18n.current_language}")}</p></th>
</tr></thead>
<tbody>
<tr><th align="left" width="95">#{colon_i18n(@i18n.questions)}</th><td>#{@meta.get[:questions]}</td>
<td align="right">#{@i18n.l10n("#{@meta.get[:meeting_place]}, #{@meta.get[:meeting_date]}")}</td></tr>
<tr><th align="center" colspan="3">#{@i18n.get['doctype_dict']['contribution'].upcase}</th></tr>
<tr><th align="left" width="95">#{colon_i18n(@i18n.document_source)}</th><td colspan="2">#{@meta.get[:source]}</td></tr>
<tr><th align="left" width="95">#{colon_i18n(@i18n.title)}</th><td colspan="2">#{@meta.get[:doctitle_en]}</td></tr>
#{contribution_table_contacts}
</tbody></table>
</clause>
TABLE
end
|
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/isodoc/itu/presentation_contribution.rb', line 62
def contribution_table_contact(idx)
@meta.get[:emails][idx] and
e = "<br/>#{@i18n.email}<tab/>#{@meta.get[:emails][idx]}"
<<~CELL
<td>#{@meta.get[:authors][idx]}<br/>
#{@meta.get[:affiliations][idx]}<br/>
#{@meta.get[:addresses][idx]}</td>
<td>#{@i18n.tel_abbrev}<tab/>#{@meta.get[:phones][idx]}#{e}</td>
CELL
end
|
52
53
54
55
56
57
58
59
60
|
# File 'lib/isodoc/itu/presentation_contribution.rb', line 52
def contribution_table_contacts
n = (0..@meta.get[:authors]&.size).each_with_object([]) do |i, ret|
ret << contribution_table_contact(i)
end
n.map do |x|
lbl = colon_i18n(@i18n.contact)
"<tr><th align='left' width='95'>#{lbl}</th>#{x}</tr>"
end.join("\n")
end
|
#contribution_table_insert_pt(docxml) ⇒ Object
4
5
6
7
8
|
# File 'lib/isodoc/itu/presentation_contribution.rb', line 4
def contribution_table_insert_pt(docxml)
docxml.at(ns("//preface")) || docxml.at(ns("//sections"))
.add_previous_sibling("<preface> </preface>").first
docxml.at(ns("//preface")).children.first.before(" ").previous
end
|
#ddmmmmyyyy(date) ⇒ Object
71
72
73
74
75
76
77
|
# File 'lib/isodoc/itu/presentation_bibdata.rb', line 71
def ddmmmmyyyy(date)
@lang == "zh" and return ddMMMyyyy(date)
d = date.split("-")
d[1] &&= @meta.months[d[1].to_sym]
d[2] &&= d[2].sub(/^0/, "")
l10n(d.reverse.join(" "))
end
|
#ddMMMyyyy(date) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/isodoc/itu/presentation_bibdata.rb', line 54
def ddMMMyyyy(date)
d = date.split("-").map { |x| x.sub(/^0/, "") }
case @lang
when "zh"
d[0] += "年" if d[0]
d[1] += "月" if d[1]
d[2] += "日" if d[2]
d.join
when "ar"
d[1] = ::RomanNumerals.to_roman(d[1].to_i).upcase if d[1]
d.join(".")
else
d[1] = ::RomanNumerals.to_roman(d[1].to_i).upcase if d[1]
d.reverse.join(".")
end
end
|
#designation(docxml) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 47
def designation(docxml)
super
docxml.xpath(ns("//fmt-preferred")).each do |x|
x.xpath(ns("./p")).each { |p| p.replace(p.children) }
end
end
|
#designation1(desgn) ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 37
def designation1(desgn)
super
desgn.name == "preferred" or return
out = desgn.parent
.at(ns("./fmt-preferred//semx[@element = 'preferred'][last()]"))
out or return
out.text.strip.empty? and return
out.children = l10n "#{to_xml out.children}:"
end
|
#dl(xml) ⇒ Object
141
142
143
144
145
146
147
148
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 141
def dl(xml)
super
(xml.xpath(ns("//dl")) -
xml.xpath(ns("//table//dl | //figure//dl | //formula//dl")))
.each do |d|
dl2(d)
end
end
|
#dl2(dlist) ⇒ Object
150
151
152
153
154
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 150
def dl2(dlist)
ins = dlist.at(ns("./dt"))
ins.previous =
'<colgroup><col width="20%"/><col width="80%"/></colgroup>'
end
|
#doctype_title(id, bib) ⇒ Object
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/isodoc/itu/presentation_ref.rb', line 45
def doctype_title(id, bib)
type = bib.at(ns("./ext/doctype"))&.text || "recommendation"
if type == "recommendation" &&
/^(?<prefix>ITU-[A-Z][ ][A-Z])[ .-]Sup[a-z]*\.[ ]?(?<num>\d+)$/ =~ id
"#{prefix}-series Recommendations – Supplement #{num}"
else
d = id.sub(/^\[/, "").sub(/\]$/, "")
"#{titlecase(type)} #{d}"
end
end
|
#editor_table_entries(eds, ed_lbl, mail_lbl) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/isodoc/itu/presentation_preface.rb', line 52
def editor_table_entries(eds, ed_lbl, mail_lbl)
eds.each_with_index.with_object([]) do |(n, i), m|
mail = ""
n[:email] and
mail = "#{mail_lbl}<link target='mailto:#{n[:email]}'>" \
"#{n[:email]}</link>"
aff = n[:affiliation].empty? ? "" : "<br/>#{n[:affiliation]}"
th = "<th>#{i.zero? ? ed_lbl : ''}</th>"
m << "<tr>#{th}<td>#{n[:name]}#{aff}</td><td>#{mail}</td></tr>"
end.join("\n")
end
|
#editors_clause(eds) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/isodoc/itu/presentation_preface.rb', line 39
def editors_clause(eds)
ed_lbl = @i18n.inflect(@i18n.get["editor_full"],
number: eds.size > 1 ? "pl" : "sg")
ed_lbl &&= l10n("#{ed_lbl.capitalize}:")
mail_lbl = l10n("#{@i18n.get['email']}: ")
ret = <<~SUBMITTING
<clause id="_#{UUIDTools::UUID.random_create}" type="editors">
<table id="_#{UUIDTools::UUID.random_create}" unnumbered="true"><tbody>
SUBMITTING
ret += editor_table_entries(eds, ed_lbl, mail_lbl)
"#{ret}</tbody></table></clause>"
end
|
#editors_insert_pt(docxml) ⇒ Object
15
16
17
18
19
20
|
# File 'lib/isodoc/itu/presentation_preface.rb', line 15
def editors_insert_pt(docxml)
docxml.at(ns("//preface")) || docxml.at(ns("//sections"))
.add_previous_sibling("<preface> </preface>").first
ins = docxml.at(ns("//preface/acknolwedgements")) and return ins
docxml.at(ns("//preface")).children[-1]
end
|
#eref(docxml) ⇒ Object
20
21
22
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 20
def eref(docxml)
docxml.xpath(ns("//fmt-eref")).each { |f| eref1(f) }
end
|
#eref1(elem) ⇒ Object
58
59
60
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 58
def eref1(elem)
get_eref_linkend(elem)
end
|
73
74
75
76
77
78
79
|
# File 'lib/isodoc/itu/presentation_contribution.rb', line 73
def (clause, type)
x = clause.at(ns("./clause[@type = '#{type}']")) or return
ret = x.dup
ret.at(ns("./title"))&.remove
ret.at(ns("./fmt-title"))&.remove
ret.children.to_xml
end
|
31
32
33
34
35
36
37
|
# File 'lib/isodoc/itu/presentation_preface.rb', line 31
def (doc)
e = doc.xpath(ns("//bibdata/contributor[role/@type = 'editor']/person"))
e.empty? and return
{ names: @meta.(e),
affiliations: @meta.(e),
emails: e.reduce([]) { |ret, p| ret << p.at(ns("./email"))&.text } }
end
|
#fn_body_label(fnote) ⇒ Object
106
107
108
109
110
111
112
113
114
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 106
def fn_body_label(fnote)
if fnote.ancestors("table, figure").empty? ||
!fnote.ancestors("name, fmt-name").empty?
super
else
"<sup>#{fn_label(fnote)}" \
"<span class='fmt-label-delim'>)</span></sup>"
end
end
|
#fn_ref_label(fnote) ⇒ Object
96
97
98
99
100
101
102
103
104
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 96
def fn_ref_label(fnote)
if fnote.ancestors("table, figure").empty? ||
!fnote.ancestors("name, fmt-name").empty?
super
else
"<sup>#{fn_label(fnote)}" \
"<span class='fmt-label-delim'>)</span></sup>"
end
end
|
#get_eref_linkend(node) ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 116
def get_eref_linkend(node)
non_locality_elems(node).select do |c|
!c.text? || /\S/.match(c)
end.empty? or return
link = anchor_linkend(node,
docid_l10n(node["target"] || node["citeas"]))
link && !/^\[.*\]$/.match(link) and link = "[#{link}]"
link += eref_localities(node.xpath(ns("./locality | ./localityStack")),
link, node)
non_locality_elems(node).each(&:remove)
node.add_child(link)
end
|
#insert_editors_clause(doc) ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/isodoc/itu/presentation_preface.rb', line 22
def insert_editors_clause(doc)
ret = (doc) or return
eds = ret[:names].each_with_object([]).with_index do |(_x, acc), i|
acc << { name: ret[:names][i], affiliation: ret[:affiliations][i],
email: ret[:emails][i] }
end
editors_clause(eds)
end
|
#insert_preface_sections(docxml) ⇒ Object
4
5
6
7
8
9
10
11
12
13
|
# File 'lib/isodoc/itu/presentation_preface.rb', line 4
def insert_preface_sections(docxml)
if @doctype == "contribution"
contribution_justification(docxml)
x = contribution_table(docxml) and
contribution_table_insert_pt(docxml).next = x
else
x = insert_editors_clause(docxml) and
editors_insert_pt(docxml).next = x
end
end
|
#keywords(_docxml) ⇒ Object
99
100
101
102
103
104
|
# File 'lib/isodoc/itu/presentation_preface.rb', line 99
def keywords(_docxml)
kw = @meta.get[:keywords]
kw.nil? || kw.empty? || @doctype == "contribution" and return
"<clause type='keyword'><fmt-title>#{@i18n.keywords}</fmt-title>" \
"<p>#{@i18n.l10n(kw.join(', '))}.</p>"
end
|
#keywords_abstract_swap(abstract, keywords, docxml) ⇒ Object
74
75
76
77
78
79
80
81
82
|
# File 'lib/isodoc/itu/presentation_preface.rb', line 74
def keywords_abstract_swap(abstract, keywords, docxml)
@doctype == "contribution" and return
k = keywords or return
if abstract then abstract.next = k
else
p = contribution_table_insert_pt(docxml)
p.next = k
end
end
|
#middle_title(isoxml) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/isodoc/itu/presentation_section.rb', line 57
def middle_title(isoxml)
s = isoxml.at(ns("//sections")) or return
isoxml.at(ns("//note[@type = 'title-footnote']"))
case @doctype
when "resolution"
middle_title_resolution(isoxml, s.children.first)
when "contribution"
else
middle_title_recommendation(isoxml, s.children.first)
end
end
|
#middle_title_recommendation(isoxml, out) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/isodoc/itu/presentation_section.rb', line 87
def middle_title_recommendation(isoxml, out)
ret = ""
type = @meta.get[:doctype]
@meta.get[:unpublished] && @meta.get[:draft_new_doctype] and
type = @meta.get[:draft_new_doctype]
id = @meta.get[:docnumber] and
ret += "<<p class='zzSTDTitle1'>#{type} #{id}</p>"
t = @meta.get[:doctitle] and
ret += "<p class='zzSTDTitle2'>#{t}"
ret += "#{(isoxml)}</p>"
s = @meta.get[:docsubtitle] and ret += "<p class='zzSTDTitle3'>#{s}</p>"
out.previous = ret
end
|
#middle_title_resolution(isoxml, out) ⇒ Object
70
71
72
73
74
75
76
77
|
# File 'lib/isodoc/itu/presentation_section.rb', line 70
def middle_title_resolution(isoxml, out)
res = isoxml.at(ns("//bibdata/title[@type = 'resolution']"))
out.previous =
"<p class='zzSTDTitle1' align='center'>#{res.children.to_xml}</p>"
t = @meta.get[:doctitle] and
out.previous = "<p class='zzSTDTitle2'>#{t}</p>"
middle_title_resolution_subtitle(isoxml, out)
end
|
#middle_title_resolution_subtitle(isoxml, out) ⇒ Object
79
80
81
82
83
84
85
|
# File 'lib/isodoc/itu/presentation_section.rb', line 79
def middle_title_resolution_subtitle(isoxml, out)
ret = "<p align='center' class='zzSTDTitle2'><em>("
d = isoxml.at(ns("//bibdata/title[@type = 'resolution-placedate']"))
ret += "#{d.children.to_xml.strip}</em>)"
ret += "#{(isoxml)}</p>"
out.previous = ret
end
|
#multi_bibitem_ref_code(bib) ⇒ Object
30
31
32
33
34
|
# File 'lib/isodoc/itu/presentation_ref.rb', line 30
def multi_bibitem_ref_code(bib)
id = pref_ref_code_parse(bib)
id.nil? and return []
id.sort_by { |i| /^ITU/.match?(i) ? 0 : 1 }
end
|
#norm_ref_entry_code(_ordinal, idents, _ids, _standard, datefn, _bib) ⇒ Object
85
86
87
88
89
90
91
|
# File 'lib/isodoc/itu/presentation_ref.rb', line 85
def norm_ref_entry_code(_ordinal, idents, _ids, _standard, datefn, _bib)
ret = (idents[:metanorma] || idents[:ordinal] || idents[:sdo]).to_s
ret.empty? and return ret
/^\[.+\]$/.match?(ret) or ret = "[#{ret}]"
ret += datefn
ret.gsub("-", "‑").gsub(/ /, " ")
end
|
#note1(elem) ⇒ Object
62
63
64
65
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 62
def note1(elem)
elem["type"] == "title-footnote" and return
super
end
|
#note_delim(elem) ⇒ Object
67
68
69
70
71
72
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 67
def note_delim(elem)
if elem.at(ns("./*[local-name() != 'name'][1]"))&.name == "p"
"\u00a0\u2013\u00a0"
else ""
end
end
|
#origin(docxml) ⇒ Object
24
25
26
27
28
29
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 24
def origin(docxml)
docxml.xpath(ns("//fmt-origin[not(termref)]")).each do |f|
f["citeas"] = bracket_opt(f["citeas"])
eref1(f)
end
end
|
#pref_ref_code(bibitem) ⇒ Object
108
109
110
111
112
|
# File 'lib/isodoc/itu/presentation_ref.rb', line 108
def pref_ref_code(bibitem)
ret = bibitem.xpath(ns("./docidentifier[@type = 'ITU']"))
ret.empty? and ret = super
ret
end
|
#rearrange_clauses(docxml) ⇒ Object
64
65
66
67
68
69
70
71
72
|
# File 'lib/isodoc/itu/presentation_preface.rb', line 64
def rearrange_clauses(docxml)
super
insert_preface_sections(docxml)
a = docxml.at(ns("//preface/abstract"))
keywords_abstract_swap(a, keywords(docxml), docxml)
c = docxml.at(ns("//preface/clause[@type='contribution-metadata']")) and
a and c.next = a
abstract_render(a)
end
|
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/isodoc/itu/presentation_ref.rb', line 56
def reference_format_start(bib)
id = multi_bibitem_ref_code(bib)
id1 = render_multi_identifiers(id, bib)
out = id1
out.empty? and return out
date = bib.at(ns("./date[@type = 'published']/on | " \
"./date[@type = 'published']/from")) and
out << " (#{date.text.sub(/-.*$/, '')})"
out += ", " if date || !id1.empty?
out
end
|
#reference_name(ref) ⇒ Object
122
123
124
125
126
|
# File 'lib/isodoc/itu/presentation_ref.rb', line 122
def reference_name(ref)
super
@xrefs.get[ref["id"]] =
{ xref: @xrefs.get[ref["id"]][:xref].sub(/^\[/, "").sub(/\]$/, "") }
end
|
#render_multi_identifiers(ids, bib) ⇒ Object
36
37
38
39
40
41
42
43
|
# File 'lib/isodoc/itu/presentation_ref.rb', line 36
def render_multi_identifiers(ids, bib)
ids.map do |id|
if /^ITU/.match?(id) then doctype_title(id, bib)
else
id.sub(/^\[/, "").sub(/\]$/, "")
end
end.join(" | ")
end
|
#table1(elem) ⇒ Object
74
75
76
77
78
79
80
81
82
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 74
def table1(elem)
elem.xpath(ns("./thead/tr/th")).each do |n|
capitalise_unless_text_transform(n)
end
super
elem.xpath(ns("./fmt-name//semx[@element = 'name']")).each do |n|
capitalise_unless_text_transform(n)
end
end
|
#termnote_delim(_elem) ⇒ Object
156
157
158
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 156
def termnote_delim(_elem)
" – "
end
|
#termsource_label(elem, sources) ⇒ Object
54
55
56
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 54
def termsource_label(elem, sources)
elem.replace(sources)
end
|
101
102
103
104
105
106
107
108
|
# File 'lib/isodoc/itu/presentation_section.rb', line 101
def (isoxml)
ret = ""
isoxml.xpath(ns("//note[@type = 'title-footnote']"))
.each_with_index do |f, i|
ret += "<fn reference='H#{i}'>#{f.remove.children.to_xml}</fn>"
end
ret
end
|
#titlecase(str) ⇒ Object
129
130
131
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 129
def titlecase(str)
str.gsub(/ |_|-/, " ").split(/ /).map(&:capitalize).join(" ")
end
|
#toc_title(docxml) ⇒ Object
106
107
108
109
|
# File 'lib/isodoc/itu/presentation_preface.rb', line 106
def toc_title(docxml)
%w(resolution contribution).include?(@doctype) and return
super
end
|
133
134
135
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 133
def
{ group: "'" }
end
|
#ul_label_list(_elem) ⇒ Object
137
138
139
|
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 137
def ul_label_list(_elem)
%w(– • o)
end
|
#unbracket(ident) ⇒ Object
114
115
116
117
118
119
120
|
# File 'lib/isodoc/itu/presentation_ref.rb', line 114
def unbracket(ident)
if ident.respond_to?(:size)
ident.map { |x| unbracket1(x) }.join(" | ")
else
unbracket1(ident)
end
end
|