metanorma-unece 0.0.14 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,6 @@ module IsoDoc
8
8
  class Metadata < IsoDoc::Metadata
9
9
  def initialize(lang, script, labels)
10
10
  super
11
- set(:status, "XXX")
12
11
  end
13
12
 
14
13
  def title(isoxml, _out)
@@ -31,12 +30,12 @@ module IsoDoc
31
30
  end
32
31
 
33
32
  def author(isoxml, _out)
34
- tc = isoxml.at(ns("//bibdata/editorialgroup/committee"))
33
+ tc = isoxml.at(ns("//bibdata/ext/editorialgroup/committee"))
35
34
  set(:tc, tc.text) if tc
36
- set(:distribution, isoxml&.at(ns("//bibdata/distribution"))&.text)
35
+ set(:distribution, isoxml&.at(ns("//bibdata/ext/distribution"))&.text)
37
36
  lgs = extract_languages(isoxml.xpath(ns("//bibdata/language")))
38
37
  lgs = [] if lgs.sort == %w(English French Arabic Chinese German Spanish).sort
39
- slgs = extract_languages(isoxml.xpath(ns("//bibdata/submissionlanguage")))
38
+ slgs = extract_languages(isoxml.xpath(ns("//bibdata/ext/submissionlanguage")))
40
39
  lgs = [] if slgs.size == 1
41
40
  set(:language, lgs) unless lgs.empty?
42
41
  set(:submissionlanguage, slgs) unless slgs.empty?
@@ -50,28 +49,24 @@ module IsoDoc
50
49
  end
51
50
 
52
51
  def session(isoxml, _out)
53
- set(:session_number, isoxml&.at(ns("//bibdata/session/number"))&.text&.to_i&.
52
+ set(:session_number, isoxml&.at(ns("//bibdata/ext/session/number"))&.text&.to_i&.
54
53
  localize&.to_rbnf_s("SpelloutRules", "spellout-ordinal")&.capitalize)
55
- set(:session_date, isoxml&.at(ns("//bibdata/session/date"))&.text)
56
- set(:session_collaborator, isoxml&.at(ns("//bibdata/session/collaborator"))&.text)
57
- set(:session_id, isoxml&.at(ns("//bibdata/session/id"))&.text)
58
- set(:item_footnote, isoxml&.at(ns("//bibdata/session/item-footnote"))&.text)
59
- set(:session_itemnumber, multival(isoxml, "//bibdata/session/item-number"))
60
- set(:session_itemname, multival(isoxml, "//bibdata/session/item-name"))
61
- set(:session_subitemname, multival(isoxml, "//bibdata/session/subitem-name"))
54
+ set(:session_date, isoxml&.at(ns("//bibdata/ext/session/date"))&.text)
55
+ set(:session_collaborator, isoxml&.at(ns("//bibdata/ext/session/collaborator"))&.text)
56
+ set(:session_id, isoxml&.at(ns("//bibdata/ext/session/id"))&.text)
57
+ set(:item_footnote, isoxml&.at(ns("//bibdata/ext/session/item-footnote"))&.text)
58
+ set(:session_itemnumber, multival(isoxml, "//bibdata/ext/session/item-number"))
59
+ set(:session_itemname, multival(isoxml, "//bibdata/ext/session/item-name"))
60
+ set(:session_subitemname, multival(isoxml, "//bibdata/ext/session/subitem-name"))
62
61
  end
63
62
 
64
63
  def docid(isoxml, _out)
65
64
  dn = isoxml.at(ns("//bibdata/docidentifier"))&.text
66
65
  set(:docnumber, dn)
67
- type = isoxml&.at(ns("//bibdata/@type"))&.value
66
+ type = isoxml&.at(ns("//bibdata/ext/doctype"))&.text
68
67
  set(:formatted_docnumber, type == "recommendation" ? "UN/CEFACT Recommendation #{dn}" : dn)
69
68
  end
70
69
 
71
- def status_print(status)
72
- status.split(/-/).map{ |w| w.capitalize }.join(" ")
73
- end
74
-
75
70
  def status_abbr(status)
76
71
  case status
77
72
  when "working-draft" then "wd"
@@ -1,7 +1,5 @@
1
+ require_relative "base_convert"
1
2
  require "isodoc"
2
- require_relative "metadata"
3
- require "fileutils"
4
- require "roman-numerals"
5
3
 
6
4
  module IsoDoc
7
5
  module Unece
@@ -40,11 +38,6 @@ module IsoDoc
40
38
  }
41
39
  end
42
40
 
43
- def metadata_init(lang, script, labels)
44
- @meta = Metadata.new(lang, script, labels)
45
- @meta.set(:toc, @toc)
46
- end
47
-
48
41
  def footnotes(div)
49
42
  if @meta.get[:item_footnote]
50
43
  fn = noko do |xml|
@@ -57,319 +50,122 @@ module IsoDoc
57
50
  super
58
51
  end
59
52
 
60
- def make_body(xml, docxml)
61
- plenary = docxml.at(ns("//bibdata[@type = 'plenary']"))
62
- if plenary && @wordcoverpage == html_doc_path("word_unece_titlepage.html")
63
- @wordcoverpage = html_doc_path("word_unece_plenary_titlepage.html")
64
- end
65
- @wordintropage = nil if plenary && !@toc
66
- body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72" }
67
- xml.body **body_attr do |body|
68
- make_body1(body, docxml)
69
- make_body2(body, docxml)
70
- make_body3(body, docxml)
53
+ def make_body(xml, docxml)
54
+ plenary = docxml.at(ns("//bibdata/ext[doctype = 'plenary']"))
55
+ if plenary && @wordcoverpage == html_doc_path("word_unece_titlepage.html")
56
+ @wordcoverpage = html_doc_path("word_unece_plenary_titlepage.html")
57
+ end
58
+ @wordintropage = nil if plenary && !@toc
59
+ body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72" }
60
+ xml.body **body_attr do |body|
61
+ make_body1(body, docxml)
62
+ make_body2(body, docxml)
63
+ make_body3(body, docxml)
64
+ end
71
65
  end
72
- end
73
66
 
74
- def make_body2(body, docxml)
75
- body.div **{ class: "WordSection2" } do |div2|
76
- info docxml, div2
77
- abstract docxml, div2
78
- foreword docxml, div2
79
- introduction docxml, div2
80
- div2.p { |p| p << "&nbsp;" } # placeholder
67
+ def make_body2(body, docxml)
68
+ body.div **{ class: "WordSection2" } do |div2|
69
+ info docxml, div2
70
+ abstract docxml, div2
71
+ foreword docxml, div2
72
+ introduction docxml, div2
73
+ div2.p { |p| p << "&nbsp;" } # placeholder
74
+ end
75
+ section_break(body)
81
76
  end
82
- section_break(body)
83
- end
84
77
 
85
- ENDLINE = <<~END.freeze
78
+ ENDLINE = <<~END.freeze
86
79
  <v:line id="_x0000_s1026"
87
80
  alt="" style='position:absolute;left:0;text-align:left;z-index:251662848;
88
81
  mso-wrap-edited:f;mso-width-percent:0;mso-height-percent:0;
89
82
  mso-width-percent:0;mso-height-percent:0'
90
83
  from="6.375cm,20.95pt" to="10.625cm,20.95pt"
91
84
  strokeweight="1.5pt"/>
92
- END
85
+ END
93
86
 
94
- def end_line(_isoxml, out)
95
- out.parent.add_child(ENDLINE)
96
- end
97
-
98
- def middle(isoxml, out)
99
- clause isoxml, out
100
- annex isoxml, out
101
- bibliography isoxml, out
102
- end_line(isoxml, out)
103
- end
104
-
105
- def clause_parse_title(node, div, c1, out)
106
- if node["inline-header"] == "true"
107
- inline_header_title(out, node, c1)
108
- else
109
- div.send "h#{get_anchors[node['id']][:level]}" do |h|
110
- lbl = get_anchors[node['id']][:label]
111
- h << "#{lbl}. " if lbl && !@suppressheadingnumbers
112
- insert_tab(h, 1)
113
- c1&.children&.each { |c2| parse(c2, h) }
114
- end
87
+ def end_line(_isoxml, out)
88
+ out.parent.add_child(ENDLINE)
115
89
  end
116
- end
117
90
 
118
- def introduction(isoxml, out)
119
- f = isoxml.at(ns("//introduction")) || return
120
- out.div **{ class: "Section3", id: f["id"] } do |div|
121
- page_break(out)
122
- div.p(**{ class: "IntroTitle" }) do |h1|
123
- h1 << @introduction_lbl
124
- end
125
- f.elements.each do |e|
126
- parse(e, div) unless e.name == "title"
127
- end
91
+ def middle(isoxml, out)
92
+ clause isoxml, out
93
+ annex isoxml, out
94
+ bibliography isoxml, out
95
+ end_line(isoxml, out)
128
96
  end
129
- end
130
97
 
131
- def foreword(isoxml, out)
132
- f = isoxml.at(ns("//foreword")) || return
133
- out.div **attr_code(id: f["id"]) do |s|
134
- page_break(out)
135
- s.p(**{ class: "ForewordTitle" }) do |h1|
136
- h1 << @foreword_lbl
98
+ def clause_parse_title(node, div, c1, out)
99
+ if node["inline-header"] == "true"
100
+ inline_header_title(out, node, c1)
101
+ else
102
+ div.send "h#{anchor(node['id'], :level) || '1'}" do |h|
103
+ lbl = anchor(node['id'], :label, false)
104
+ h << "#{lbl}. " if lbl && !@suppressheadingnumbers
105
+ insert_tab(h, 1)
106
+ c1&.children&.each { |c2| parse(c2, h) }
107
+ end
137
108
  end
138
- f.elements.each { |e| parse(e, s) unless e.name == "title" }
139
- end
140
- end
141
-
142
- def word_preface(docxml)
143
- super
144
- preface_container = docxml.at("//div[@id = 'preface_container']") # recommendation
145
- abstractbox = docxml.at("//div[@id = 'abstractbox']") # plenary
146
- foreword = docxml.at("//p[@class = 'ForewordTitle']/..")
147
- intro = docxml.at("//p[@class = 'IntroTitle']/..")
148
- abstract = docxml.at("//p[@class = 'AbstractTitle']/..")
149
- abstract.parent = (abstractbox || preface_container) if abstract
150
- abstractbox and abstract&.xpath(".//p/br")&.each do |a|
151
- a.parent.remove if /page-break-before:always/.match(a["style"])
152
- end
153
- docxml&.at("//p[@class = 'AbstractTitle']")&.remove if abstractbox
154
- foreword.parent = preface_container if foreword && preface_container
155
- intro.parent = preface_container if intro && preface_container
156
- if preface_container && (foreword || intro)
157
- preface_container.at("./div/p[br]").remove # remove initial page break
158
109
  end
159
- if abstractbox && !intro && !foreword && !@toc
160
- sect2 = docxml.at("//div[@class='WordSection2']")
161
- sect2.next_element.remove # pagebreak
162
- sect2.remove # pagebreak
163
- end
164
- end
165
-
166
- # SAME as html_convert.rb from here on, starting with annex_name
167
110
 
168
- def annex_name(annex, name, div)
169
- div.h1 **{ class: "Annex" } do |t|
170
- t << "#{get_anchors[annex['id']][:label]}"
171
- t.br
172
- t.b do |b|
173
- name&.children&.each { |c2| parse(c2, b) }
111
+ def introduction(isoxml, out)
112
+ f = isoxml.at(ns("//introduction")) || return
113
+ out.div **{ class: "Section3", id: f["id"] } do |div|
114
+ page_break(out)
115
+ div.p(**{ class: "IntroTitle" }) do |h1|
116
+ h1 << @introduction_lbl
117
+ end
118
+ f.elements.each do |e|
119
+ parse(e, div) unless e.name == "title"
120
+ end
174
121
  end
175
122
  end
176
- end
177
-
178
- def i18n_init(lang, script)
179
- super
180
- @admonition_lbl = "Box"
181
- @abstract_lbl = "Summary"
182
- end
183
-
184
- def fileloc(loc)
185
- File.join(File.dirname(__FILE__), loc)
186
- end
187
-
188
- MIDDLE_CLAUSE = "//clause[parent::sections]".freeze
189
-
190
- def initial_anchor_names(d)
191
- preface_names(d.at(ns("//foreword")))
192
- preface_names(d.at(ns("//introduction")))
193
- sequential_asset_names(d.xpath(ns("//foreword | //introduction")))
194
- middle_section_asset_names(d)
195
- clause_names(d, 0)
196
- termnote_anchor_names(d)
197
- termexample_anchor_names(d)
198
- end
199
-
200
- def clause_names(docxml, sect_num)
201
- q = "//clause[parent::sections]"
202
- @paranumber = 0
203
- docxml.xpath(ns(q)).each_with_index do |c, i|
204
- section_names(c, (i + sect_num), 1)
205
- end
206
- end
207
-
208
- def levelnumber(num, lvl)
209
- case lvl % 3
210
- when 1 then RomanNumerals.to_roman(num)
211
- when 2 then ("A".ord + num - 1).chr
212
- when 0 then num.to_s
213
- end
214
- end
215
-
216
- def annex_levelnumber(num, lvl)
217
- case lvl % 3
218
- when 0 then RomanNumerals.to_roman(num)
219
- when 1 then ("A".ord + num - 1).chr
220
- when 2 then num.to_s
221
- end
222
- end
223
-
224
- def leaf_section(clause, lvl)
225
- @paranumber += 1
226
- @anchors[clause["id"]] = {label: @paranumber.to_s, xref: "paragraph #{@paranumber}", level: lvl, type: "paragraph" }
227
- end
228
-
229
- def annex_leaf_section(clause, num, lvl)
230
- @paranumber += 1
231
- @anchors[clause["id"]] = {label: @paranumber.to_s, xref: "paragraph #{num}.#{@paranumber}", level: lvl, type: "paragraph" }
232
- end
233
-
234
- def section_names(clause, num, lvl)
235
- return num if clause.nil?
236
- clause.at(ns("./clause | ./term | ./terms | ./definitions")) or
237
- leaf_section(clause, lvl) && return
238
- num = num + 1
239
- lbl = levelnumber(num, 1)
240
- @anchors[clause["id"]] =
241
- { label: lbl, xref: l10n("#{@clause_lbl} #{lbl}"), level: lvl, type: "clause" }
242
- i = 1
243
- clause.xpath(ns("./clause | ./term | ./terms | ./definitions")).each do |c|
244
- section_names1(c, "#{lbl}.#{levelnumber(i, lvl + 1)}", lvl + 1)
245
- i += 1 if c.at(ns("./clause | ./term | ./terms | ./definitions"))
246
- end
247
- num
248
- end
249
-
250
- def section_names1(clause, num, level)
251
- unless clause.at(ns("./clause | ./term | ./terms | ./definitions"))
252
- leaf_section(clause, level) and return
253
- end
254
- /\.(?<leafnum>[^.]+$)/ =~ num
255
- @anchors[clause["id"]] =
256
- { label: leafnum, level: level, xref: l10n("#{@clause_lbl} #{num}"), type: "clause" }
257
- i = 1
258
- clause.xpath(ns("./clause | ./terms | ./term | ./definitions")).each do |c|
259
- section_names1(c, "#{num}.#{levelnumber(i, level + 1)}", level + 1)
260
- i += 1 if c.at(ns("./clause | ./term | ./terms | ./definitions"))
261
- end
262
- end
263
-
264
- def annex_name_lbl(clause, num)
265
- l10n("<b>#{@annex_lbl} #{num}</b>")
266
- end
267
-
268
- def annex_names(clause, num)
269
- hierarchical_asset_names(clause, num)
270
- unless clause.at(ns("./clause | ./term | ./terms | ./definitions"))
271
- annex_leaf_section(clause, num, 1) and return
272
- end
273
- @anchors[clause["id"]] = { label: annex_name_lbl(clause, num), type: "clause",
274
- xref: "#{@annex_lbl} #{num}", level: 1 }
275
- i = 1
276
- clause.xpath(ns("./clause")).each do |c|
277
- annex_names1(c, "#{num}.#{annex_levelnumber(i, 2)}", 2)
278
- i += 1 if c.at(ns("./clause | ./term | ./terms | ./definitions"))
279
- end
280
- end
281
-
282
- def annex_names1(clause, num, level)
283
- unless clause.at(ns("./clause | ./term | ./terms | ./definitions"))
284
- annex_leaf_section(clause, num, level) and return
285
- end
286
- /\.(?<leafnum>[^.]+$)/ =~ num
287
- @anchors[clause["id"]] = { label: leafnum, xref: "#{@annex_lbl} #{num}",
288
- level: level, type: "clause" }
289
- i = 1
290
- clause.xpath(ns("./clause")).each do |c|
291
- annex_names1(c, "#{num}.#{annex_levelnumber(i, level + 1)}", level + 1)
292
- i += 1 if c.at(ns("./clause | ./term | ./terms | ./definitions"))
293
- end
294
- end
295
-
296
- def back_anchor_names(docxml)
297
- docxml.xpath(ns("//annex")).each_with_index do |c, i|
298
- @paranumber = 0
299
- annex_names(c, RomanNumerals.to_roman(i + 1))
300
- end
301
- docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref|
302
- reference_names(ref)
303
- end
304
- end
305
-
306
- def sequential_admonition_names(clause)
307
- i = 0
308
- clause.xpath(ns(".//admonition")).each do |t|
309
- i += 1
310
- next if t["id"].nil? || t["id"].empty?
311
- @anchors[t["id"]] = anchor_struct(i.to_s, nil, @admonition_lbl, "box")
312
- end
313
- end
314
-
315
- def hierarchical_admonition_names(clause, num)
316
- i = 0
317
- clause.xpath(ns(".//admonition")).each do |t|
318
- i += 1
319
- next if t["id"].nil? || t["id"].empty?
320
- @anchors[t["id"]] = anchor_struct("#{num}.#{i}", nil, @admonition_lbl, "box")
321
- end
322
- end
323
-
324
- def sequential_asset_names(clause)
325
- super
326
- sequential_admonition_names(clause)
327
- end
328
123
 
329
- def hierarchical_asset_names(clause, num)
330
- super
331
- hierarchical_admonition_names(clause, num)
332
- end
333
-
334
- def admonition_name_parse(node, div, name)
335
- div.p **{ class: "FigureTitle", align: "center" } do |p|
336
- p << l10n("#{@admonition_lbl} #{get_anchors[node['id']][:label]}")
337
- if name
338
- p << "&nbsp;&mdash; "
339
- name.children.each { |n| parse(n, div) }
124
+ def foreword(isoxml, out)
125
+ f = isoxml.at(ns("//foreword")) || return
126
+ out.div **attr_code(id: f["id"]) do |s|
127
+ page_break(out)
128
+ s.p(**{ class: "ForewordTitle" }) do |h1|
129
+ h1 << @foreword_lbl
130
+ end
131
+ f.elements.each { |e| parse(e, s) unless e.name == "title" }
340
132
  end
341
133
  end
342
- end
343
134
 
344
- def admonition_parse(node, out)
345
- name = node.at(ns("./name"))
346
- out.div **{ class: "Admonition" } do |t|
347
- admonition_name_parse(node, t, name) if name
348
- node.children.each do |n|
349
- parse(n, t) unless n.name == "name"
135
+ def word_preface(docxml)
136
+ super
137
+ preface_container = docxml.at("//div[@id = 'preface_container']") # recommendation
138
+ abstractbox = docxml.at("//div[@id = 'abstractbox']") # plenary
139
+ foreword = docxml.at("//p[@class = 'ForewordTitle']/..")
140
+ intro = docxml.at("//p[@class = 'IntroTitle']/..")
141
+ abstract = docxml.at("//p[@class = 'AbstractTitle']/..")
142
+ abstract.parent = (abstractbox || preface_container) if abstract
143
+ abstractbox and abstract&.xpath(".//p/br")&.each do |a|
144
+ a.parent.remove if /page-break-before:always/.match(a["style"])
145
+ end
146
+ docxml&.at("//p[@class = 'AbstractTitle']")&.remove if abstractbox
147
+ foreword.parent = preface_container if foreword && preface_container
148
+ intro.parent = preface_container if intro && preface_container
149
+ if preface_container && (foreword || intro)
150
+ preface_container.at("./div/p[br]").remove # remove initial page break
151
+ end
152
+ if abstractbox && !intro && !foreword && !@toc
153
+ sect2 = docxml.at("//div[@class='WordSection2']")
154
+ sect2.next_element.remove # pagebreak
155
+ sect2.remove # pagebreak
350
156
  end
351
157
  end
352
- end
353
158
 
354
- def inline_header_title(out, node, c1)
355
- title = c1&.content || ""
356
- out.span **{ class: "zzMoveToFollowing" } do |s|
357
- if get_anchors[node['id']][:label]
358
- s << "#{get_anchors[node['id']][:label]}. " unless @suppressheadingnumbers
359
- insert_tab(s, 1)
159
+ def abstract(isoxml, out)
160
+ f = isoxml.at(ns("//abstract")) || return
161
+ out.div **attr_code(id: f["id"]) do |s|
162
+ page_break(out)
163
+ s.p(**{ class: "AbstractTitle" }) { |h1| h1 << @abstract_lbl }
164
+ f.elements.each { |e| parse(e, s) unless e.name == "title" }
360
165
  end
361
- s << "#{title} "
362
166
  end
363
- end
364
167
 
365
- def abstract(isoxml, out)
366
- f = isoxml.at(ns("//abstract")) || return
367
- out.div **attr_code(id: f["id"]) do |s|
368
- page_break(out)
369
- s.p(**{ class: "AbstractTitle" }) { |h1| h1 << @abstract_lbl }
370
- f.elements.each { |e| parse(e, s) unless e.name == "title" }
371
- end
168
+ include BaseConvert
372
169
  end
373
170
  end
374
171
  end
375
- end