metanorma-itu 1.3.4 → 1.3.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,12 +5,12 @@ require "fileutils"
5
5
  module IsoDoc
6
6
  module ITU
7
7
  module BaseConvert
8
- def nonstd_bibitem(list, b, ordinal, biblio)
8
+ def nonstd_bibitem(list, b, _ordinal, biblio)
9
9
  list.tr **attr_code(iso_bibitem_entry_attrs(b, biblio)) do |ref|
10
10
  id = render_identifier(bibitem_ref_code(b))
11
- ref.td **{style: "vertical-align:top"} do |td|
12
- td << (id[0] || "[#{id[1]}]")&.
13
- gsub(/-/, "&#x2011;")&.gsub(/ /, "&#xa0;")
11
+ ref.td **{ style: "vertical-align:top" } do |td|
12
+ td << (id[0] || "[#{id[1]}]")
13
+ &.gsub(/-/, "&#x2011;")&.gsub(/ /, "&#xa0;")
14
14
  date_note_process(b, td)
15
15
  end
16
16
  ref.td { |td| reference_format(b, td) }
@@ -28,6 +28,7 @@ module IsoDoc
28
28
  f.elements.each do |b|
29
29
  if b.name == "bibitem"
30
30
  next if implicit_reference(b)
31
+
31
32
  i += 1
32
33
  nonstd_bibitem(tbody, b, i, biblio)
33
34
  else
@@ -45,6 +46,7 @@ module IsoDoc
45
46
 
46
47
  def bracket_if_num(x)
47
48
  return nil if x.nil?
49
+
48
50
  x = x.text.sub(/^\[/, "").sub(/\]$/, "")
49
51
  "[#{x}]"
50
52
  end
@@ -55,7 +57,7 @@ module IsoDoc
55
57
  end
56
58
 
57
59
  def titlecase(s)
58
- s.gsub(/ |\_|\-/, " ").split(/ /).map(&:capitalize).join(" ")
60
+ s.gsub(/ |_|-/, " ").split(/ /).map(&:capitalize).join(" ")
59
61
  end
60
62
 
61
63
  def pref_ref_code(b)
@@ -71,23 +73,27 @@ module IsoDoc
71
73
  id.empty? and
72
74
  id = b.xpath(ns("./docidentifier[not(@type = 'metanorma')]"))
73
75
  return [] if id.empty?
76
+
74
77
  id.sort_by { |i| i["type"] == "ITU" ? 0 : 1 }
75
78
  end
76
79
 
77
80
  def render_multi_identifiers(ids)
78
81
  ids.map do |id|
79
- id["type"] == "ITU" ? doctype_title(id) :
82
+ if id["type"] == "ITU"
83
+ doctype_title(id)
84
+ else
80
85
  docid_prefix(id["type"], id.text.sub(/^\[/, "").sub(/\]$/, ""))
86
+ end
81
87
  end.join(" | ")
82
88
  end
83
89
 
84
90
  def doctype_title(id)
85
91
  type = id.parent&.at(ns("./ext/doctype"))&.text || "recommendation"
86
92
  if type == "recommendation" &&
87
- /^(?<prefix>ITU-[A-Z] [A-Z])[ .-]Sup[a-z]*\.[ ]?(?<num>\d+)$/ =~ id.text
93
+ /^(?<prefix>ITU-[A-Z] [A-Z])[ .-]Sup[a-z]*\. ?(?<num>\d+)$/ =~ id.text
88
94
  "#{prefix}-series Recommendations – Supplement #{num}"
89
95
  else
90
- d = docid_prefix(id["type"], id.text.sub(/^\[/, '').sub(/\]$/, ''))
96
+ d = docid_prefix(id["type"], id.text.sub(/^\[/, "").sub(/\]$/, ""))
91
97
  "#{titlecase(type)} #{d}"
92
98
  end
93
99
  end
@@ -98,7 +104,7 @@ module IsoDoc
98
104
  r << id1
99
105
  date = b.at(ns("./date[@type = 'published']")) and
100
106
  r << " (#{date.text.sub(/-.*$/, '')})"
101
- r << ", " if (date || !id1.empty?)
107
+ r << ", " if date || !id1.empty?
102
108
  end
103
109
 
104
110
  def reference_format_title(b, r)
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module ITU
3
- VERSION = "1.3.4".freeze
3
+ VERSION = "1.3.8".freeze
4
4
  end
5
5
  end
@@ -22,11 +22,11 @@ Gem::Specification.new do |spec|
22
22
  spec.bindir = "exe"
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ["lib"]
25
- spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-itu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 1.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-07 00:00:00.000000000 Z
11
+ date: 2021-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.6.0
33
+ version: 1.7.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.6.0
40
+ version: 1.7.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: metanorma-standoc
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.9.0
47
+ version: 1.10.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.9.0
54
+ version: 1.10.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: ruby-jing
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -333,6 +333,7 @@ files:
333
333
  - lib/isodoc/itu/itu.recommendation-supplement.xsl
334
334
  - lib/isodoc/itu/itu.recommendation.xsl
335
335
  - lib/isodoc/itu/itu.resolution.xsl
336
+ - lib/isodoc/itu/itu.service-publication.xsl
336
337
  - lib/isodoc/itu/itu.technical-paper.xsl
337
338
  - lib/isodoc/itu/itu.technical-report.xsl
338
339
  - lib/isodoc/itu/metadata.rb
@@ -343,6 +344,7 @@ files:
343
344
  - lib/isodoc/itu/word_cleanup.rb
344
345
  - lib/isodoc/itu/word_convert.rb
345
346
  - lib/isodoc/itu/xref.rb
347
+ - lib/isodoc/itu/xref_section.rb
346
348
  - lib/metanorma-itu.rb
347
349
  - lib/metanorma/itu.rb
348
350
  - lib/metanorma/itu/processor.rb
@@ -360,7 +362,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
360
362
  requirements:
361
363
  - - ">="
362
364
  - !ruby/object:Gem::Version
363
- version: 2.4.0
365
+ version: 2.5.0
364
366
  required_rubygems_version: !ruby/object:Gem::Requirement
365
367
  requirements:
366
368
  - - ">="