isodoc 1.5.5 → 1.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +2 -12
  3. data/.hound.yml +3 -1
  4. data/.rubocop.yml +3 -7
  5. data/Gemfile +2 -2
  6. data/Rakefile +2 -2
  7. data/bin/rspec +1 -2
  8. data/isodoc.gemspec +11 -11
  9. data/lib/isodoc-yaml/i18n-ar.yaml +152 -0
  10. data/lib/isodoc-yaml/i18n-de.yaml +149 -0
  11. data/lib/isodoc-yaml/i18n-es.yaml +151 -0
  12. data/lib/isodoc-yaml/i18n-ru.yaml +154 -0
  13. data/lib/isodoc.rb +0 -2
  14. data/lib/isodoc/base_style/all.css +7 -0
  15. data/lib/isodoc/base_style/metanorma_word.css +7 -0
  16. data/lib/isodoc/base_style/metanorma_word.scss +8 -0
  17. data/lib/isodoc/base_style/reset.css +7 -0
  18. data/lib/isodoc/base_style/reset.scss +9 -0
  19. data/lib/isodoc/base_style/scripts.html +187 -0
  20. data/lib/isodoc/class_utils.rb +6 -5
  21. data/lib/isodoc/common.rb +2 -0
  22. data/lib/isodoc/convert.rb +30 -17
  23. data/lib/isodoc/css.rb +43 -34
  24. data/lib/isodoc/function/blocks.rb +21 -4
  25. data/lib/isodoc/function/blocks_example_note.rb +2 -2
  26. data/lib/isodoc/function/cleanup.rb +53 -45
  27. data/lib/isodoc/function/form.rb +51 -0
  28. data/lib/isodoc/function/inline.rb +37 -15
  29. data/lib/isodoc/function/references.rb +55 -42
  30. data/lib/isodoc/function/section.rb +29 -16
  31. data/lib/isodoc/function/table.rb +1 -0
  32. data/lib/isodoc/function/to_word_html.rb +33 -29
  33. data/lib/isodoc/function/utils.rb +180 -159
  34. data/lib/isodoc/gem_tasks.rb +30 -31
  35. data/lib/isodoc/headlesshtml_convert.rb +8 -7
  36. data/lib/isodoc/html_convert.rb +6 -4
  37. data/lib/isodoc/html_function/comments.rb +2 -0
  38. data/lib/isodoc/html_function/footnotes.rb +14 -7
  39. data/lib/isodoc/html_function/form.rb +62 -0
  40. data/lib/isodoc/html_function/html.rb +30 -26
  41. data/lib/isodoc/html_function/postprocess.rb +41 -82
  42. data/lib/isodoc/html_function/postprocess_footnotes.rb +59 -0
  43. data/lib/isodoc/i18n.rb +33 -31
  44. data/lib/isodoc/pdf_convert.rb +12 -16
  45. data/lib/isodoc/presentation_function/bibdata.rb +54 -30
  46. data/lib/isodoc/presentation_function/block.rb +17 -8
  47. data/lib/isodoc/presentation_function/inline.rb +84 -120
  48. data/lib/isodoc/presentation_function/math.rb +84 -0
  49. data/lib/isodoc/presentation_function/section.rb +20 -22
  50. data/lib/isodoc/presentation_xml_convert.rb +2 -1
  51. data/lib/isodoc/sassc_importer.rb +1 -1
  52. data/lib/isodoc/version.rb +1 -1
  53. data/lib/isodoc/word_function/body.rb +28 -24
  54. data/lib/isodoc/word_function/footnotes.rb +22 -15
  55. data/lib/isodoc/word_function/postprocess.rb +50 -36
  56. data/lib/isodoc/xref.rb +9 -10
  57. data/lib/isodoc/xref/xref_counter.rb +32 -17
  58. data/lib/isodoc/xref/xref_gen.rb +33 -21
  59. data/lib/isodoc/xref/xref_gen_seq.rb +60 -35
  60. data/lib/isodoc/xref/xref_sect_gen.rb +37 -35
  61. data/lib/isodoc/xslfo_convert.rb +36 -27
  62. data/spec/assets/scripts_override.html +3 -0
  63. data/spec/isodoc/blocks_spec.rb +2490 -2591
  64. data/spec/isodoc/cleanup_spec.rb +1107 -1109
  65. data/spec/isodoc/footnotes_spec.rb +1 -16
  66. data/spec/isodoc/form_spec.rb +156 -0
  67. data/spec/isodoc/i18n_spec.rb +984 -972
  68. data/spec/isodoc/inline_spec.rb +1129 -912
  69. data/spec/isodoc/lists_spec.rb +316 -315
  70. data/spec/isodoc/postproc_spec.rb +1751 -1540
  71. data/spec/isodoc/presentation_xml_spec.rb +403 -323
  72. data/spec/isodoc/ref_spec.rb +718 -723
  73. data/spec/isodoc/section_spec.rb +910 -902
  74. data/spec/isodoc/table_spec.rb +566 -556
  75. data/spec/isodoc/terms_spec.rb +251 -255
  76. data/spec/isodoc/xref_spec.rb +3041 -2992
  77. data/spec/isodoc/xslfo_convert_spec.rb +39 -0
  78. data/spec/spec_helper.rb +30 -29
  79. metadata +77 -65
@@ -2,16 +2,17 @@ require "roman-numerals"
2
2
 
3
3
  module IsoDoc::XrefGen
4
4
  class Counter
5
- def initialize(num = 0, opts = {numerals: :arabic})
5
+ def initialize(num = 0, opts = { numerals: :arabic })
6
6
  @num = num
7
7
  @letter = ""
8
8
  @subseq = ""
9
9
  @letter_override = nil
10
10
  @number_override = nil
11
11
  @style = opts[:numerals]
12
+ @skip_i = opts[:skip_i]
12
13
  @base = ""
13
14
  if num.is_a? String
14
- if /^\d+$/.match(num)
15
+ if /^\d+$/.match?(num)
15
16
  @num = num.to_i
16
17
  else
17
18
  @num = nil
@@ -34,7 +35,7 @@ module IsoDoc::XrefGen
34
35
  @base = b
35
36
  else
36
37
  @letter_override = node["number"]
37
- @letter = @letter_override if /^[a-zA-Z]$/.match(@letter_override)
38
+ @letter = @letter_override if /^[a-zA-Z]$/.match?(@letter_override)
38
39
  end
39
40
  end
40
41
  end
@@ -48,8 +49,7 @@ module IsoDoc::XrefGen
48
49
  @base = node["number"][0..-2]
49
50
  @letter = @letter_override = node["number"][-1]
50
51
  else
51
- @number_override = node["number"]
52
- @num = n.to_i
52
+ @number_override = @num = n.to_i
53
53
  @base = b
54
54
  @letter = ""
55
55
  end
@@ -64,7 +64,7 @@ module IsoDoc::XrefGen
64
64
  @letter_override = node["number"]
65
65
  /^(?<b>.*?)(?<n>\d*)(?<a>[a-zA-Z])$/ =~ node["number"]
66
66
  if blank?(a)
67
- if /^\d+$/.match(node["number"])
67
+ if /^\d+$/.match?(node["number"])
68
68
  @letter_override = @letter = ""
69
69
  @number_override = @num = node["number"].to_i
70
70
  else
@@ -80,32 +80,46 @@ module IsoDoc::XrefGen
80
80
  @number_override = @num = n.to_i unless n.empty?
81
81
  end
82
82
  else
83
- @letter = (@letter.ord + 1).chr.to_s
83
+ increment_letter
84
+ end
85
+ end
86
+
87
+ def increment_letter
88
+ case @letter
89
+ when "Z"
90
+ @letter = "@"
91
+ @base = @base.empty? ? "A" : @base[0..-2] + (@base[-1].ord + 1).chr.to_s
92
+ when "z"
93
+ @letter = "`"
94
+ @base = @base.empty? ? "a" : @base[0..-2] + (@base[-1].ord + 1).chr.to_s
84
95
  end
96
+ @letter = (@letter.ord + 1).chr.to_s
97
+ @skip_i && %w(i I).include?(@letter) and
98
+ @letter = (@letter.ord + 1).chr.to_s
85
99
  end
86
100
 
87
- def blank?(x)
88
- x.nil? || x.empty?
101
+ def blank?(str)
102
+ str.nil? || str.empty?
89
103
  end
90
104
 
91
105
  def increment(node)
92
106
  return self if node["unnumbered"]
107
+
93
108
  @letter_override = nil
94
109
  @number_override = nil
95
- if node["subsequence"] != @subseq && !(blank?(node["subsequence"]) && blank?(@subseq))
110
+ if node["subsequence"] != @subseq &&
111
+ !(blank?(node["subsequence"]) && blank?(@subseq))
96
112
  new_subseq_increment(node)
97
- elsif @letter.empty?
98
- sequence_increment(node)
99
- else
100
- subsequence_increment(node)
113
+ elsif @letter.empty? then sequence_increment(node)
114
+ else subsequence_increment(node)
101
115
  end
102
116
  self
103
117
  end
104
118
 
105
119
  def print
106
120
  num = @number_override || @num
107
- num_out = @style == :roman && !num.nil? ? RomanNumerals.to_roman(num) : num
108
- "#{@base}#{num_out}#{@letter_override || @letter}"
121
+ out = @style == :roman && !num.nil? ? RomanNumerals.to_roman(num) : num
122
+ "#{@base}#{out}#{@letter_override || @letter}"
109
123
  end
110
124
 
111
125
  def ol_type(list, depth)
@@ -115,7 +129,8 @@ module IsoDoc::XrefGen
115
129
  return :alphabet_upper if [4, 9].include? depth
116
130
  return :roman if [3, 8].include? depth
117
131
  return :roman_upper if [5, 10].include? depth
118
- return :arabic
132
+
133
+ :arabic
119
134
  end
120
135
 
121
136
  def listlabel(list, depth)
@@ -1,4 +1,4 @@
1
- require_relative "xref_gen_seq.rb"
1
+ require_relative "xref_gen_seq"
2
2
 
3
3
  module IsoDoc::XrefGen
4
4
  module Blocks
@@ -10,35 +10,43 @@ module IsoDoc::XrefGen
10
10
  autonum = amend_autonums(a)
11
11
  NUMBERED_BLOCKS.each do |b|
12
12
  a.xpath(ns("./newcontent//#{b}")).each_with_index do |e, i|
13
- autonum[b] and i == 0 and e["number"] = autonum[b]
13
+ autonum[b] && i.zero? and e["number"] = autonum[b]
14
14
  !autonum[b] and e["unnumbered"] = "true"
15
15
  end
16
16
  end
17
17
  end
18
18
  end
19
19
 
20
- def amend_autonums(a)
20
+ def amend_autonums(amend)
21
21
  autonum = {}
22
- a.xpath(ns("./autonumber")).each do |n|
22
+ amend.xpath(ns("./autonumber")).each do |n|
23
23
  autonum[n["type"]] = n.text
24
24
  end
25
25
  autonum
26
26
  end
27
27
 
28
- def termnote_label(n)
29
- @labels["termnote"].gsub(/%/, n.to_s)
28
+ def termnote_label(note)
29
+ @labels["termnote"].gsub(/%/, note.to_s)
30
+ end
31
+
32
+ def increment_label(elems, node, counter, increment = true)
33
+ return "" if elems.size == 1 && !node["number"]
34
+
35
+ counter.increment(node) if increment
36
+ " #{counter.print}"
30
37
  end
31
38
 
32
39
  def termnote_anchor_names(docxml)
33
40
  docxml.xpath(ns("//term[descendant::termnote]")).each do |t|
34
41
  c = Counter.new
35
42
  t.xpath(ns(".//termnote")).each do |n|
36
- return if n["id"].nil? || n["id"].empty?
43
+ next if n["id"].nil? || n["id"].empty?
44
+
37
45
  c.increment(n)
38
46
  @anchors[n["id"]] =
39
47
  { label: termnote_label(c.print), type: "termnote", value: c.print,
40
48
  xref: l10n("#{anchor(t['id'], :xref)}, "\
41
- "#{@labels["note_xref"]} #{c.print}") }
49
+ "#{@labels['note_xref']} #{c.print}") }
42
50
  end
43
51
  end
44
52
  end
@@ -48,13 +56,14 @@ module IsoDoc::XrefGen
48
56
  examples = t.xpath(ns(".//termexample"))
49
57
  c = Counter.new
50
58
  examples.each do |n|
51
- return if n["id"].nil? || n["id"].empty?
59
+ next if n["id"].nil? || n["id"].empty?
60
+
52
61
  c.increment(n)
53
- idx = examples.size == 1 && !n["number"] ? "" : c.print
62
+ idx = increment_label(examples, n, c, false)
54
63
  @anchors[n["id"]] = {
55
64
  type: "termexample", label: idx, value: c.print,
56
65
  xref: l10n("#{anchor(t['id'], :xref)}, "\
57
- "#{@labels["example_xref"]} #{c.print}") }
66
+ "#{@labels['example_xref']} #{c.print}") }
58
67
  end
59
68
  end
60
69
  end
@@ -81,9 +90,10 @@ module IsoDoc::XrefGen
81
90
  c = Counter.new
82
91
  notes.each do |n|
83
92
  next if @anchors[n["id"]] || n["id"].nil? || n["id"].empty?
84
- idx = notes.size == 1 && !n["number"] ? "" : " #{c.increment(n).print}"
85
- @anchors[n["id"]] = anchor_struct(idx, n, @labels["note_xref"],
86
- "note", false)
93
+
94
+ @anchors[n["id"]] =
95
+ anchor_struct(increment_label(notes, n, c), n,
96
+ @labels["note_xref"], "note", false)
87
97
  end
88
98
  note_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
89
99
  end
@@ -103,10 +113,10 @@ module IsoDoc::XrefGen
103
113
  c = Counter.new
104
114
  notes.each do |n|
105
115
  next if @anchors[n["id"]] || n["id"].nil? || n["id"].empty?
106
- idx = notes.size == 1 && !n["number"] ? "" :
107
- " #{c.increment(n).print}"
108
- @anchors[n["id"]] = anchor_struct(idx, n, @labels["example_xref"],
109
- "example", n["unnumbered"])
116
+
117
+ @anchors[n["id"]] =
118
+ anchor_struct(increment_label(notes, n, c), n,
119
+ @labels["example_xref"], "example", n["unnumbered"])
110
120
  end
111
121
  example_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
112
122
  end
@@ -119,9 +129,9 @@ module IsoDoc::XrefGen
119
129
  c = Counter.new
120
130
  notes.each do |n|
121
131
  next if n["id"].nil? || n["id"].empty?
122
- idx = notes.size == 1 && !n["number"] ? "" : " #{c.increment(n).print}"
123
- @anchors[n["id"]] = anchor_struct(idx, n, @labels["list"], "list",
124
- false)
132
+
133
+ @anchors[n["id"]] = anchor_struct(increment_label(notes, n, c), n,
134
+ @labels["list"], "list", false)
125
135
  list_item_anchor_names(n, @anchors[n["id"]], 1, "", notes.size != 1)
126
136
  end
127
137
  list_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
@@ -146,9 +156,11 @@ module IsoDoc::XrefGen
146
156
  def bookmark_anchor_names(docxml)
147
157
  docxml.xpath(ns(".//bookmark")).each do |n|
148
158
  next if n["id"].nil? || n["id"].empty?
159
+
149
160
  parent = nil
150
161
  n.ancestors.each do |a|
151
162
  next unless a["id"] && parent = @anchors.dig(a["id"], :xref)
163
+
152
164
  break
153
165
  end
154
166
  @anchors[n["id"]] = { type: "bookmark", label: nil, value: nil,
@@ -8,25 +8,27 @@ module IsoDoc::XrefGen
8
8
  "-"
9
9
  end
10
10
 
11
- def subfigure_increment(j, c, t)
12
- if t.parent.name == "figure" then j += 1
11
+ def subfigure_increment(idx, counter, elem)
12
+ if elem.parent.name == "figure" then idx += 1
13
13
  else
14
- j = 0
15
- c.increment(t)
14
+ idx = 0
15
+ counter.increment(elem)
16
16
  end
17
- j
17
+ idx
18
18
  end
19
19
 
20
20
  def sequential_figure_names(clause)
21
21
  c = Counter.new
22
22
  j = 0
23
- clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]")).
24
- each do |t|
23
+ clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]"))
24
+ .each do |t|
25
25
  j = subfigure_increment(j, c, t)
26
26
  label = c.print + (j.zero? ? "" : "-#{j}")
27
27
  next if t["id"].nil? || t["id"].empty?
28
- @anchors[t["id"]] =
29
- anchor_struct(label, nil, @labels["figure"], "figure", t["unnumbered"])
28
+
29
+ @anchors[t["id"]] = anchor_struct(
30
+ label, nil, @labels["figure"], "figure", t["unnumbered"]
31
+ )
30
32
  end
31
33
  end
32
34
 
@@ -34,8 +36,11 @@ module IsoDoc::XrefGen
34
36
  c = Counter.new
35
37
  clause.xpath(ns(".//table")).each do |t|
36
38
  next if t["id"].nil? || t["id"].empty?
37
- @anchors[t["id"]] = anchor_struct(c.increment(t).print, nil,
38
- @labels["table"], "table", t["unnumbered"])
39
+
40
+ @anchors[t["id"]] = anchor_struct(
41
+ c.increment(t).print, nil,
42
+ @labels["table"], "table", t["unnumbered"]
43
+ )
39
44
  end
40
45
  end
41
46
 
@@ -43,10 +48,12 @@ module IsoDoc::XrefGen
43
48
  c = Counter.new
44
49
  clause.xpath(ns(".//formula")).each do |t|
45
50
  next if t["id"].nil? || t["id"].empty?
46
- @anchors[t["id"]] =
47
- anchor_struct(c.increment(t).print, t,
48
- t["inequality"] ? @labels["inequality"] : @labels["formula"],
49
- "formula", t["unnumbered"])
51
+
52
+ @anchors[t["id"]] = anchor_struct(
53
+ c.increment(t).print, t,
54
+ t["inequality"] ? @labels["inequality"] : @labels["formula"],
55
+ "formula", t["unnumbered"]
56
+ )
50
57
  end
51
58
  end
52
59
 
@@ -57,22 +64,27 @@ module IsoDoc::XrefGen
57
64
  c = Counter.new
58
65
  clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}")).each do |t|
59
66
  next if t["id"].nil? || t["id"].empty?
67
+
60
68
  id = c.increment(t).print
61
69
  @anchors[t["id"]] = anchor_struct(id, t, label, klass, t["unnumbered"])
62
70
  sequential_permission_names2(t, id)
63
71
  end
64
72
  end
65
73
 
66
- def sequential_permission_names2(t, id)
67
- sequential_permission_names1(t, id, "permission", @labels["permission"])
68
- sequential_permission_names1(t, id, "requirement", @labels["requirement"])
69
- sequential_permission_names1(t, id, "recommendation", @labels["recommendation"])
74
+ def sequential_permission_names2(elem, ident)
75
+ sequential_permission_names1(elem, ident, "permission",
76
+ @labels["permission"])
77
+ sequential_permission_names1(elem, ident, "requirement",
78
+ @labels["requirement"])
79
+ sequential_permission_names1(elem, ident, "recommendation",
80
+ @labels["recommendation"])
70
81
  end
71
82
 
72
83
  def sequential_permission_names1(block, lbl, klass, label)
73
84
  c = Counter.new
74
85
  block.xpath(ns("./#{klass}")).each do |t|
75
86
  next if t["id"].nil? || t["id"].empty?
87
+
76
88
  id = "#{lbl}#{hierfigsep}#{c.increment(t).print}"
77
89
  @anchors[t["id"]] = anchor_struct(id, t, label, klass, t["unnumbered"])
78
90
  sequential_permission_names2(t, id)
@@ -85,20 +97,22 @@ module IsoDoc::XrefGen
85
97
  sequential_formula_names(clause)
86
98
  sequential_permission_names(clause, "permission", @labels["permission"])
87
99
  sequential_permission_names(clause, "requirement", @labels["requirement"])
88
- sequential_permission_names(clause, "recommendation", @labels["recommendation"])
100
+ sequential_permission_names(clause, "recommendation",
101
+ @labels["recommendation"])
89
102
  end
90
103
 
91
104
  def hierarchical_figure_names(clause, num)
92
105
  c = Counter.new
93
106
  j = 0
94
- clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]")).
95
- each do |t|
107
+ clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]"))
108
+ .each do |t|
96
109
  j = subfigure_increment(j, c, t)
97
110
  label = "#{num}#{hiersep}#{c.print}" +
98
111
  (j.zero? ? "" : "#{hierfigsep}#{j}")
99
112
  next if t["id"].nil? || t["id"].empty?
100
- @anchors[t["id"]] = anchor_struct(label, nil, @labels["figure"], "figure",
101
- t["unnumbered"])
113
+
114
+ @anchors[t["id"]] = anchor_struct(label, nil, @labels["figure"],
115
+ "figure", t["unnumbered"])
102
116
  end
103
117
  end
104
118
 
@@ -106,6 +120,7 @@ module IsoDoc::XrefGen
106
120
  c = Counter.new
107
121
  clause.xpath(ns(".//table")).each do |t|
108
122
  next if t["id"].nil? || t["id"].empty?
123
+
109
124
  @anchors[t["id"]] =
110
125
  anchor_struct("#{num}#{hiersep}#{c.increment(t).print}",
111
126
  nil, @labels["table"], "table", t["unnumbered"])
@@ -116,7 +131,8 @@ module IsoDoc::XrefGen
116
131
  hierarchical_table_names(clause, num)
117
132
  hierarchical_figure_names(clause, num)
118
133
  hierarchical_formula_names(clause, num)
119
- hierarchical_permission_names(clause, num, "permission", @labels["permission"])
134
+ hierarchical_permission_names(clause, num, "permission",
135
+ @labels["permission"])
120
136
  hierarchical_permission_names(clause, num, "requirement",
121
137
  @labels["requirement"])
122
138
  hierarchical_permission_names(clause, num, "recommendation",
@@ -127,10 +143,12 @@ module IsoDoc::XrefGen
127
143
  c = Counter.new
128
144
  clause.xpath(ns(".//formula")).each do |t|
129
145
  next if t["id"].nil? || t["id"].empty?
130
- @anchors[t["id"]] =
131
- anchor_struct("#{num}#{hiersep}#{c.increment(t).print}", nil,
132
- t["inequality"] ? @labels["inequality"] : @labels["formula"],
133
- "formula", t["unnumbered"])
146
+
147
+ @anchors[t["id"]] = anchor_struct(
148
+ "#{num}#{hiersep}#{c.increment(t).print}", nil,
149
+ t["inequality"] ? @labels["inequality"] : @labels["formula"],
150
+ "formula", t["unnumbered"]
151
+ )
134
152
  end
135
153
  end
136
154
 
@@ -138,24 +156,31 @@ module IsoDoc::XrefGen
138
156
  c = Counter.new
139
157
  clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}")).each do |t|
140
158
  next if t["id"].nil? || t["id"].empty?
159
+
141
160
  id = "#{num}#{hiersep}#{c.increment(t).print}"
142
- @anchors[t["id"]] = anchor_struct(id, nil, label, klass, t["unnumbered"])
161
+ @anchors[t["id"]] =
162
+ anchor_struct(id, nil, label, klass, t["unnumbered"])
143
163
  hierarchical_permission_names2(t, id)
144
164
  end
145
165
  end
146
166
 
147
- def hierarchical_permission_names2(t, id)
148
- hierarchical_permission_names1(t, id, "permission", @labels["permission"])
149
- hierarchical_permission_names1(t, id, "requirement", @labels["requirement"])
150
- hierarchical_permission_names1(t, id, "recommendation", @labels["recommendation"])
167
+ def hierarchical_permission_names2(elem, ident)
168
+ hierarchical_permission_names1(elem, ident, "permission",
169
+ @labels["permission"])
170
+ hierarchical_permission_names1(elem, ident, "requirement",
171
+ @labels["requirement"])
172
+ hierarchical_permission_names1(elem, ident, "recommendation",
173
+ @labels["recommendation"])
151
174
  end
152
175
 
153
176
  def hierarchical_permission_names1(block, lbl, klass, label)
154
177
  c = Counter.new
155
178
  block.xpath(ns("./#{klass}")).each do |t|
156
179
  next if t["id"].nil? || t["id"].empty?
180
+
157
181
  id = "#{lbl}#{hierfigsep}#{c.increment(t).print}"
158
- @anchors[t["id"]] = anchor_struct(id, nil, label, klass, t["unnumbered"])
182
+ @anchors[t["id"]] =
183
+ anchor_struct(id, nil, label, klass, t["unnumbered"])
159
184
  hierarchical_permission_names2(t, id)
160
185
  end
161
186
  end
@@ -14,25 +14,24 @@ module IsoDoc::XrefGen
14
14
  end
15
15
  end
16
16
 
17
- def initial_anchor_names(d)
18
- d.xpath(ns("//preface/*")).each { |c| c.element? and preface_names(c) }
17
+ def initial_anchor_names(doc)
18
+ doc.xpath(ns("//preface/*")).each { |c| c.element? and preface_names(c) }
19
19
  # potentially overridden in middle_section_asset_names()
20
- sequential_asset_names(d.xpath(ns("//preface/*")))
20
+ sequential_asset_names(doc.xpath(ns("//preface/*")))
21
21
  n = Counter.new
22
- n = section_names(d.at(ns("//clause[@type = 'scope']")), n, 1)
23
- n = section_names(d.at(ns(@klass.norm_ref_xpath)), n, 1)
24
- n = section_names(d.at(ns("//sections/terms | "\
22
+ n = section_names(doc.at(ns("//clause[@type = 'scope']")), n, 1)
23
+ n = section_names(doc.at(ns(@klass.norm_ref_xpath)), n, 1)
24
+ n = section_names(doc.at(ns("//sections/terms | "\
25
25
  "//sections/clause[descendant::terms]")), n, 1)
26
- n = section_names(d.at(ns("//sections/definitions")), n, 1)
27
- clause_names(d, n)
28
- middle_section_asset_names(d)
29
- termnote_anchor_names(d)
30
- termexample_anchor_names(d)
26
+ n = section_names(doc.at(ns("//sections/definitions")), n, 1)
27
+ clause_names(doc, n)
28
+ middle_section_asset_names(doc)
29
+ termnote_anchor_names(doc)
30
+ termexample_anchor_names(doc)
31
31
  end
32
32
 
33
- def preface_clause_name(c)
34
- ret = c.at(ns("./title"))&.text || c.name.capitalize
35
- ret
33
+ def preface_clause_name(clause)
34
+ clause.at(ns("./title"))&.text || clause.name.capitalize
36
35
  end
37
36
 
38
37
  SUBCLAUSES =
@@ -41,12 +40,13 @@ module IsoDoc::XrefGen
41
40
  # in StanDoc, prefaces have no numbering; they are referenced only by title
42
41
  def preface_names(clause)
43
42
  return if clause.nil?
43
+
44
44
  @anchors[clause["id"]] =
45
45
  { label: nil, level: 1, xref: preface_clause_name(clause),
46
46
  type: "clause" }
47
47
  clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i|
48
48
  preface_names1(c, c.at(ns("./title"))&.text,
49
- "#{preface_clause_name(clause)}, #{i+1}", 2)
49
+ "#{preface_clause_name(clause)}, #{i + 1}", 2)
50
50
  end
51
51
  end
52
52
 
@@ -55,31 +55,32 @@ module IsoDoc::XrefGen
55
55
  @anchors[clause["id"]] =
56
56
  { label: nil, level: level, xref: label, type: "clause" }
57
57
  clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i|
58
- preface_names1(c, c.at(ns("./title"))&.text, "#{label} #{i+1}",
58
+ preface_names1(c, c.at(ns("./title"))&.text, "#{label} #{i + 1}",
59
59
  level + 1)
60
60
  end
61
61
  end
62
62
 
63
- def middle_section_asset_names(d)
63
+ def middle_section_asset_names(doc)
64
64
  middle_sections = "//clause[@type = 'scope'] | "\
65
65
  "#{@klass.norm_ref_xpath} | "\
66
66
  "//sections/terms | //preface/* | "\
67
67
  "//sections/definitions | //clause[parent::sections]"
68
- sequential_asset_names(d.xpath(ns(middle_sections)))
68
+ sequential_asset_names(doc.xpath(ns(middle_sections)))
69
69
  end
70
70
 
71
- def clause_names(docxml, n)
72
- docxml.xpath(ns(@klass.middle_clause(docxml))).each_with_index do |c, i|
73
- section_names(c, n, 1)
71
+ def clause_names(docxml, num)
72
+ docxml.xpath(ns(@klass.middle_clause(docxml))).each_with_index do |c, _i|
73
+ section_names(c, num, 1)
74
74
  end
75
75
  end
76
76
 
77
77
  def section_names(clause, num, lvl)
78
78
  return num if clause.nil?
79
+
79
80
  num.increment(clause)
80
81
  @anchors[clause["id"]] =
81
- { label: num.print, xref: l10n("#{@labels["clause"]} #{num.print}"), level: lvl,
82
- type: "clause" }
82
+ { label: num.print, xref: l10n("#{@labels['clause']} #{num.print}"),
83
+ level: lvl, type: "clause" }
83
84
  i = Counter.new
84
85
  clause.xpath(ns(SUBCLAUSES)).each do |c|
85
86
  i.increment(c)
@@ -90,7 +91,7 @@ module IsoDoc::XrefGen
90
91
 
91
92
  def section_names1(clause, num, level)
92
93
  @anchors[clause["id"]] =
93
- { label: num, level: level, xref: l10n("#{@labels["clause"]} #{num}"),
94
+ { label: num, level: level, xref: l10n("#{@labels['clause']} #{num}"),
94
95
  type: "clause" }
95
96
  i = Counter.new
96
97
  clause.xpath(ns(SUBCLAUSES)).each do |c|
@@ -100,26 +101,27 @@ module IsoDoc::XrefGen
100
101
  end
101
102
 
102
103
  def annex_name_lbl(clause, num)
103
- obl = l10n("(#{@labels["inform_annex"]})")
104
- obl = l10n("(#{@labels["norm_annex"]})") if clause["obligation"] == "normative"
105
- l10n("<strong>#{@labels["annex"]} #{num}</strong><br/>#{obl}")
104
+ obl = l10n("(#{@labels['inform_annex']})")
105
+ clause["obligation"] == "normative" and
106
+ obl = l10n("(#{@labels['norm_annex']})")
107
+ l10n("<strong>#{@labels['annex']} #{num}</strong><br/>#{obl}")
106
108
  end
107
109
 
108
110
  def single_annex_special_section(clause)
109
111
  a = clause.xpath(ns("./references | ./terms | ./definitions"))
110
112
  a.size == 1 or return nil
111
113
  clause.xpath(ns("./clause | ./p | ./table | ./ol | ./ul | ./dl | "\
112
- "./note | ./admonition | ./figure")).size == 0 or
113
- return nil
114
+ "./note | ./admonition | ./figure")).empty? or
115
+ return nil
114
116
  a[0]
115
117
  end
116
118
 
117
119
  def annex_names(clause, num)
118
120
  @anchors[clause["id"]] = { label: annex_name_lbl(clause, num),
119
121
  type: "clause", value: num.to_s,
120
- xref: "#{@labels["annex"]} #{num}", level: 1 }
122
+ xref: "#{@labels['annex']} #{num}", level: 1 }
121
123
  if a = single_annex_special_section(clause)
122
- annex_names1(a, "#{num}", 1)
124
+ annex_names1(a, num.to_s, 1)
123
125
  else
124
126
  i = Counter.new
125
127
  clause.xpath(ns(SUBCLAUSES)).each do |c|
@@ -131,10 +133,10 @@ module IsoDoc::XrefGen
131
133
  end
132
134
 
133
135
  def annex_names1(clause, num, level)
134
- @anchors[clause["id"]] = { label: num, xref: "#{@labels["annex"]} #{num}",
136
+ @anchors[clause["id"]] = { label: num, xref: "#{@labels['annex']} #{num}",
135
137
  level: level, type: "clause" }
136
138
  i = Counter.new
137
- clause.xpath(ns(SUBCLAUSES)).each_with_index do |c|
139
+ clause.xpath(ns(SUBCLAUSES)).each do |c|
138
140
  i.increment(c)
139
141
  annex_names1(c, "#{num}.#{i.print}", level + 1)
140
142
  end
@@ -147,10 +149,10 @@ module IsoDoc::XrefGen
147
149
  "xmlns:name = 'International Electrotechnical Commission']".freeze
148
150
 
149
151
  def reference_names(ref)
150
- isopub = ref.at(ns(ISO_PUBLISHER_XPATH))
152
+ # isopub = ref.at(ns(ISO_PUBLISHER_XPATH))
151
153
  ids = @klass.bibitem_ref_code(ref)
152
154
  identifiers = @klass.render_identifier(ids)
153
- date = ref.at(ns("./date[@type = 'published']"))
155
+ # date = ref.at(ns("./date[@type = 'published']"))
154
156
  reference = @klass.docid_l10n(identifiers[0] || identifiers[1])
155
157
  @anchors[ref["id"]] = { xref: reference }
156
158
  end