Skip to content

Commit e1085df

Browse files
authored
Merge pull request #515 from metanorma/features/itu-attributes-pdf-2024
Features/itu attributes pdf 2024
2 parents 7a2a8f3 + 08311fe commit e1085df

15 files changed

+396
-241
lines changed

Gemfile.devel

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
gem "metanorma-standoc", git: "https://github.com/metanorma/metanorma-standoc", branch: "main"
2+
gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "main"
3+
4+
5+

lib/isodoc/itu/html/html_itu_titlepage.html

+7-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343

4444
<div class="doc-info-left">
4545
<div class="doc-identifier">
46-
{% if doctype != "Recommendation" %}{{doctype }} {% endif %}{{ docnumeric }}
46+
{% if collectiontitle %}<div>{{ collectiontitle}}</div>{%endif%}
47+
<div>{% if doctype != "Recommendation" %}{{doctype }} {% endif %}{{ docnumeric }}</div>
4748
{% if amendmentid %}<div class="doc-subidentifier">{{ amendmentid }}</div>{% endif %}
4849
{% if corrigendumid %}<div class="doc-subidentifier">{{ corrigendumid }}</div>{% endif %}
4950
{% if edition %} <div> Revision {{ edition }}</div> {% endif %}
@@ -59,9 +60,11 @@
5960
</div>
6061

6162
<div class="doc-category">
62-
{% if bureau == "T" %}Telecommunication <br/>Standardization Sector <br/>of ITU{% endif %}
63-
{% if bureau == "D" %}Telecommunication <br/>Development Sector <br/>of ITU{% endif %}
64-
{% if bureau == "R" %}Radiocommunication <br/>Sector of ITU{% endif %}
63+
{% if sector %}{{sector}}{%else%}
64+
{% if bureau == "T" %}{{ labels["tsb_full"] }}{% endif %}
65+
{% if bureau == "D" %}{{ labels["bdt_full"] }}{% endif %}
66+
{% if bureau == "R" %}{{ labels["br_full"] }}{% endif %}
67+
{%endif%}
6568
</div>
6669

6770
<div class="coverpage-title">

lib/isodoc/itu/html/word_itu_titlepage.html

+17-34
Original file line numberDiff line numberDiff line change
@@ -223,44 +223,27 @@
223223
width="95" colspan="2"><p class='MsoNormal'>&#xA0;</p></td>
224224
<td width="303" colspan="2" valign="top" style='width:227.45pt;padding:0cm 4.25pt 0cm 4.25pt;
225225
height:48.7pt'>
226-
{% if bureau == "T" %}
227-
<p class="MsoNormal" align="left" style='text-align:left'><span style='mso-bookmark:
228-
_Hlk526346232'><span lang="EN-US" style='font-size:10.0pt;font-family:"Arial",sans-serif;
229-
mso-bidi-font-family:"Times New Roman";mso-ansi-language:EN-US'>TELECOMMUNICATION</span></span><span
230-
style='mso-bookmark:_Hlk526346232'><span lang="EN-US" style='font-size:10.0pt;
231-
font-family:"Arial",sans-serif;mso-ansi-language:EN-US'><br/>
232-
</span></span><span style='mso-bookmark:_Hlk526346232'><span lang="EN-US"
233-
style='font-size:10.0pt;font-family:"Arial",sans-serif;mso-bidi-font-family:
234-
"Times New Roman";mso-ansi-language:EN-US'>STANDARDIZATION SECTOR<br/>
235-
OF ITU</span></span><span style='mso-bookmark:_Hlk526346232'><b
236-
style='mso-bidi-font-weight:normal'><span lang="EN-US" style='font-size:10.0pt;
237-
mso-ansi-language:EN-US'><o:p></o:p></span></b></span></p>
226+
227+
{% if sector %}
228+
<p class="MsoNormal" align="left" style='text-align:left'>
229+
<span lang="EN-US" style='font-size:10.0pt;font-family:"Arial",sans-serif;
230+
mso-bidi-font-family:"Times New Roman";mso-ansi-language:EN-US'>{{ sector }}</span></p>
231+
{% else %}
232+
{% if bureau == "T" %}
233+
<p class="MsoNormal" align="left" style='text-align:left'>
234+
<span lang="EN-US" style='font-size:10.0pt;font-family:"Arial",sans-serif;
235+
mso-bidi-font-family:"Times New Roman";mso-ansi-language:EN-US'>{{ labels["tsb_full"] }}</span></p>
238236
{% endif %}
239237
{% if bureau == "D" %}
240-
<p class="MsoNormal" align="left" style='text-align:left'><span style='mso-bookmark:
241-
_Hlk526346232'><span lang="EN-US" style='font-size:10.0pt;font-family:"Arial",sans-serif;
242-
mso-bidi-font-family:"Times New Roman";mso-ansi-language:EN-US'>TELECOMMUNICATION</span></span><span
243-
style='mso-bookmark:_Hlk526346232'><span lang="EN-US" style='font-size:10.0pt;
244-
font-family:"Arial",sans-serif;mso-ansi-language:EN-US'><br/>
245-
</span></span><span style='mso-bookmark:_Hlk526346232'><span lang="EN-US"
246-
style='font-size:10.0pt;font-family:"Arial",sans-serif;mso-bidi-font-family:
247-
"Times New Roman";mso-ansi-language:EN-US'>DEVELOPMENT SECTOR<br/>
248-
OF ITU</span></span><span style='mso-bookmark:_Hlk526346232'><b
249-
style='mso-bidi-font-weight:normal'><span lang="EN-US" style='font-size:10.0pt;
250-
mso-ansi-language:EN-US'><o:p></o:p></span></b></span></p>
238+
<p class="MsoNormal" align="left" style='text-align:left'>
239+
<span lang="EN-US" style='font-size:10.0pt;font-family:"Arial",sans-serif;
240+
mso-bidi-font-family:"Times New Roman";mso-ansi-language:EN-US'>{{ labels["bdt_full"] }}</span></p>
251241
{% endif %}
252242
{% if bureau == "R" %}
253-
<p class="MsoNormal" align="left" style='text-align:left'><span style='mso-bookmark:
254-
_Hlk526346232'><span lang="EN-US" style='font-size:10.0pt;font-family:"Arial",sans-serif;
255-
mso-bidi-font-family:"Times New Roman";mso-ansi-language:EN-US'>RADIOCOMMUNICATION</span></span><span
256-
style='mso-bookmark:_Hlk526346232'><span lang="EN-US" style='font-size:10.0pt;
257-
font-family:"Arial",sans-serif;mso-ansi-language:EN-US'><br/>
258-
</span></span><span style='mso-bookmark:_Hlk526346232'><span lang="EN-US"
259-
style='font-size:10.0pt;font-family:"Arial",sans-serif;mso-bidi-font-family:
260-
"Times New Roman";mso-ansi-language:EN-US'>SECTOR<br/>
261-
OF ITU</span></span><span style='mso-bookmark:_Hlk526346232'><b
262-
style='mso-bidi-font-weight:normal'><span lang="EN-US" style='font-size:10.0pt;
263-
mso-ansi-language:EN-US'><o:p></o:p></span></b></span></p>
243+
<p class="MsoNormal" align="left" style='text-align:left'>
244+
<span lang="EN-US" style='font-size:10.0pt;font-family:"Arial",sans-serif;
245+
mso-bidi-font-family:"Times New Roman";mso-ansi-language:EN-US'>{{ labels["br_full"] }}</span></p>
246+
{% endif %}
264247
{% endif %}
265248

266249
</td>

lib/isodoc/itu/metadata.rb

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def title(isoxml, _out)
3131
series1: "//bibdata/series[@type='secondary']/title",
3232
series2: "//bibdata/series[@type='tertiary']/title",
3333
annextitle: "//bibdata/title[@type='annex']",
34+
collectiontitle: "//bibdata/title[@type='collection']",
35+
slogantitle: "//bibdata/title[@type='slogan']",
3436
positiontitle: "//bibdata/title[@type='position-sp']" }.each do |k, v|
3537
titleset(isoxml, k, v)
3638
end
@@ -51,6 +53,8 @@ def subtitle(_isoxml, _out)
5153
end
5254

5355
def author(xml, _out)
56+
sector = xml.at(ns("//bibdata/ext/editorialgroup/sector"))
57+
set(:sector, sector.text) if sector
5458
bureau = xml.at(ns("//bibdata/ext/editorialgroup/bureau"))
5559
set(:bureau, bureau.text) if bureau
5660
tc = xml.at(ns("//bibdata/ext/editorialgroup/committee"))

lib/isodoc/itu/presentation_ref.rb

+18-13
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,34 @@ def bibrender_relaton(xml, renderings)
2424
end
2525

2626
def multi_bibitem_ref_code(bib)
27-
skip = IsoDoc::Function::References::SKIP_DOCID
28-
skip1 = "@type = 'metanorma' or @type = 'metanorma-ordinal'"
29-
prim = "[@primary = 'true']"
30-
id = bib.xpath(ns("./docidentifier#{prim}[not(#{skip} or #{skip1})]"))
31-
id.empty? and id = bib.xpath(ns("./docidentifier#{prim}[not(#{skip1})]"))
32-
id.empty? and id = bib.xpath(ns("./docidentifier[not(#{skip} or #{skip1})]"))
33-
id.empty? and id = bib.xpath(ns("./docidentifier[not(#{skip1})]"))
34-
id.empty? and return id
35-
id.sort_by { |i| i["type"] == "ITU" ? 0 : 1 }
27+
id = pref_ref_code_parse(bib)
28+
id.nil? and return []
29+
id.sort_by { |i| /^ITU/.match?(i) ? 0 : 1 }
3630
end
3731

38-
def render_multi_identifiers(ids)
32+
def render_multi_identifiers(ids, bib)
3933
ids.map do |id|
40-
if id["type"] == "ITU" then doctype_title(id)
34+
if /^ITU/.match?(id) then doctype_title(id, bib)
4135
else
42-
docid_prefix(id["type"], id.text.sub(/^\[/, "").sub(/\]$/, ""))
36+
id.sub(/^\[/, "").sub(/\]$/, "")
4337
end
4438
end.join("&#xA0;| ")
4539
end
4640

41+
def doctype_title(id, bib)
42+
type = bib.at(ns("./ext/doctype"))&.text || "recommendation"
43+
if type == "recommendation" &&
44+
/^(?<prefix>ITU-[A-Z][  ][A-Z])[  .-]Sup[a-z]*\.[  ]?(?<num>\d+)$/ =~ id
45+
"#{prefix}-series Recommendations – Supplement #{num}"
46+
else
47+
d = id.sub(/^\[/, "").sub(/\]$/, "")
48+
"#{titlecase(type)} #{d}"
49+
end
50+
end
51+
4752
def reference_format_start(bib)
4853
id = multi_bibitem_ref_code(bib)
49-
id1 = render_multi_identifiers(id)
54+
id1 = render_multi_identifiers(id, bib)
5055
out = id1
5156
date = bib.at(ns("./date[@type = 'published']/on | " \
5257
"./date[@type = 'published']/from")) and

lib/isodoc/itu/presentation_xml_convert.rb

-11
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,6 @@ def titlecase(str)
8787
str.gsub(/ |_|-/, " ").split(/ /).map(&:capitalize).join(" ")
8888
end
8989

90-
def doctype_title(id)
91-
type = id.parent&.at(ns("./ext/doctype"))&.text || "recommendation"
92-
if type == "recommendation" &&
93-
/^(?<prefix>ITU-[A-Z][  ][A-Z])[  .-]Sup[a-z]*\.[  ]?(?<num>\d+)$/ =~ id.text
94-
"#{prefix}-series Recommendations – Supplement #{num}"
95-
else
96-
d = docid_prefix(id["type"], id.text.sub(/^\[/, "").sub(/\]$/, ""))
97-
"#{titlecase(type)} #{d}"
98-
end
99-
end
100-
10190
def twitter_cldr_localiser_symbols
10291
{ group: "'" }
10392
end

lib/metanorma/itu/cleanup.rb

+17-146
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
1+
require_relative "cleanup_section"
2+
13
module Metanorma
24
module ITU
35
class Converter < Standoc::Converter
4-
def sections_cleanup(xml)
5-
super
6-
insert_missing_sections(xml) unless @no_insert_missing_sections
7-
insert_empty_clauses(xml)
8-
resolution_inline_header(xml)
9-
end
10-
11-
def resolution_inline_header(xml)
12-
@doctype == "resolution" or return
13-
xml.xpath("//clause//clause").each do |c|
14-
(title = c.at("./title")) && !title.text&.empty? and next
15-
c["inline-header"] = true
16-
end
17-
end
18-
196
def table_cleanup(xmldoc)
207
super
218
xmldoc.xpath("//thead/tr[1]/th | //thead/tr[1]/td").each do |t|
@@ -31,84 +18,6 @@ def header_rows_cleanup(xmldoc)
3118
end
3219
end
3320

34-
def insert_missing_sections(xml)
35-
xml.at("//metanorma-extension/semantic-metadata/" \
36-
"headless[text() = 'true']") and return nil
37-
insert_scope(xml)
38-
insert_norm_ref(xml)
39-
insert_terms(xml)
40-
insert_symbols(xml)
41-
insert_conventions(xml)
42-
end
43-
44-
def add_id
45-
%(id="_#{UUIDTools::UUID.random_create}")
46-
end
47-
48-
def insert_scope(xml)
49-
xml.at("./*/sections") or
50-
xml.at("./*/preface | ./*/boilerplate | ./*/bibdata").next =
51-
"<sections><sentinel/></sections>"
52-
xml.at("./*/sections/*") or xml.at("./*/sections") << "<sentinel/>"
53-
ins = xml.at("//sections").elements.first
54-
xml.at("//sections/clause[@type = 'scope']") or
55-
ins.previous =
56-
"<clause type='scope' #{add_id}><title>#{@i18n.scope}</title><p>" \
57-
"#{@i18n.clause_empty}</p></clause>"
58-
xml.at("//sentinel")&.remove
59-
end
60-
61-
def insert_norm_ref(xml)
62-
xml.at("//bibliography") or
63-
xml.at("./*/annex[last()] | ./*/sections").next =
64-
"<bibliography><sentinel/></bibliography>"
65-
ins = xml.at("//bibliography").elements.first
66-
xml.at("//bibliography/references[@normative = 'true']") or
67-
ins.previous = "<references #{add_id} normative='true'>" \
68-
"<title>#{@i18n.normref}</title></references>"
69-
xml.at("//sentinel")&.remove
70-
end
71-
72-
def insert_terms(xml)
73-
ins = xml.at("//sections/clause[@type = 'scope']")
74-
xml.at("//sections//terms") or
75-
ins.next = "<terms #{add_id}><title>#{@i18n.termsdef}</title></terms>"
76-
end
77-
78-
def insert_symbols(xml)
79-
ins = xml.at("//sections/terms") ||
80-
xml.at("//sections/clause[descendant::terms]")
81-
unless xml.at("//sections//definitions")
82-
ins.next = "<definitions #{add_id}>" \
83-
"<title>#{@i18n.symbolsabbrev}</title></definitions>"
84-
end
85-
end
86-
87-
def insert_conventions(xml)
88-
ins = xml.at("//sections//definitions") ||
89-
xml.at("//sections/clause[descendant::definitions]")
90-
unless xml.at("//sections/clause[@type = 'conventions']")
91-
ins.next = "<clause #{add_id} type='conventions'>" \
92-
"<title>#{@i18n.conventions}</title><p>" \
93-
"#{@i18n.clause_empty}</p></clause>"
94-
end
95-
end
96-
97-
def insert_empty_clauses(xml)
98-
xml.xpath("//terms[not(./term)][not(.//terms)]").each do |c|
99-
insert_empty_clauses1(c, @i18n.clause_empty)
100-
end
101-
xml.xpath("//definitions[not(./dl)]").each do |c|
102-
insert_empty_clauses1(c, @i18n.clause_empty)
103-
end
104-
end
105-
106-
def insert_empty_clauses1(clause, text)
107-
clause.at("./p") and return
108-
ins = clause.at("./title") or return
109-
ins.next = "<p>#{text}</p>"
110-
end
111-
11221
def cleanup(xmldoc)
11322
symbols_cleanup(xmldoc)
11423
super
@@ -117,11 +26,9 @@ def cleanup(xmldoc)
11726
end
11827

11928
def smartquotes_cleanup(xmldoc)
120-
return super if @smartquotes
121-
29+
@smartquotes and return super
12230
xmldoc.traverse do |n|
123-
next unless n.text?
124-
31+
n.text? or next
12532
n.replace(HTMLEntities.new.encode(
12633
n.text.gsub(/\u2019|\u2018|\u201a|\u201b/, "'")
12734
.gsub(/\u201c|\u201d|\u201e|\u201f/, '"'), :basic
@@ -130,51 +37,6 @@ def smartquotes_cleanup(xmldoc)
13037
xmldoc
13138
end
13239

133-
def termdef_boilerplate_cleanup(xmldoc); end
134-
135-
def terms_extract(div)
136-
internal = div.at("./terms[@type = 'internal']/title")
137-
external = div.at("./terms[@type = 'external']/title")
138-
[internal, external]
139-
end
140-
141-
def term_defs_boilerplate(div, _source, _term, _preface, _isodoc)
142-
internal, external = terms_extract(div.parent)
143-
internal&.next_element&.name == "term" and
144-
internal.next = "<p>#{@i18n.internal_terms_boilerplate}</p>"
145-
internal and internal&.next_element == nil and
146-
internal.next = "<p>#{@i18n.no_terms_boilerplate}</p>"
147-
external&.next_element&.name == "term" and
148-
external.next = "<p>#{@i18n.external_terms_boilerplate}</p>"
149-
external and external&.next_element == nil and
150-
external.next = "<p>#{@i18n.no_terms_boilerplate}</p>"
151-
!internal and !external and
152-
%w(term terms).include? div&.next_element&.name and
153-
div.next = "<p>#{@i18n.term_def_boilerplate}</p>"
154-
end
155-
156-
def section_names_terms_cleanup(xml)
157-
super
158-
replace_title(
159-
xml, "//terms[@type = 'internal'] | " \
160-
"//clause[./terms[@type = 'internal']]" \
161-
"[not(./terms[@type = 'external'])]",
162-
@i18n&.internal_termsdef
163-
)
164-
replace_title(
165-
xml, "//terms[@type = 'external'] | " \
166-
"//clause[./terms[@type = 'external']]" \
167-
"[not(./terms[@type = 'internal'])]",
168-
@i18n&.external_termsdef
169-
)
170-
end
171-
172-
def symbols_cleanup(xmldoc)
173-
sym = xmldoc.at("//definitions/title")
174-
sym and sym&.next_element&.name == "dl" and
175-
sym.next = "<p>#{@i18n.symbols_boilerplate}</p>"
176-
end
177-
17840
PUBLISHER = "./contributor[role/@type = 'publisher']/organization".freeze
17941

18042
def pub_class(bib)
@@ -221,11 +83,20 @@ def biblio_reorder(xmldoc)
22183
end
22284
end
22385

224-
def sections_names_cleanup(xml)
86+
def bibdata_cleanup(xmldoc)
22587
super
226-
t = xml.at("//preface//abstract") or return
227-
t["id"] == "_summary" and
228-
replace_title(xml, "//preface//abstract", @i18n&.summary)
88+
coverpage_images(xmldoc)
89+
end
90+
91+
def coverpage_images(xmldoc)
92+
%w(coverpage-image).each do |n|
93+
xmldoc.xpath("//bibdata/ext/#{n}").each do |x|
94+
ins = add_misc_container(xmldoc)
95+
ins << "<presentation-metadata><name>#{n}</name>" \
96+
"<value>#{x.remove.children.to_xml}</value>" \
97+
"</presentation-metadata>"
98+
end
99+
end
229100
end
230101
end
231102
end

0 commit comments

Comments
 (0)