metanorma-itu 1.3.6 → 1.3.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.6".freeze
3
+ VERSION = "1.3.7".freeze
4
4
  end
5
5
  end
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.6
4
+ version: 1.3.7
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-07-05 00:00:00.000000000 Z
11
+ date: 2021-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -343,6 +343,7 @@ files:
343
343
  - lib/isodoc/itu/word_cleanup.rb
344
344
  - lib/isodoc/itu/word_convert.rb
345
345
  - lib/isodoc/itu/xref.rb
346
+ - lib/isodoc/itu/xref_section.rb
346
347
  - lib/metanorma-itu.rb
347
348
  - lib/metanorma/itu.rb
348
349
  - lib/metanorma/itu/processor.rb