metanorma-itu 1.2.1 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  require "isodoc"
2
+ require "twitter_cldr"
2
3
 
3
4
  module IsoDoc
4
5
  module ITU
@@ -23,6 +24,12 @@ module IsoDoc
23
24
  main = isoxml&.at(ns("//bibdata/title[@language='#{@lang}']"\
24
25
  "[@type = 'subtitle']"))&.text
25
26
  set(:docsubtitle, main)
27
+ main = isoxml&.at(ns("//bibdata/title[@language='#{@lang}']"\
28
+ "[@type = 'amendment']"))&.text
29
+ set(:amendmenttitle, main)
30
+ main = isoxml&.at(ns("//bibdata/title[@language='#{@lang}']"\
31
+ "[@type = 'corrigendum']"))&.text
32
+ set(:corrigendumtitle, main)
26
33
  series = isoxml&.at(ns("//bibdata/series[@type='main']/title"))&.text
27
34
  set(:series, series)
28
35
  series1 =
@@ -39,12 +46,38 @@ module IsoDoc
39
46
  nil
40
47
  end
41
48
 
42
- def author(isoxml, _out)
43
- bureau = isoxml.at(ns("//bibdata/ext/editorialgroup/bureau"))
49
+ def author(xml, _out)
50
+ bureau = xml.at(ns("//bibdata/ext/editorialgroup/bureau"))
44
51
  set(:bureau, bureau.text) if bureau
45
- tc = isoxml.at(ns("//bibdata/ext/editorialgroup/committee"))
52
+ tc = xml.at(ns("//bibdata/ext/editorialgroup/committee"))
46
53
  set(:tc, tc.text) if tc
54
+ tc = xml.at(ns("//bibdata/ext/editorialgroup/group/name"))
55
+ set(:group, tc.text) if tc
56
+ tc = xml.at(ns("//bibdata/ext/editorialgroup/subgroup/name"))
57
+ set(:subgroup, tc.text) if tc
58
+ tc = xml.at(ns("//bibdata/ext/editorialgroup/workgroup/name"))
59
+ set(:workgroup, tc.text) if tc
47
60
  super
61
+ authors = xml.xpath(ns("//bibdata/contributor[role/@type = 'author' "\
62
+ "or xmlns:role/@type = 'editor']/person"))
63
+ person_attributes(authors) unless authors.empty?
64
+ end
65
+
66
+ def append(key, value)
67
+ @metadata[key] << value
68
+ end
69
+
70
+ def person_attributes(authors)
71
+ %i(affiliations addresses emails faxes phones).each { |i| set(i, []) }
72
+ authors.each do |a|
73
+ append(:affiliations,
74
+ a&.at(ns("./affiliation/organization/name"))&.text)
75
+ append(:addresses, a&.at(ns("./affiliation/organization/address/"\
76
+ "formattedAddress"))&.text)
77
+ append(:emails, a&.at(ns("./email"))&.text)
78
+ append(:faxes, a&.at(ns("./phone[@type = 'fax']"))&.text)
79
+ append(:phones, a&.at(ns("./phone[not(@type = 'fax')]"))&.text)
80
+ end
48
81
  end
49
82
 
50
83
  def docid(isoxml, _out)
@@ -54,6 +87,11 @@ module IsoDoc
54
87
  oblig = isoxml&.at(ns("//annex/@obligation"))&.text
55
88
  lbl = oblig == "informative" ? @labels["appendix"] : @labels["annex"]
56
89
  dn and set(:annexid, @i18n.l10n("#{lbl} #{dn&.text}"))
90
+ dn = isoxml.at(ns("//bibdata/ext/structuredidentifier/amendment")) and
91
+ set(:amendmentid, @i18n.l10n("#{@labels["amendment"]} #{dn&.text}"))
92
+ dn = isoxml.at(ns("//bibdata/ext/structuredidentifier/corrigendum")) and
93
+ set(:corrigendumid,
94
+ @i18n.l10n("#{@labels["corrigendum"]} #{dn&.text}"))
57
95
  end
58
96
 
59
97
  def unpublished(status)
@@ -91,6 +129,27 @@ module IsoDoc
91
129
  "false"
92
130
  set(:ip_notice_received, received)
93
131
  end
132
+
133
+ def ddMMMYYYY(isodate)
134
+ m = /(?<yr>\d\d\d\d)-(?<mo>\d\d)-(?<dd>\d\d)/.match isodate
135
+ return isodate unless m && m[:yr] && m[:mo] && m[:dd]
136
+ mmm = DateTime.parse(isodate).localize(@lang.to_sym).#with_timezone("UCT").
137
+ to_additional_s("MMM")
138
+ @i18n.l10n("#{m[:dd]} #{mmm} #{m[:yr]}")
139
+ end
140
+
141
+ def techreport(isoxml, _out)
142
+ a = isoxml&.at(ns("//bibdata/ext/meeting"))&.text and set(:meeting, a)
143
+ a = isoxml&.at(ns("//bibdata/ext/intended-type"))&.text and
144
+ set(:intended_type, a)
145
+ a = isoxml&.at(ns("//bibdata/ext/source"))&.text and set(:source, a)
146
+ if o = isoxml&.at(ns("//bibdata/ext/meeting-date/on"))&.text
147
+ set(:meeting_date, ddMMMYYYY(o))
148
+ elsif f = isoxml&.at(ns("//bibdata/ext/meeting-date/from"))&.text
149
+ t = isoxml&.at(ns("//bibdata/ext/meeting-date/to"))&.text
150
+ set(:meeting_date, "#{ddMMMYYYY(f)}/#{ddMMMYYYY(t)}")
151
+ end
152
+ end
94
153
  end
95
154
  end
96
155
  end
@@ -48,6 +48,18 @@ module IsoDoc
48
48
  node.add_child(link)
49
49
  end
50
50
 
51
+ def bibdata_i18n(b)
52
+ super
53
+ %w(amendment corrigendum).each do |w|
54
+ if dn = b.at(ns("./ext/structuredidentifier/#{w}"))
55
+ dn["language"] = ""
56
+ dn.next = dn.dup
57
+ dn.next["language"] = @lang
58
+ dn.next.children = @i18n.l10n("#{@i18n.get[w]} #{dn&.text}")
59
+ end
60
+ end
61
+ end
62
+
51
63
  include Init
52
64
  end
53
65
  end
@@ -0,0 +1,152 @@
1
+ module IsoDoc
2
+ module ITU
3
+ class WordConvert < IsoDoc::WordConvert
4
+ def word_preface_cleanup(docxml)
5
+ docxml.xpath("//h1[@class = 'AbstractTitle'] | "\
6
+ "//h1[@class = 'IntroTitle']").each do |h2|
7
+ h2.name = "p"
8
+ h2["class"] = "h1Preface"
9
+ end
10
+ end
11
+
12
+ def word_term_cleanup(docxml)
13
+ end
14
+
15
+ def word_cleanup(docxml)
16
+ word_footnote_cleanup(docxml)
17
+ word_title_cleanup(docxml)
18
+ word_preface_cleanup(docxml)
19
+ word_term_cleanup(docxml)
20
+ word_history_cleanup(docxml)
21
+ authority_hdr_cleanup(docxml)
22
+ table_list_style(docxml)
23
+ super
24
+ docxml
25
+ end
26
+
27
+ def word_footnote_cleanup(docxml)
28
+ docxml.xpath("//aside").each do |a|
29
+ a.first_element_child.children.first.previous =
30
+ '<span style="mso-tab-count:1"/>'
31
+ end
32
+ end
33
+
34
+ def word_title_cleanup(docxml)
35
+ docxml.xpath("//p[@class = 'annex_obligation']").each do |h|
36
+ h&.next_element&.name == "p" or next
37
+ h.next_element["class"] ||= "Normalaftertitle"
38
+ end
39
+ docxml.xpath("//p[@class = 'FigureTitle']").each do |h|
40
+ h&.parent&.next_element&.name == "p" or next
41
+ h.parent.next_element["class"] ||= "Normalaftertitle"
42
+ end
43
+ end
44
+
45
+ def word_history_cleanup(docxml)
46
+ docxml.xpath("//div[@id='_history']//table").each do |t|
47
+ t["class"] = "MsoNormalTable"
48
+ t.xpath(".//td").each { |td| td["style"] = nil }
49
+ end
50
+ end
51
+
52
+ def word_preface(docxml)
53
+ super
54
+ abstractbox = docxml.at("//div[@id='abstractbox']")
55
+ historybox = docxml.at("//div[@id='historybox']")
56
+ sourcebox = docxml.at("//div[@id='sourcebox']")
57
+ keywordsbox = docxml.at("//div[@id='keywordsbox']")
58
+ abstract = docxml.at("//div[@class = 'Abstract']")
59
+ history = docxml.at("//div[@class = 'history']")
60
+ source = docxml.at("//div[@class = 'source']")
61
+ keywords = docxml.at("//div[@class = 'Keywords']")
62
+ abstract.parent = abstractbox if abstract && abstractbox
63
+ history.parent = historybox if history && historybox
64
+ source.parent = sourcebox if source && sourcebox
65
+ keywords.parent = keywordsbox if keywords && keywordsbox
66
+ end
67
+
68
+ def toWord(result, filename, dir, header)
69
+ result = populate_template(result, :word)
70
+ result = from_xhtml(word_cleanup(to_xhtml(result)))
71
+ unless @landscapestyle.nil? || @landscapestyle.empty?
72
+ @wordstylesheet&.open
73
+ @wordstylesheet&.write(@landscapestyle)
74
+ @wordstylesheet&.close
75
+ end
76
+ Html2Doc.process(
77
+ result, filename: filename,
78
+ stylesheet: @wordstylesheet&.path,
79
+ header_file: header&.path, dir: dir,
80
+ asciimathdelims: [@openmathdelim, @closemathdelim],
81
+ liststyles: { ul: @ulstyle, ol: @olstyle, steps: "l4" })
82
+ header&.unlink
83
+ @wordstylesheet&.unlink
84
+ end
85
+
86
+ def authority_hdr_cleanup(docxml)
87
+ docxml&.xpath("//div[@id = 'draft-warning']").each do |d|
88
+ d.xpath(".//h1 | .//h2").each do |p|
89
+ p.name = "p"
90
+ p["class"] = "draftwarningHdr"
91
+ end
92
+ end
93
+ %w(copyright license legal).each do |t|
94
+ docxml&.xpath("//div[@class = 'boilerplate-#{t}']").each do |d|
95
+ p = d&.at("./descendant::h1[2]") and
96
+ p.previous = "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>"
97
+ d.xpath(".//h1 | .//h2").each do |p|
98
+ p.name = "p"
99
+ p["class"] = "boilerplateHdr"
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ def authority_cleanup(docxml)
106
+ dest = docxml.at("//div[@class = 'draft-warning']")
107
+ auth = docxml.at("//div[@id = 'draft-warning']")
108
+ dest and auth and dest.replace(auth.remove)
109
+ %w(copyright license legal).each do |t|
110
+ dest = docxml.at("//div[@id = 'boilerplate-#{t}-destination']")
111
+ auth = docxml.at("//div[@class = 'boilerplate-#{t}']")
112
+ next unless auth && dest
113
+ t == "copyright" and p = auth&.at(".//p") and
114
+ p["class"] = "boilerplateHdr"
115
+ auth&.xpath(".//p[not(@class)]")&.each_with_index do |p, i|
116
+ p["class"] = "boilerplate"
117
+ #i == 0 && t == "copyright" and p["style"] = "text-align:center;"
118
+ end
119
+ t == "copyright" or
120
+ auth << "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>"
121
+ dest.replace(auth.remove)
122
+ end
123
+ end
124
+
125
+ TOPLIST = "[not(ancestor::ul) and not(ancestor::ol)]".freeze
126
+
127
+ def table_list_style(xml)
128
+ xml.xpath("//table//ul#{TOPLIST} | //table//ol#{TOPLIST}").each do |t|
129
+ table_list_style1(t, 1)
130
+ end
131
+ end
132
+
133
+ def table_list_style1(t, num)
134
+ (t.xpath(".//li") - t.xpath(".//ol//li | .//ul//li")).each do |t1|
135
+ indent_list(t1, num)
136
+ t1.xpath("./div | ./p").each { |p| indent_list(p, num) }
137
+ (t1.xpath(".//ul") - t1.xpath(".//ul//ul | .//ol//ul")).each do |t2|
138
+ table_list_style1(t2, num + 1)
139
+ end
140
+ (t1.xpath(".//ol") - t1.xpath(".//ul//ol | .//ol//ol")).each do |t2|
141
+ table_list_style1(t2, num + 1)
142
+ end
143
+ end
144
+ end
145
+
146
+ def indent_list(li, num)
147
+ li["style"] = (li["style"] ? li["style"] + ";" : "")
148
+ li["style"] += "margin-left: #{num * 0.5}cm;text-indent: -0.5cm;"
149
+ end
150
+ end
151
+ end
152
+ end
@@ -1,12 +1,10 @@
1
1
  require "isodoc"
2
2
  require_relative "init"
3
+ require_relative "word_cleanup"
3
4
  require "fileutils"
4
5
 
5
6
  module IsoDoc
6
7
  module ITU
7
- # A {Converter} implementation that generates Word output, and a document
8
- # schema encapsulation of the document for validation
9
-
10
8
  class WordConvert < IsoDoc::WordConvert
11
9
  def initialize(options)
12
10
  @libdir = File.dirname(__FILE__)
@@ -27,6 +25,7 @@ module IsoDoc
27
25
  body.div **{ class: "WordSection2" } do |div2|
28
26
  info docxml, div2
29
27
  boilerplate docxml, div2
28
+ preface_block docxml, div2
30
29
  abstract docxml, div2
31
30
  keywords docxml, div2
32
31
  preface docxml, div2
@@ -52,71 +51,6 @@ module IsoDoc
52
51
  end
53
52
  end
54
53
 
55
- def word_preface_cleanup(docxml)
56
- docxml.xpath("//h1[@class = 'AbstractTitle'] | "\
57
- "//h1[@class = 'IntroTitle']").each do |h2|
58
- h2.name = "p"
59
- h2["class"] = "h1Preface"
60
- end
61
- end
62
-
63
- def word_term_cleanup(docxml)
64
- docxml.xpath("//p[@class = 'TermNum']").each do |t|
65
- end
66
- end
67
-
68
- def word_cleanup(docxml)
69
- word_footnote_cleanup(docxml)
70
- word_title_cleanup(docxml)
71
- word_preface_cleanup(docxml)
72
- word_term_cleanup(docxml)
73
- word_history_cleanup(docxml)
74
- authority_hdr_cleanup(docxml)
75
- super
76
- docxml
77
- end
78
-
79
- def word_footnote_cleanup(docxml)
80
- docxml.xpath("//aside").each do |a|
81
- a.first_element_child.children.first.previous =
82
- '<span style="mso-tab-count:1"/>'
83
- end
84
- end
85
-
86
- def word_title_cleanup(docxml)
87
- docxml.xpath("//p[@class = 'annex_obligation']").each do |h|
88
- h&.next_element&.name == "p" or next
89
- h.next_element["class"] ||= "Normalaftertitle"
90
- end
91
- docxml.xpath("//p[@class = 'FigureTitle']").each do |h|
92
- h&.parent&.next_element&.name == "p" or next
93
- h.parent.next_element["class"] ||= "Normalaftertitle"
94
- end
95
- end
96
-
97
- def word_history_cleanup(docxml)
98
- docxml.xpath("//div[@id='_history']//table").each do |t|
99
- t["class"] = "MsoNormalTable"
100
- t.xpath(".//td").each { |td| td["style"] = nil }
101
- end
102
- end
103
-
104
- def word_preface(docxml)
105
- super
106
- abstractbox = docxml.at("//div[@id='abstractbox']")
107
- historybox = docxml.at("//div[@id='historybox']")
108
- sourcebox = docxml.at("//div[@id='sourcebox']")
109
- keywordsbox = docxml.at("//div[@id='keywordsbox']")
110
- abstract = docxml.at("//div[@class = 'Abstract']")
111
- history = docxml.at("//div[@class = 'history']")
112
- source = docxml.at("//div[@class = 'source']")
113
- keywords = docxml.at("//div[@class = 'Keywords']")
114
- abstract.parent = abstractbox if abstract && abstractbox
115
- history.parent = historybox if history && historybox
116
- source.parent = sourcebox if source && sourcebox
117
- keywords.parent = keywordsbox if keywords && keywordsbox
118
- end
119
-
120
54
  def formula_parse1(node, out)
121
55
  out.div **attr_code(class: "formula") do |div|
122
56
  div.p **attr_code(class: "formula") do |p|
@@ -156,24 +90,6 @@ module IsoDoc
156
90
  { class: node["class"], id: node["id"], style: keep_style(node) }
157
91
  end
158
92
 
159
- def toWord(result, filename, dir, header)
160
- result = populate_template(result, :word)
161
- result = from_xhtml(word_cleanup(to_xhtml(result)))
162
- unless @landscapestyle.nil? || @landscapestyle.empty?
163
- @wordstylesheet&.open
164
- @wordstylesheet&.write(@landscapestyle)
165
- @wordstylesheet&.close
166
- end
167
- Html2Doc.process(result, filename: filename,
168
- stylesheet: @wordstylesheet&.path,
169
- header_file: header&.path, dir: dir,
170
- asciimathdelims: [@openmathdelim, @closemathdelim],
171
- liststyles: { ul: @ulstyle, ol: @olstyle,
172
- steps: "l4" })
173
- header&.unlink
174
- @wordstylesheet&.unlink
175
- end
176
-
177
93
  def link_parse(node, out)
178
94
  out.a **attr_code(href: node["target"], title: node["alt"],
179
95
  class: "url") do |l|
@@ -185,45 +101,6 @@ module IsoDoc
185
101
  end
186
102
  end
187
103
 
188
- def authority_hdr_cleanup(docxml)
189
- docxml&.xpath("//div[@id = 'draft-warning']").each do |d|
190
- d.xpath(".//h1 | .//h2").each do |p|
191
- p.name = "p"
192
- p["class"] = "draftwarningHdr"
193
- end
194
- end
195
- %w(copyright license legal).each do |t|
196
- docxml&.xpath("//div[@class = 'boilerplate-#{t}']").each do |d|
197
- p = d&.at("./descendant::h1[2]") and
198
- p.previous = "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>"
199
- d.xpath(".//h1 | .//h2").each do |p|
200
- p.name = "p"
201
- p["class"] = "boilerplateHdr"
202
- end
203
- end
204
- end
205
- end
206
-
207
- def authority_cleanup(docxml)
208
- dest = docxml.at("//div[@class = 'draft-warning']")
209
- auth = docxml.at("//div[@id = 'draft-warning']")
210
- dest and auth and dest.replace(auth.remove)
211
- %w(copyright license legal).each do |t|
212
- dest = docxml.at("//div[@id = 'boilerplate-#{t}-destination']")
213
- auth = docxml.at("//div[@class = 'boilerplate-#{t}']")
214
- next unless auth && dest
215
- t == "copyright" and p = auth&.at(".//p") and
216
- p["class"] = "boilerplateHdr"
217
- auth&.xpath(".//p[not(@class)]")&.each_with_index do |p, i|
218
- p["class"] = "boilerplate"
219
- #i == 0 && t == "copyright" and p["style"] = "text-align:center;"
220
- end
221
- t == "copyright" or
222
- auth << "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>"
223
- dest.replace(auth.remove)
224
- end
225
- end
226
-
227
104
  def clause_attrs(node)
228
105
  ret = {}
229
106
  %w(source history).include?(node["type"]) and
@@ -20,7 +20,7 @@ module IsoDoc
20
20
  @labels["appendix"] : @labels["annex"]
21
21
  @anchors[clause["id"]] =
22
22
  { label: annex_name_lbl(clause, num), type: "clause",
23
- xref: "#{lbl} #{num}", level: 1 }
23
+ xref: "#{lbl} #{num}", level: 1, value: num }
24
24
  if a = single_annex_special_section(clause)
25
25
  annex_names1(a, "#{num}", 1)
26
26
  else
@@ -101,7 +101,7 @@ module IsoDoc
101
101
  j = 0
102
102
  c.increment(t)
103
103
  end
104
- label = c.print + (j.zero? ? "" : "-#{(96 + j).chr.to_s}")
104
+ label = c.print + (j.zero? ? "" : "#{hierfigsep}#{(96 + j).chr.to_s}")
105
105
  next if t["id"].nil? || t["id"].empty?
106
106
  @anchors[t["id"]] =
107
107
  anchor_struct(label, nil, @labels["figure"], "figure", t["unnumbered"])
@@ -164,6 +164,7 @@ module IsoDoc
164
164
  idx = notes.size == 1 ? "" : " #{c.increment(n).print}"
165
165
  @anchors[n["id"]] =
166
166
  { label: termnote_label(idx).strip, type: "termnote",
167
+ value: idx,
167
168
  xref: l10n("#{anchor(t['id'], :xref)}, "\
168
169
  "#{@labels["note_xref"]} #{c.print}") }
169
170