metanorma-itu 1.3.6 → 1.3.10

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)
@@ -113,14 +112,19 @@ module IsoDoc
113
112
  pubdate and set(:pubdate_ddMMMyyyy, monthyr(pubdate.text))
114
113
  pubdate = isoxml.at(ns("//bibdata/date[not(@format)][@type = 'published']")) ||
115
114
  isoxml.at(ns("//bibdata/copyright/from"))
116
- pubdate and set(:placedate_year,
117
- @labels["placedate"].sub(/%/, pubdate.text.sub(/^(\d\d\d\d).*$/, "\\1")))
115
+ pubdate and
116
+ set(:placedate_year,
117
+ @labels["placedate"].sub(/%/,
118
+ pubdate.text.sub(
119
+ /^(\d\d\d\d).*$/, "\\1"
120
+ )))
118
121
  end
119
122
 
120
123
  def monthyr(isodate)
121
124
  m = /(?<yr>\d\d\d\d)-(?<mo>\d\d)/.match isodate
122
125
  return isodate unless m && m[:yr] && m[:mo]
123
- return "#{m[:mo]}/#{m[:yr]}"
126
+
127
+ "#{m[:mo]}/#{m[:yr]}"
124
128
  end
125
129
 
126
130
  def keywords(isoxml, _out)
@@ -149,7 +153,9 @@ module IsoDoc
149
153
  def ddMMMYYYY(isodate)
150
154
  m = /(?<yr>\d\d\d\d)-(?<mo>\d\d)-(?<dd>\d\d)/.match isodate
151
155
  return isodate unless m && m[:yr] && m[:mo] && m[:dd]
152
- mmm = DateTime.parse(isodate).localize(@lang.to_sym).to_additional_s("MMM")
156
+
157
+ mmm = DateTime.parse(isodate).localize(@lang.to_sym)
158
+ .to_additional_s("MMM")
153
159
  @i18n.l10n("#{m[:dd]} #{mmm} #{m[:yr]}")
154
160
  end
155
161
 
@@ -184,20 +190,25 @@ module IsoDoc
184
190
  set(:meeting, a)
185
191
  set(:meeting_acronym, a)
186
192
  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)
193
+ a = isoxml&.at(ns("//bibdata/ext/meeting/@acronym"))&.text and
194
+ set(:meeting_acronym, a)
195
+ a = isoxml&.at(ns("//bibdata/ext/meeting-place"))&.text and
196
+ set(:meeting_place, a)
197
+ a = isoxml&.at(ns("//bibdata/ext/intended-type"))&.text and
198
+ set(:intended_type, a)
190
199
  a = isoxml&.at(ns("//bibdata/ext/source"))&.text and set(:source, a)
191
200
  meeting(isoxml)
192
201
  end
193
202
 
194
203
  def meeting(isoxml)
195
- resolution = isoxml&.at(ns("//bibdata/ext/doctype"))&.text == "resolution"
204
+ resolution =
205
+ isoxml&.at(ns("//bibdata/ext/doctype"))&.text == "resolution"
196
206
  if o = isoxml&.at(ns("//bibdata/ext/meeting-date/on"))&.text
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
@@ -11,7 +11,7 @@ module IsoDoc
11
11
  end
12
12
 
13
13
  def prefix_container(container, linkend, _target)
14
- l10n("#{linkend} #{@i18n.get["in"]} #{@xrefs.anchor(container, :xref)}")
14
+ l10n("#{linkend} #{@i18n.get['in']} #{@xrefs.anchor(container, :xref)}")
15
15
  end
16
16
 
17
17
  def eref(docxml)
@@ -32,12 +32,13 @@ module IsoDoc
32
32
  end
33
33
  end
34
34
 
35
- def eref1(f)
36
- get_eref_linkend(f)
35
+ def eref1(elem)
36
+ get_eref_linkend(elem)
37
37
  end
38
38
 
39
- def note1(f)
40
- return if f["type"] == "title-footnote"
39
+ def note1(elem)
40
+ return if elem["type"] == "title-footnote"
41
+
41
42
  super
42
43
  end
43
44
 
@@ -46,71 +47,76 @@ module IsoDoc
46
47
  !c.text? || /\S/.match(c)
47
48
  end
48
49
  return unless contents.empty?
49
- link = anchor_linkend(node, docid_l10n(node["target"] || node["citeas"]))
50
+
51
+ link = anchor_linkend(node,
52
+ docid_l10n(node["target"] || node["citeas"]))
50
53
  link && !/^\[.*\]$/.match(link) and link = "[#{link}]"
51
- link += eref_localities(node.xpath(ns("./locality | ./localityStack")), link, node)
52
- non_locality_elems(node).each { |n| n.remove }
54
+ link += eref_localities(node.xpath(ns("./locality | ./localityStack")),
55
+ link, node)
56
+ non_locality_elems(node).each(&:remove)
53
57
  node.add_child(link)
54
58
  end
55
59
 
56
- def bibdata_i18n(b)
60
+ def bibdata_i18n(bib)
57
61
  super
58
- bibdata_dates(b)
59
- bibdata_title(b)
60
- amendment_id(b)
62
+ bibdata_dates(bib)
63
+ bibdata_title(bib)
64
+ amendment_id(bib)
61
65
  end
62
66
 
63
- def bibdata_dates(b)
64
- b.xpath(ns("./date")).each do |d|
67
+ def bibdata_dates(bib)
68
+ bib.xpath(ns("./date")).each do |d|
65
69
  d.next = d.dup
66
70
  d.next["format"] = "ddMMMyyyy"
67
71
  d.next.children = ddMMMyyyy(d.text)
68
72
  end
69
73
  end
70
74
 
71
- def bibdata_title(b)
72
- case b&.at(ns("./ext/doctype"))&.text
73
- when "service-publication" then bibdata_title_service_population(b)
74
- when "resolution" then bibdata_title_resolution(b)
75
+ def bibdata_title(bib)
76
+ case bib&.at(ns("./ext/doctype"))&.text
77
+ when "service-publication" then bibdata_title_service_population(bib)
78
+ when "resolution" then bibdata_title_resolution(bib)
75
79
  end
76
80
  end
77
81
 
78
- def bibdata_title_resolution(b)
79
- num = b&.at(ns("./docnumber"))&.text
80
- place = b&.at(ns("./ext/meeting-place"))&.text
81
- ed = b&.at(ns("./edition"))&.text
82
- rev = (ed && ed != "1") ? "#{@i18n.get["revision_abbreviation"]} " : ""
83
- year = b&.at(ns("./ext/meeting-date/from | ./ext/meeting-date/on"))&.text&.gsub(/-.*$/, "")
84
- num = b&.at(ns("./docnumber"))&.text
85
- text = @i18n.l10n("#{@i18n.get['doctype_dict']['resolution'].upcase} #{num} (#{rev}#{place}, #{year})")
86
- ins = b.at(ns("./title"))
87
- ins.next = <<~END
88
- <title language="#{@lang}" format="text/plain" type="resolution">#{text}</title>
89
- <title language="#{@lang}" format="text/plain" type="resolution-placedate">#{place}, #{year}</title>
90
- END
91
- end
92
-
93
- def bibdata_title_service_population(b)
94
- date = b&.at(ns("./date[@type = 'published']"))&.text or return
82
+ def bibdata_title_resolution(bib)
83
+ place = bib&.at(ns("./ext/meeting-place"))&.text
84
+ ed = bib&.at(ns("./edition"))&.text
85
+ rev = ed && ed != "1" ? "#{@i18n.get['revision_abbreviation']} " : ""
86
+ year = bib&.at(ns("./ext/meeting-date/from | ./ext/meeting-date/on"))
87
+ &.text&.gsub(/-.*$/, "")
88
+ num = bib&.at(ns("./docnumber"))&.text
89
+ text = @i18n.l10n("#{@i18n.get['doctype_dict']['resolution'].upcase} "\
90
+ "#{num} (#{rev}#{place}, #{year})")
91
+ ins = bib.at(ns("./title"))
92
+ ins.next = <<~INS
93
+ <title language="#{@lang}" format="text/plain" type="resolution">#{text}</title>
94
+ <title language="#{@lang}" format="text/plain" type="resolution-placedate">#{place}, #{year}</title>
95
+ INS
96
+ end
97
+
98
+ def bibdata_title_service_population(bib)
99
+ date = bib&.at(ns("./date[@type = 'published']"))&.text or return
95
100
  text = l10n(@i18n.get["position_on"].sub(/%/, ddmmmmyyyy(date)))
96
- ins = b.at(ns("./title"))
97
- ins.next = <<~END
98
- <title language="#{@lang}" format="text/plain" type="position-sp">#{text}</title>
99
- END
101
+ ins = bib.at(ns("./title"))
102
+ ins.next = <<~INS
103
+ <title language="#{@lang}" format="text/plain" type="position-sp">#{text}</title>
104
+ INS
100
105
  end
101
106
 
102
107
  def ddMMMyyyy(date)
103
- d = date.split(/-/).map { |x| x.sub(/^0/, "") }
104
- if @lang == "zh"
105
- d[0] += "" if d.dig(0)
106
- d[1] += "" if d.dig(1)
107
- d[2] += "" if d.dig(2)
108
- d.join("")
109
- elsif @lang == "ar"
110
- d[1] = ::RomanNumerals.to_roman(d[1].to_i).upcase if d.dig(1)
108
+ d = date.split("-").map { |x| x.sub(/^0/, "") }
109
+ case @lang
110
+ when "zh"
111
+ d[0] += "" if d[0]
112
+ d[1] += "" if d[1]
113
+ d[2] += "" if d[2]
114
+ d.join
115
+ when "ar"
116
+ d[1] = ::RomanNumerals.to_roman(d[1].to_i).upcase if d[1]
111
117
  d.join(".")
112
118
  else
113
- d[1] = ::RomanNumerals.to_roman(d[1].to_i).upcase if d.dig(1)
119
+ d[1] = ::RomanNumerals.to_roman(d[1].to_i).upcase if d[1]
114
120
  d.reverse.join(".")
115
121
  end
116
122
  end
@@ -119,16 +125,16 @@ module IsoDoc
119
125
  if @lang == "zh"
120
126
  ddMMMyyyy(date)
121
127
  else
122
- d = date.split(/-/)
123
- d[1] = @meta.months[d[1].to_sym] if d.dig(1)
124
- d[2] = d[2].sub(/^0/, "") if d.dig(2)
128
+ d = date.split("-")
129
+ d[1] = @meta.months[d[1].to_sym] if d[1]
130
+ d[2] = d[2].sub(/^0/, "") if d[2]
125
131
  l10n(d.reverse.join(" "))
126
132
  end
127
133
  end
128
134
 
129
- def amendment_id(b)
135
+ def amendment_id(bib)
130
136
  %w(amendment corrigendum).each do |w|
131
- if dn = b.at(ns("./ext/structuredidentifier/#{w}"))
137
+ if dn = bib.at(ns("./ext/structuredidentifier/#{w}"))
132
138
  dn["language"] = ""
133
139
  dn.next = dn.dup
134
140
  dn.next["language"] = @lang
@@ -138,32 +144,37 @@ module IsoDoc
138
144
  end
139
145
 
140
146
  def twitter_cldr_localiser_symbols
141
- {group: "'"}
142
- end
143
-
144
- def clause1(f)
145
- return super unless f&.at(ns("//bibdata/ext/doctype"))&.text == "resolution"
146
- return super unless %w(sections bibliography).include? f.parent.name
147
- return if @suppressheadingnumbers || f["unnumbered"]
148
- t = f.at(ns("./title")) and t["depth"] = "1"
149
- lbl = @xrefs.anchor(f['id'], :label, false) or return
150
- f.elements.first.previous =
151
- "<p keep-with-next='true' class='supertitle'>#{@i18n.get['section'].upcase} #{lbl}</p>"
152
- end
153
-
154
- def annex1(f)
155
- return super unless f&.at(ns("//bibdata/ext/doctype"))&.text == "resolution"
156
- lbl = @xrefs.anchor(f['id'], :label)
157
- subhead = (@i18n.l10n("(#{@i18n.get['to']} ") +
158
- f.at(ns("//bibdata/title[@type = 'resolution']")).children.to_xml + @i18n.l10n(")"))
159
- f.elements.first.previous = "<p class='supertitle'>#{lbl}<br/>#{subhead}</p>"
160
- if t = f.at(ns("./title"))
147
+ { group: "'" }
148
+ end
149
+
150
+ def clause1(elem)
151
+ return super unless elem&.at(ns("//bibdata/ext/doctype"))&.text ==
152
+ "resolution"
153
+ return super unless %w(sections bibliography).include? elem.parent.name
154
+ return if @suppressheadingnumbers || elem["unnumbered"]
155
+
156
+ t = elem.at(ns("./title")) and t["depth"] = "1"
157
+ lbl = @xrefs.anchor(elem["id"], :label, false) or return
158
+ elem.elements.first.previous =
159
+ "<p keep-with-next='true' class='supertitle'>"\
160
+ "#{@i18n.get['section'].upcase} #{lbl}</p>"
161
+ end
162
+
163
+ def annex1(elem)
164
+ return super unless elem&.at(ns("//bibdata/ext/doctype"))&.text ==
165
+ "resolution"
166
+
167
+ lbl = @xrefs.anchor(elem["id"], :label)
168
+ subhead = (@i18n.l10n("(#{@i18n.get['to']} ") +
169
+ elem.at(ns("//bibdata/title[@type = 'resolution']"))
170
+ .children.to_xml + @i18n.l10n(")"))
171
+ elem.elements.first.previous =
172
+ "<p class='supertitle'>#{lbl}<br/>#{subhead}</p>"
173
+ t = elem.at(ns("./title")) and
161
174
  t.children = "<strong>#{t.children.to_xml}</strong>"
162
- end
163
175
  end
164
176
 
165
177
  include Init
166
178
  end
167
179
  end
168
180
  end
169
-
@@ -9,8 +9,7 @@ module IsoDoc
9
9
  end
10
10
  end
11
11
 
12
- def word_term_cleanup(docxml)
13
- end
12
+ def word_term_cleanup(docxml); end
14
13
 
15
14
  def word_cleanup(docxml)
16
15
  word_footnote_cleanup(docxml)
@@ -77,26 +76,35 @@ module IsoDoc
77
76
  @wordstylesheet&.close
78
77
  end
79
78
  Html2Doc.process(
80
- result, filename: filename,
81
- stylesheet: @wordstylesheet&.path,
82
- header_file: header&.path, dir: dir,
83
- asciimathdelims: [@openmathdelim, @closemathdelim],
84
- liststyles: { ul: @ulstyle, ol: @olstyle, steps: "l4" })
79
+ result, filename: filename,
80
+ stylesheet: @wordstylesheet&.path,
81
+ header_file: header&.path, dir: dir,
82
+ asciimathdelims: [@openmathdelim, @closemathdelim],
83
+ liststyles: { ul: @ulstyle, ol: @olstyle, steps: "l4" }
84
+ )
85
85
  header&.unlink
86
86
  @wordstylesheet&.unlink
87
87
  end
88
88
 
89
89
  def authority_hdr_cleanup(docxml)
90
- docxml&.xpath("//div[@id = 'draft-warning']").each do |d|
90
+ authority_hdr_cleanup1(docxml)
91
+ authority_hdr_cleanup2(docxml)
92
+ end
93
+
94
+ def authority_hdr_cleanup1(docxml)
95
+ docxml&.xpath("//div[@id = 'draft-warning']")&.each do |d|
91
96
  d.xpath(".//h1 | .//h2").each do |p|
92
97
  p.name = "p"
93
98
  p["class"] = "draftwarningHdr"
94
99
  end
95
100
  end
101
+ end
102
+
103
+ def authority_hdr_cleanup2(docxml)
96
104
  %w(copyright license legal).each do |t|
97
- docxml&.xpath("//div[@class = 'boilerplate-#{t}']").each do |d|
98
- p = d&.at("./descendant::h1[2]") and
99
- p.previous = "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>"
105
+ docxml&.xpath("//div[@class = 'boilerplate-#{t}']")&.each do |d|
106
+ para = d&.at("./descendant::h1[2]") and
107
+ para.previous = "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>"
100
108
  d.xpath(".//h1 | .//h2").each do |p|
101
109
  p.name = "p"
102
110
  p["class"] = "boilerplateHdr"
@@ -114,14 +122,15 @@ module IsoDoc
114
122
  auth = docxml.at("//div[@class = 'boilerplate-#{t}']")
115
123
  auth.remove if auth && !dest
116
124
  next unless auth && dest
117
- t == "copyright" and p = auth&.at(".//p") and
118
- p["class"] = "boilerplateHdr"
119
- auth&.xpath(".//p[not(@class)]")&.each_with_index do |p, i|
125
+
126
+ t == "copyright" and para = auth&.at(".//p") and
127
+ para["class"] = "boilerplateHdr"
128
+ auth&.xpath(".//p[not(@class)]")&.each_with_index do |p, _i|
120
129
  p["class"] = "boilerplate"
121
- #i == 0 && t == "copyright" and p["style"] = "text-align:center;"
130
+ # i == 0 && t == "copyright" and p["style"] = "text-align:center;"
122
131
  end
123
132
  t == "copyright" or
124
- auth << "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>"
133
+ auth << "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>"
125
134
  dest.replace(auth.remove)
126
135
  end
127
136
  end
@@ -134,8 +143,8 @@ module IsoDoc
134
143
  end
135
144
  end
136
145
 
137
- def table_list_style1(t, num)
138
- (t.xpath(".//li") - t.xpath(".//ol//li | .//ul//li")).each do |t1|
146
+ def table_list_style1(tab, num)
147
+ (tab.xpath(".//li") - tab.xpath(".//ol//li | .//ul//li")).each do |t1|
139
148
  indent_list(t1, num)
140
149
  t1.xpath("./div | ./p").each { |p| indent_list(p, num) }
141
150
  (t1.xpath(".//ul") - t1.xpath(".//ul//ul | .//ol//ul")).each do |t2|
@@ -147,9 +156,9 @@ module IsoDoc
147
156
  end
148
157
  end
149
158
 
150
- def indent_list(li, num)
151
- li["style"] = (li["style"] ? li["style"] + ";" : "")
152
- li["style"] += "margin-left: #{num * 0.5}cm;text-indent: -0.5cm;"
159
+ def indent_list(list, num)
160
+ list["style"] = (list["style"] ? "#{list['style']};" : "")
161
+ list["style"] += "margin-left: #{num * 0.5}cm;text-indent: -0.5cm;"
153
162
  end
154
163
  end
155
164
  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