metanorma-itu 1.3.5 → 1.3.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,6 @@ require "twitter_cldr"
3
3
 
4
4
  module IsoDoc
5
5
  module ITU
6
-
7
6
  class Metadata < IsoDoc::Metadata
8
7
  def initialize(lang, script, labels)
9
8
  super
@@ -96,10 +95,10 @@ module IsoDoc
96
95
  lbl = oblig == "informative" ? @labels["appendix"] : @labels["annex"]
97
96
  dn and set(:annexid, @i18n.l10n("#{lbl} #{dn&.text}"))
98
97
  dn = isoxml.at(ns("//bibdata/ext/structuredidentifier/amendment")) and
99
- set(:amendmentid, @i18n.l10n("#{@labels["amendment"]} #{dn&.text}"))
98
+ set(:amendmentid, @i18n.l10n("#{@labels['amendment']} #{dn&.text}"))
100
99
  dn = isoxml.at(ns("//bibdata/ext/structuredidentifier/corrigendum")) and
101
100
  set(:corrigendumid,
102
- @i18n.l10n("#{@labels["corrigendum"]} #{dn&.text}"))
101
+ @i18n.l10n("#{@labels['corrigendum']} #{dn&.text}"))
103
102
  end
104
103
 
105
104
  def unpublished(status)
@@ -114,13 +113,17 @@ module IsoDoc
114
113
  pubdate = isoxml.at(ns("//bibdata/date[not(@format)][@type = 'published']")) ||
115
114
  isoxml.at(ns("//bibdata/copyright/from"))
116
115
  pubdate and set(:placedate_year,
117
- @labels["placedate"].sub(/%/, pubdate.text.sub(/^(\d\d\d\d).*$/, "\\1")))
116
+ @labels["placedate"].sub(/%/,
117
+ pubdate.text.sub(
118
+ /^(\d\d\d\d).*$/, "\\1"
119
+ )))
118
120
  end
119
121
 
120
122
  def monthyr(isodate)
121
123
  m = /(?<yr>\d\d\d\d)-(?<mo>\d\d)/.match isodate
122
124
  return isodate unless m && m[:yr] && m[:mo]
123
- return "#{m[:mo]}/#{m[:yr]}"
125
+
126
+ "#{m[:mo]}/#{m[:yr]}"
124
127
  end
125
128
 
126
129
  def keywords(isoxml, _out)
@@ -149,6 +152,7 @@ module IsoDoc
149
152
  def ddMMMYYYY(isodate)
150
153
  m = /(?<yr>\d\d\d\d)-(?<mo>\d\d)-(?<dd>\d\d)/.match isodate
151
154
  return isodate unless m && m[:yr] && m[:mo] && m[:dd]
155
+
152
156
  mmm = DateTime.parse(isodate).localize(@lang.to_sym).to_additional_s("MMM")
153
157
  @i18n.l10n("#{m[:dd]} #{mmm} #{m[:yr]}")
154
158
  end
@@ -184,9 +188,15 @@ module IsoDoc
184
188
  set(:meeting, a)
185
189
  set(:meeting_acronym, a)
186
190
  end
187
- a = isoxml&.at(ns("//bibdata/ext/meeting/@acronym"))&.text and set(:meeting_acronym, a)
188
- a = isoxml&.at(ns("//bibdata/ext/meeting-place"))&.text and set(:meeting_place, a)
189
- a = isoxml&.at(ns("//bibdata/ext/intended-type"))&.text and set(:intended_type, a)
191
+ a = isoxml&.at(ns("//bibdata/ext/meeting/@acronym"))&.text and set(
192
+ :meeting_acronym, a
193
+ )
194
+ a = isoxml&.at(ns("//bibdata/ext/meeting-place"))&.text and set(
195
+ :meeting_place, a
196
+ )
197
+ a = isoxml&.at(ns("//bibdata/ext/intended-type"))&.text and set(
198
+ :intended_type, a
199
+ )
190
200
  a = isoxml&.at(ns("//bibdata/ext/source"))&.text and set(:source, a)
191
201
  meeting(isoxml)
192
202
  end
@@ -197,7 +207,8 @@ module IsoDoc
197
207
  set(:meeting_date, resolution ? ddMMMMYYYY(o, nil) : ddMMMYYYY(o))
198
208
  elsif f = isoxml&.at(ns("//bibdata/ext/meeting-date/from"))&.text
199
209
  t = isoxml&.at(ns("//bibdata/ext/meeting-date/to"))&.text
200
- set(:meeting_date, resolution ? ddMMMMYYYY(f, t) : "#{ddMMMYYYY(f)}/#{ddMMMYYYY(t)}")
210
+ set(:meeting_date,
211
+ resolution ? ddMMMMYYYY(f, t) : "#{ddMMMYYYY(f)}/#{ddMMMYYYY(t)}")
201
212
  end
202
213
  end
203
214
  end
@@ -1,5 +1,6 @@
1
1
  require "isodoc"
2
2
  require "fileutils"
3
+ require_relative "./xref_section"
3
4
 
4
5
  module IsoDoc
5
6
  module ITU
@@ -16,38 +17,15 @@ module IsoDoc
16
17
  @hierarchical_assets = options[:hierarchical_assets]
17
18
  end
18
19
 
19
- def annex_name_lbl(clause, num)
20
- lbl = clause["obligation"] == "informative" ? @labels["appendix"] : @labels["annex"]
21
- @doctype == "resolution" ? l10n("#{lbl.upcase} #{num}") :
22
- l10n("<strong>#{lbl} #{num}</strong>")
23
- end
24
-
25
- def annex_names(clause, num)
26
- lbl = clause["obligation"] == "informative" ?
27
- @labels["appendix"] : @labels["annex"]
28
- @anchors[clause["id"]] =
29
- { label: annex_name_lbl(clause, num), type: "clause", xref: l10n("#{lbl} #{num}"), level: 1, value: num }
30
- if a = single_annex_special_section(clause)
31
- annex_names1(a, "#{num}", 1)
32
- else
33
- i = Counter.new
34
- clause.xpath(ns("./clause | ./references | ./terms | ./definitions")).
35
- each do |c|
36
- i.increment(c)
37
- annex_names1(c, "#{num}.#{i.print}", 2)
38
- end
39
- end
40
- hierarchical_asset_names(clause, num)
41
- end
42
-
43
20
  def back_anchor_names(docxml)
44
21
  super
45
- if annexid = docxml&.at(ns("//bibdata/ext/structuredidentifier/annexid"))&.text
22
+ if annexid = docxml
23
+ &.at(ns("//bibdata/ext/structuredidentifier/annexid"))&.text
46
24
  docxml.xpath(ns("//annex")).each { |c| annex_names(c, annexid) }
47
25
  else
48
26
  i = Counter.new(0, numerals: :roman)
49
27
  docxml.xpath(ns("//annex[@obligation = 'informative']"))
50
- .each_with_index do |c|
28
+ .each do |c|
51
29
  i.increment(c)
52
30
  annex_names(c, i.print.upcase)
53
31
  end
@@ -60,35 +38,25 @@ module IsoDoc
60
38
  end
61
39
  end
62
40
 
63
- def annex_names1(clause, num, level)
64
- @anchors[clause["id"]] =
65
- { label: num, xref: @doctype == "resolution" ? num : l10n("#{@labels["annex_subclause"]} #{num}"),
66
- level: level, type: "clause" }
67
- i = Counter.new
68
- clause.xpath(ns("./clause | ./references | ./terms | ./definitions"))
69
- .each do |c|
70
- i.increment(c)
71
- annex_names1(c, "#{num}.#{i.print}", level + 1)
41
+ def initial_anchor_names(doc)
42
+ @doctype = doc&.at(ns("//bibdata/ext/doctype"))&.text
43
+ doc.xpath(ns("//boilerplate//clause")).each { |c| preface_names(c) }
44
+ doc.xpath("//xmlns:preface/child::*").each { |c| preface_names(c) }
45
+ if @hierarchical_assets
46
+ hierarchical_asset_names(doc.xpath("//xmlns:preface/child::*"),
47
+ "Preface")
48
+ else
49
+ sequential_asset_names(doc.xpath("//xmlns:preface/child::*"))
72
50
  end
73
- end
74
-
75
- def initial_anchor_names(d)
76
- @doctype = d&.at(ns("//bibdata/ext/doctype"))&.text
77
- d.xpath(ns("//boilerplate//clause")).each { |c| preface_names(c) }
78
- d.xpath("//xmlns:preface/child::*").each { |c| preface_names(c) }
79
- @hierarchical_assets ?
80
- hierarchical_asset_names(d.xpath("//xmlns:preface/child::*"),
81
- "Preface") :
82
- sequential_asset_names(d.xpath("//xmlns:preface/child::*"))
83
51
  n = Counter.new
84
- n = section_names(d.at(ns("//clause[@type = 'scope']")), n, 1)
85
- n = section_names(d.at(ns(@klass.norm_ref_xpath)), n, 1)
86
- n = section_names(d.at(ns("//sections/terms | //sections/clause[descendant::terms]")), n, 1)
87
- n = section_names(d.at(ns("//sections/definitions")), n, 1)
88
- clause_names(d, n)
89
- middle_section_asset_names(d)
90
- termnote_anchor_names(d)
91
- termexample_anchor_names(d)
52
+ n = section_names(doc.at(ns("//clause[@type = 'scope']")), n, 1)
53
+ n = section_names(doc.at(ns(@klass.norm_ref_xpath)), n, 1)
54
+ n = section_names(doc.at(ns("//sections/terms | //sections/clause[descendant::terms]")), n, 1)
55
+ n = section_names(doc.at(ns("//sections/definitions")), n, 1)
56
+ clause_names(doc, n)
57
+ middle_section_asset_names(doc)
58
+ termnote_anchor_names(doc)
59
+ termexample_anchor_names(doc)
92
60
  end
93
61
 
94
62
  def middle_sections
@@ -99,9 +67,10 @@ module IsoDoc
99
67
  "//sections/definitions | //clause[parent::sections]"
100
68
  end
101
69
 
102
- def middle_section_asset_names(d)
70
+ def middle_section_asset_names(doc)
103
71
  return super unless @hierarchical_assets
104
- d.xpath(ns(middle_sections)).each do |c|
72
+
73
+ doc.xpath(ns(middle_sections)).each do |c|
105
74
  hierarchical_asset_names(c, @anchors[c["id"]][:label])
106
75
  end
107
76
  end
@@ -115,9 +84,11 @@ module IsoDoc
115
84
  j = 0
116
85
  c.increment(t)
117
86
  end
118
- label = c.print + (j.zero? ? "" : "#{hierfigsep}#{(96 + j).chr.to_s}")
87
+ label = c.print + (j.zero? ? "" : "#{hierfigsep}#{(96 + j).chr}")
119
88
  next if t["id"].nil? || t["id"].empty?
120
- @anchors[t["id"]] = anchor_struct(label, nil, @labels["figure"], "figure", t["unnumbered"])
89
+
90
+ @anchors[t["id"]] =
91
+ anchor_struct(label, nil, @labels["figure"], "figure", t["unnumbered"])
121
92
  end
122
93
  end
123
94
 
@@ -130,9 +101,11 @@ module IsoDoc
130
101
  j = 0
131
102
  c.increment(t)
132
103
  end
133
- label = "#{num}#{hiersep}#{c.print}" + (j.zero? ? "" : "#{hierfigsep}#{(96 + j).chr.to_s}")
104
+ label = "#{num}#{hiersep}#{c.print}" + (j.zero? ? "" : "#{hierfigsep}#{(96 + j).chr}")
134
105
  next if t["id"].nil? || t["id"].empty?
135
- @anchors[t["id"]] = anchor_struct(label, nil, @labels["figure"], "figure", t["unnumbered"])
106
+
107
+ @anchors[t["id"]] =
108
+ anchor_struct(label, nil, @labels["figure"], "figure", t["unnumbered"])
136
109
  end
137
110
  end
138
111
 
@@ -150,15 +123,19 @@ module IsoDoc
150
123
  c = Counter.new
151
124
  clause.xpath(ns(".//formula")).each do |t|
152
125
  next if t["id"].nil? || t["id"].empty?
126
+
153
127
  @anchors[t["id"]] = anchor_struct(
154
128
  "#{num}-#{c.increment(t).print}", nil,
155
- t["inequality"] ? @labels["inequality"] : @labels["formula"], "formula", t["unnumbered"])
129
+ t["inequality"] ? @labels["inequality"] : @labels["formula"],
130
+ "formula", t["unnumbered"]
131
+ )
156
132
  end
157
133
  end
158
134
 
159
135
  def reference_names(ref)
160
136
  super
161
- @anchors[ref["id"]] = { xref: @anchors[ref["id"]][:xref].sub(/^\[/, '').sub(/\]$/, '') }
137
+ @anchors[ref["id"]] =
138
+ { xref: @anchors[ref["id"]][:xref].sub(/^\[/, "").sub(/\]$/, "") }
162
139
  end
163
140
 
164
141
  def termnote_anchor_names(docxml)
@@ -167,67 +144,15 @@ module IsoDoc
167
144
  notes = t.xpath(ns(".//termnote"))
168
145
  notes.each do |n|
169
146
  return if n["id"].nil? || n["id"].empty?
147
+
170
148
  idx = notes.size == 1 ? "" : " #{c.increment(n).print}"
171
- @anchors[n["id"]] =
149
+ @anchors[n["id"]] =
172
150
  { label: termnote_label(idx).strip, type: "termnote", value: idx,
173
- xref: l10n("#{anchor(t['id'], :xref)}, #{@labels["note_xref"]} #{c.print}") }
151
+ xref: l10n("#{anchor(t['id'], :xref)},
152
+ #{@labels['note_xref']} #{c.print}") }
174
153
  end
175
154
  end
176
155
  end
177
-
178
- def clause_names(docxml, sect_num)
179
- docxml.xpath(ns("//sections/clause[not(@unnumbered = 'true')][not(@type = 'scope')][not(descendant::terms)]")).
180
- each do |c|
181
- section_names(c, sect_num, 1)
182
- end
183
- docxml.xpath(ns("//sections/clause[@unnumbered = 'true']")).each do |c|
184
- unnumbered_section_names(c, 1)
185
- end
186
- end
187
-
188
- def section_names(clause, num, lvl)
189
- return num if clause.nil?
190
- num.increment(clause)
191
- lbl = @doctype == "resolution" ? @labels["section"] : @labels["clause"]
192
- @anchors[clause["id"]] =
193
- { label: num.print, xref: l10n("#{lbl} #{num.print}"), level: lvl, type: "clause" }
194
- i = Counter.new()
195
- clause.xpath(ns(SUBCLAUSES)).each do |c|
196
- i.increment(c)
197
- section_names1(c, "#{num.print}.#{i.print}", lvl + 1)
198
- end
199
- num
200
- end
201
-
202
- def section_names1(clause, num, level)
203
- @anchors[clause["id"]] =
204
- { label: num, level: level,
205
- xref: @doctype == "resolution" ? num : l10n("#{@labels["clause"]} #{num}") }
206
- i = Counter.new()
207
- clause.xpath(ns(SUBCLAUSES)).each do |c|
208
- i.increment(c)
209
- section_names1(c, "#{num}.#{i.print}", level + 1)
210
- end
211
- end
212
-
213
- def unnumbered_section_names(clause, lvl)
214
- return if clause.nil?
215
- lbl = clause&.at(ns("./title"))&.text || "[#{clause["id"]}]"
216
- @anchors[clause["id"]] =
217
- { label: lbl, xref: l10n(%{"#{lbl}"}), level: lvl, type: "clause" }
218
- clause.xpath(ns(SUBCLAUSES)).each do |c|
219
- unnumbered_section_names1(c, lvl + 1)
220
- end
221
- end
222
-
223
- def unnumbered_section_names1(clause, level)
224
- lbl = clause&.at(ns("./title"))&.text || "[#{clause["id"]}]"
225
- @anchors[clause["id"]] =
226
- { label: lbl, xref: l10n(%{"#{lbl}"}), level: level, type: "clause" }
227
- clause.xpath(ns(SUBCLAUSES)).each do |c|
228
- unnumbered_section_names1(c, level + 1)
229
- end
230
- end
231
156
  end
232
157
  end
233
158
  end
@@ -0,0 +1,109 @@
1
+ module IsoDoc
2
+ module ITU
3
+ class Xref < IsoDoc::Xref
4
+ def annextype(clause)
5
+ if clause["obligation"] == "informative" then @labels["appendix"]
6
+ else @labels["annex"]
7
+ end
8
+ end
9
+
10
+ def annex_name_lbl(clause, num)
11
+ lbl = annextype(clause)
12
+ if @doctype == "resolution"
13
+ l10n("#{lbl.upcase} #{num}")
14
+ else
15
+ l10n("<strong>#{lbl} #{num}</strong>")
16
+ end
17
+ end
18
+
19
+ def annex_names(clause, num)
20
+ lbl = annextype(clause)
21
+ @anchors[clause["id"]] =
22
+ { label: annex_name_lbl(clause, num), type: "clause",
23
+ xref: l10n("#{lbl} #{num}"), level: 1, value: num }
24
+ if a = single_annex_special_section(clause)
25
+ annex_names1(a, num.to_s, 1)
26
+ else
27
+ i = Counter.new
28
+ clause.xpath(ns("./clause | ./references | ./terms | ./definitions"))
29
+ .each do |c|
30
+ i.increment(c)
31
+ annex_names1(c, "#{num}.#{i.print}", 2)
32
+ end
33
+ end
34
+ hierarchical_asset_names(clause, num)
35
+ end
36
+
37
+ def annex_names1(clause, num, level)
38
+ @anchors[clause["id"]] =
39
+ { label: num,
40
+ xref: @doctype == "resolution" ? num : l10n("#{@labels['annex_subclause']} #{num}"),
41
+ level: level, type: "clause" }
42
+ i = Counter.new
43
+ clause.xpath(ns("./clause | ./references | ./terms | ./definitions"))
44
+ .each do |c|
45
+ i.increment(c)
46
+ annex_names1(c, "#{num}.#{i.print}", level + 1)
47
+ end
48
+ end
49
+
50
+ def clause_names(docxml, sect_num)
51
+ docxml.xpath(ns("//sections/clause[not(@unnumbered = 'true')]"\
52
+ "[not(@type = 'scope')][not(descendant::terms)]"))
53
+ .each do |c|
54
+ section_names(c, sect_num, 1)
55
+ end
56
+ docxml.xpath(ns("//sections/clause[@unnumbered = 'true']")).each do |c|
57
+ unnumbered_section_names(c, 1)
58
+ end
59
+ end
60
+
61
+ def section_names(clause, num, lvl)
62
+ return num if clause.nil?
63
+
64
+ num.increment(clause)
65
+ lbl = @doctype == "resolution" ? @labels["section"] : @labels["clause"]
66
+ @anchors[clause["id"]] =
67
+ { label: num.print, xref: l10n("#{lbl} #{num.print}"),
68
+ level: lvl, type: "clause" }
69
+ i = Counter.new
70
+ clause.xpath(ns(SUBCLAUSES)).each do |c|
71
+ i.increment(c)
72
+ section_names1(c, "#{num.print}.#{i.print}", lvl + 1)
73
+ end
74
+ num
75
+ end
76
+
77
+ def section_names1(clause, num, level)
78
+ @anchors[clause["id"]] =
79
+ { label: num, level: level,
80
+ xref: @doctype == "resolution" ? num : l10n("#{@labels['clause']} #{num}") }
81
+ i = Counter.new
82
+ clause.xpath(ns(SUBCLAUSES)).each do |c|
83
+ i.increment(c)
84
+ section_names1(c, "#{num}.#{i.print}", level + 1)
85
+ end
86
+ end
87
+
88
+ def unnumbered_section_names(clause, lvl)
89
+ return if clause.nil?
90
+
91
+ lbl = clause&.at(ns("./title"))&.text || "[#{clause['id']}]"
92
+ @anchors[clause["id"]] =
93
+ { label: lbl, xref: l10n(%{"#{lbl}"}), level: lvl, type: "clause" }
94
+ clause.xpath(ns(SUBCLAUSES)).each do |c|
95
+ unnumbered_section_names1(c, lvl + 1)
96
+ end
97
+ end
98
+
99
+ def unnumbered_section_names1(clause, level)
100
+ lbl = clause&.at(ns("./title"))&.text || "[#{clause['id']}]"
101
+ @anchors[clause["id"]] =
102
+ { label: lbl, xref: l10n(%{"#{lbl}"}), level: level, type: "clause" }
103
+ clause.xpath(ns(SUBCLAUSES)).each do |c|
104
+ unnumbered_section_names1(c, level + 1)
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -21,10 +21,10 @@ module Metanorma
21
21
  def fonts_manifest
22
22
  {
23
23
  "Arial" => nil,
24
- "Courier" => nil,
25
24
  "Courier New" => nil,
26
25
  "Times New Roman" => nil,
27
26
  "Source Han Sans" => nil,
27
+ "Source Han Sans Normal" => nil,
28
28
  "STIX Two Math" => nil,
29
29
  }
30
30
  end
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module ITU
3
- VERSION = "1.3.5".freeze
3
+ VERSION = "1.3.9".freeze
4
4
  end
5
5
  end
@@ -25,8 +25,8 @@ Gem::Specification.new do |spec|
25
25
  spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
26
26
 
27
27
  spec.add_dependency "htmlentities", "~> 4.3.4"
28
- spec.add_dependency "isodoc", "~> 1.6.0"
29
- spec.add_dependency "metanorma-standoc", "~> 1.9.0"
28
+ spec.add_dependency "isodoc", "~> 1.7.0"
29
+ spec.add_dependency "metanorma-standoc", "~> 1.10.0"
30
30
  spec.add_dependency "ruby-jing"
31
31
  spec.add_dependency "twitter_cldr"
32
32
  spec.add_dependency "tzinfo-data" # we need this for windows only