isodoc 2.1.4 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,103 @@
1
+ require_relative "../../relaton/render/general"
2
+
3
+ module IsoDoc
4
+ class PresentationXMLConvert < ::IsoDoc::Convert
5
+ def references(docxml)
6
+ bibliography_bibitem_number(docxml)
7
+ renderings = references_render(docxml)
8
+ docxml.xpath(ns("//references/bibitem")).each do |x|
9
+ bibitem(x, renderings)
10
+ end
11
+ docxml.xpath(ns("//references[bibitem/@hidden = 'true']")).each do |x|
12
+ x.at(ns("./bibitem[not(@hidden = 'true')]")) and next
13
+ x["hidden"] = "true"
14
+ end
15
+ @xrefs.parse_inclusions(refs: true).parse(docxml)
16
+ end
17
+
18
+ def references_render(docxml)
19
+ d = docxml.clone
20
+ d.remove_namespaces!
21
+ refs = d.xpath("//references/bibitem").each_with_object([]) do |b, m|
22
+ prep_for_rendering(b)
23
+ m << b.to_xml
24
+ end.join
25
+ bibrenderer.render_all("<references>#{refs}</references>",
26
+ type: citestyle)
27
+ end
28
+
29
+ def prep_for_rendering(bib)
30
+ bib["suppress_identifier"] == true and
31
+ bib.xpath(ns("./docidentifier")).each(&:remove)
32
+ bib["type"] ||= "standard"
33
+ end
34
+
35
+ def bibitem(xml, renderings)
36
+ @xrefs.klass.implicit_reference(xml) and xml["hidden"] = "true"
37
+ bibrender(xml, renderings)
38
+ end
39
+
40
+ def bibrender(xml, renderings)
41
+ if f = xml.at(ns("./formattedref"))
42
+ bibrender_formattedref(f, xml)
43
+ else bibrender_relaton(xml, renderings)
44
+ end
45
+ end
46
+
47
+ def bibrender_formattedref(formattedref, xml)
48
+ code = render_identifier(bibitem_ref_code(xml))
49
+ (code[:sdo] && xml["suppress_identifier"] != "true") and
50
+ formattedref << " [#{code[:sdo]}] "
51
+ end
52
+
53
+ def bibrender_relaton(xml, renderings)
54
+ f = renderings[xml["id"]][:formattedref]
55
+ f &&= "<formattedref>#{f}</formattedref>"
56
+ xml.children =
57
+ "#{f}#{xml.xpath(ns('./docidentifier | ./uri | ./note')).to_xml}"
58
+ end
59
+
60
+ def bibrenderer
61
+ ::Relaton::Render::IsoDoc::General.new(language: @lang)
62
+ end
63
+
64
+ def citestyle
65
+ nil
66
+ end
67
+
68
+ def bibliography_bibitem_number_skip(bibitem)
69
+ @xrefs.klass.implicit_reference(bibitem) ||
70
+ bibitem.at(ns(".//docidentifier[@type = 'metanorma']")) ||
71
+ bibitem.at(ns(".//docidentifier[@type = 'metanorma-ordinal']")) ||
72
+ bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
73
+ end
74
+
75
+ def bibliography_bibitem_number(docxml)
76
+ i = 0
77
+ docxml.xpath(ns("//references[@normative = 'false']/bibitem")).each do |b|
78
+ i = bibliography_bibitem_number1(b, i)
79
+ end
80
+ @xrefs.references docxml
81
+ end
82
+
83
+ def bibliography_bibitem_number1(bibitem, idx)
84
+ if mn = bibitem.at(ns(".//docidentifier[@type = 'metanorma']"))
85
+ /^\[?\d\]?$/.match?(mn&.text) and
86
+ idx = mn.text.sub(/^\[/, "").sub(/\]$/, "").to_i
87
+ end
88
+ unless bibliography_bibitem_number_skip(bibitem)
89
+
90
+ idx += 1
91
+ bibitem.at(ns(".//docidentifier")).previous =
92
+ "<docidentifier type='metanorma-ordinal'>[#{idx}]</docidentifier>"
93
+ end
94
+ idx
95
+ end
96
+
97
+ def docid_prefixes(docxml)
98
+ docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
99
+ i.children = @xrefs.klass.docid_prefix(i["type"], i.text)
100
+ end
101
+ end
102
+ end
103
+ end
@@ -1,4 +1,4 @@
1
- require_relative "../../relaton/render/general"
1
+ require_relative "refs"
2
2
 
3
3
  module IsoDoc
4
4
  class PresentationXMLConvert < ::IsoDoc::Convert
@@ -76,81 +76,6 @@ module IsoDoc
76
76
  prefix_name(elem, "", "#{lbl}#{clausedelim}", "name")
77
77
  end
78
78
 
79
- def references(docxml)
80
- bibliography_bibitem_number(docxml)
81
- docxml.xpath(ns("//references/bibitem")).each do |x|
82
- bibitem(x)
83
- end
84
- @xrefs.parse_inclusions(refs: true).parse(docxml)
85
- end
86
-
87
- def bibitem(xml)
88
- @xrefs.klass.implicit_reference(xml) and
89
- xml["hidden"] = "true"
90
- bibrender(xml)
91
- end
92
-
93
- def bibrender(xml)
94
- if f = xml.at(ns("./formattedref"))
95
- bibrender_formattedref(f, xml)
96
- else bibrender_relaton(xml)
97
- end
98
- end
99
-
100
- def bibrender_formattedref(formattedref, xml)
101
- code = render_identifier(bibitem_ref_code(xml))
102
- (code[:sdo] && xml["suppress_identifier"] != "true") and
103
- formattedref << " [#{code[:sdo]}] "
104
- end
105
-
106
- def bibrender_relaton(xml)
107
- bib = xml.dup
108
- bib["suppress_identifier"] == true and
109
- bib.xpath(ns("./docidentifier")).each(&:remove)
110
- xml.children =
111
- "#{bibrenderer.render(bib.to_xml)}"\
112
- "#{xml.xpath(ns('./docidentifier | ./uri | ./note')).to_xml}"
113
- end
114
-
115
- def bibrenderer
116
- ::Relaton::Render::IsoDoc::General.new(language: @lang)
117
- end
118
-
119
- def bibliography_bibitem_number_skip(bibitem)
120
- @xrefs.klass.implicit_reference(bibitem) ||
121
- bibitem.at(ns(".//docidentifier[@type = 'metanorma']")) ||
122
- bibitem.at(ns(".//docidentifier[@type = 'metanorma-ordinal']")) ||
123
- bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
124
- end
125
-
126
- def bibliography_bibitem_number(docxml)
127
- i = 0
128
- docxml.xpath(ns("//references[@normative = 'false']/bibitem")).each do |b|
129
- i = bibliography_bibitem_number1(b, i)
130
- end
131
- @xrefs.references docxml
132
- end
133
-
134
- def bibliography_bibitem_number1(bibitem, idx)
135
- if mn = bibitem.at(ns(".//docidentifier[@type = 'metanorma']"))
136
- /^\[?\d\]?$/.match?(mn&.text) and
137
- idx = mn.text.sub(/^\[/, "").sub(/\]$/, "").to_i
138
- end
139
- unless bibliography_bibitem_number_skip(bibitem)
140
-
141
- idx += 1
142
- bibitem.at(ns(".//docidentifier")).previous =
143
- "<docidentifier type='metanorma-ordinal'>[#{idx}]</docidentifier>"
144
- end
145
- idx
146
- end
147
-
148
- def docid_prefixes(docxml)
149
- docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
150
- i.children = @xrefs.klass.docid_prefix(i["type"], i.text)
151
- end
152
- end
153
-
154
79
  def index(docxml)
155
80
  docxml.xpath(ns("//index | //index-xref | //indexsect")).each(&:remove)
156
81
  end
@@ -28,10 +28,9 @@ module IsoDoc
28
28
  end
29
29
 
30
30
  def concept1_nonital(node, opts)
31
- if opts[:ital] == "false"
32
- r = node.at(ns(".//renderterm"))
33
- r&.replace(r&.children)
34
- end
31
+ opts[:ital] == "false" or return
32
+ r = node.at(ns(".//renderterm"))
33
+ r&.replace(r&.children)
35
34
  end
36
35
 
37
36
  def concept_render_init(node, defaults)
@@ -43,11 +42,11 @@ module IsoDoc
43
42
  end
44
43
 
45
44
  def concept1_linkmention(ref, renderterm, opts)
46
- if opts[:linkmention] == "true" && !renderterm.nil? && !ref.nil?
47
- ref2 = ref.clone
48
- r2 = renderterm.clone
49
- renderterm.replace(ref2).children = r2
50
- end
45
+ return unless opts[:linkmention] == "true" && !renderterm.nil? && !ref.nil?
46
+
47
+ ref2 = ref.clone
48
+ r2 = renderterm.clone
49
+ renderterm.replace(ref2).children = r2
51
50
  end
52
51
 
53
52
  def concept1_ref(_node, ref, opts)
@@ -82,14 +81,17 @@ module IsoDoc
82
81
  p = node.at(ns("./preferred"))
83
82
  ref = node.at(ns("./xref | ./eref | ./termref"))
84
83
  label = @i18n.relatedterms[node["type"]].upcase
85
- node.replace(l10n("<p><strong>#{label}:</strong> "\
86
- "<em>#{p.to_xml}</em> (#{ref.to_xml})</p>"))
84
+ if p && ref
85
+ node.replace(l10n("<p><strong>#{label}:</strong> "\
86
+ "<em>#{p.to_xml}</em> (#{ref.to_xml})</p>"))
87
+ else
88
+ node.replace(l10n("<p><strong>#{label}:</strong> "\
89
+ "<strong>**RELATED TERM NOT FOUND**</strong></p>"))
90
+ end
87
91
  end
88
92
 
89
93
  def designation(docxml)
90
- docxml.xpath(ns("//term")).each do |t|
91
- merge_second_preferred(t)
92
- end
94
+ docxml.xpath(ns("//term")).each { |t| merge_second_preferred(t) }
93
95
  docxml.xpath(ns("//preferred | //admitted | //deprecates")).each do |p|
94
96
  designation1(p)
95
97
  end
@@ -189,7 +191,6 @@ module IsoDoc
189
191
  end
190
192
  end
191
193
 
192
- # introduce name element
193
194
  def termnote1(elem)
194
195
  lbl = l10n(@xrefs.anchor(elem["id"], :label) || "???")
195
196
  prefix_name(elem, "", lower2cap(lbl), "name")
@@ -59,6 +59,7 @@ module IsoDoc
59
59
  permission docxml
60
60
  requirement docxml
61
61
  recommendation docxml
62
+ requirement_render docxml
62
63
  end
63
64
 
64
65
  def inline(docxml)
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.1.4".freeze
2
+ VERSION = "2.2.1".freeze
3
3
  end
@@ -98,7 +98,7 @@ module IsoDoc
98
98
  docxml.xpath("//p[@class='Biblio']//span[@style='mso-tab-count:1']")
99
99
  .each do |s|
100
100
  s.next.text? or next
101
- s.next.replace(s.next.text.sub(/^\s+/, ""))
101
+ s.next.replace(@c.encode(s.next.text.sub(/^\s+/, ""), :hexadecimal))
102
102
  end
103
103
  end
104
104
 
@@ -2,6 +2,18 @@ require "roman-numerals"
2
2
 
3
3
  module IsoDoc
4
4
  module XrefGen
5
+ class ReqCounter
6
+ # one counter for each requirements label
7
+ def initialize
8
+ @counters = {}
9
+ end
10
+
11
+ def increment(label, node)
12
+ @counters[label] ||= Counter.new
13
+ @counters[label].increment(node)
14
+ end
15
+ end
16
+
5
17
  class Counter
6
18
  def initialize(num = 0, opts = { numerals: :arabic })
7
19
  @unnumbered = false
@@ -1,5 +1,13 @@
1
1
  require_relative "xref_gen_seq"
2
2
 
3
+ module Enumerable
4
+ def noblank
5
+ reject do |n|
6
+ n["id"].nil? || n["id"].empty?
7
+ end
8
+ end
9
+ end
10
+
3
11
  module IsoDoc
4
12
  module XrefGen
5
13
  module Blocks
@@ -11,6 +19,10 @@ module IsoDoc
11
19
  text.nil? || text.empty?
12
20
  end
13
21
 
22
+ def noblank(xpath)
23
+ xpath.reject { |n| blank?(n["id"]) }
24
+ end
25
+
14
26
  def amend_preprocess(xmldoc)
15
27
  xmldoc.xpath(ns("//amend[newcontent]")).each do |a|
16
28
  autonum = amend_autonums(a)
@@ -45,7 +57,7 @@ module IsoDoc
45
57
  def termnote_anchor_names(docxml)
46
58
  docxml.xpath(ns("//*[termnote]")).each do |t|
47
59
  c = Counter.new
48
- t.xpath(ns("./termnote")).reject { |n| blank?(n["id"]) }.each do |n|
60
+ t.xpath(ns("./termnote")).noblank.each do |n|
49
61
  c.increment(n)
50
62
  @anchors[n["id"]] =
51
63
  { label: termnote_label(c.print), type: "termnote",
@@ -60,7 +72,7 @@ module IsoDoc
60
72
  docxml.xpath(ns("//*[termexample]")).each do |t|
61
73
  examples = t.xpath(ns("./termexample"))
62
74
  c = Counter.new
63
- examples.reject { |n| blank?(n["id"]) }.each do |n|
75
+ examples.noblank.each do |n|
64
76
  c.increment(n)
65
77
  idx = increment_label(examples, n, c, increment: false)
66
78
  @anchors[n["id"]] = anchor_struct(idx, n, @labels["example_xref"],
@@ -135,7 +147,7 @@ module IsoDoc
135
147
  notes = s.xpath(ns(".//ol")) - s.xpath(ns(".//clause//ol")) -
136
148
  s.xpath(ns(".//appendix//ol")) - s.xpath(ns(".//ol//ol"))
137
149
  c = Counter.new
138
- notes.reject { |n| blank?(n["id"]) }.each do |n|
150
+ notes.noblank.each do |n|
139
151
  @anchors[n["id"]] = anchor_struct(increment_label(notes, n, c), n,
140
152
  @labels["list"], "list", false)
141
153
  list_item_anchor_names(n, @anchors[n["id"]], 1, "", notes.size != 1)
@@ -169,7 +181,7 @@ module IsoDoc
169
181
  end
170
182
 
171
183
  def deflist_anchor_names1(notes, counter)
172
- notes.reject { |n| blank?(n["id"]) }.each do |n|
184
+ notes.noblank.each do |n|
173
185
  @anchors[n["id"]] =
174
186
  anchor_struct(increment_label(notes, n, counter), n,
175
187
  @labels["deflist"], "deflist", false)
@@ -197,7 +209,7 @@ module IsoDoc
197
209
  end
198
210
 
199
211
  def bookmark_anchor_names(xml)
200
- xml.xpath(ns(".//bookmark")).reject { |n| blank?(n["id"]) }.each do |n|
212
+ xml.xpath(ns(".//bookmark")).noblank.each do |n|
201
213
  parent = nil
202
214
  n.ancestors.each do |a|
203
215
  next unless a["id"] && parent = @anchors.dig(a["id"], :xref)
@@ -24,22 +24,24 @@ module IsoDoc
24
24
  c = Counter.new
25
25
  j = 0
26
26
  clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]"))
27
- .each do |t|
28
- next if blank?(t["id"])
29
-
27
+ .noblank.each do |t|
30
28
  j = subfigure_increment(j, c, t)
31
- label = c.print
32
- label &&= label + (j.zero? ? "" : "-#{j}")
33
-
34
- @anchors[t["id"]] = anchor_struct(
35
- label, nil, @labels["figure"], "figure", t["unnumbered"]
36
- )
29
+ sequential_figure_body(j, c, t)
37
30
  end
38
31
  end
39
32
 
33
+ def sequential_figure_body(subfignum, counter, block)
34
+ label = counter.print
35
+ label &&= label + (subfignum.zero? ? "" : "-#{subfignum}")
36
+
37
+ @anchors[block["id"]] = anchor_struct(
38
+ label, nil, @labels["figure"], "figure", block["unnumbered"]
39
+ )
40
+ end
41
+
40
42
  def sequential_table_names(clause)
41
43
  c = Counter.new
42
- clause.xpath(ns(".//table")).reject { |n| blank?(n["id"]) }.each do |t|
44
+ clause.xpath(ns(".//table")).noblank.each do |t|
43
45
  next if labelled_ancestor(t)
44
46
 
45
47
  @anchors[t["id"]] = anchor_struct(
@@ -51,9 +53,7 @@ module IsoDoc
51
53
 
52
54
  def sequential_formula_names(clause)
53
55
  c = Counter.new
54
- clause.xpath(ns(".//formula")).reject do |n|
55
- blank?(n["id"])
56
- end.each do |t|
56
+ clause.xpath(ns(".//formula")).noblank.each do |t|
57
57
  @anchors[t["id"]] = anchor_struct(
58
58
  c.increment(t).print, t,
59
59
  t["inequality"] ? @labels["inequality"] : @labels["formula"],
@@ -62,70 +62,98 @@ module IsoDoc
62
62
  end
63
63
  end
64
64
 
65
- FIRST_LVL_REQ = "[not(ancestor::permission or ancestor::requirement or "\
66
- "ancestor::recommendation)]".freeze
65
+ FIRST_LVL_REQ_RULE = <<~XPATH.freeze
66
+ [not(ancestor::permission or ancestor::requirement or ancestor::recommendation)]
67
+ XPATH
67
68
 
68
- def sequential_permission_names(clause, klass, label)
69
- c = Counter.new
70
- clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}"))
71
- .reject { |n| blank?(n["id"]) }.each do |t|
72
- id = c.increment(t).print
73
- @anchors[t["id"]] =
74
- anchor_struct(id, t, label, klass, t["unnumbered"])
75
- sequential_permission_names2(t, id)
69
+ FIRST_LVL_REQ = <<~XPATH.freeze
70
+ .//permission#{FIRST_LVL_REQ_RULE} | .//requirement#{FIRST_LVL_REQ_RULE} | .//recommendation#{FIRST_LVL_REQ_RULE}
71
+ XPATH
72
+
73
+ REQ_CHILDREN = <<~XPATH.freeze
74
+ ./permission | ./requirement | ./recommendation
75
+ XPATH
76
+
77
+ def sequential_permission_names(clause)
78
+ c = ReqCounter.new
79
+ clause.xpath(ns(FIRST_LVL_REQ)).noblank.each do |t|
80
+ m = @reqt_models.model(t["model"])
81
+ klass, label = reqt2class_label(t, m)
82
+ id = c.increment(label, t).print
83
+ sequential_permission_body(id, t, label, klass, m)
84
+ sequential_permission_children(t, id)
76
85
  end
77
86
  end
78
87
 
79
- def sequential_permission_names2(elem, ident)
80
- sequential_permission_names1(elem, ident, "permission",
81
- @labels["permission"])
82
- sequential_permission_names1(elem, ident, "requirement",
83
- @labels["requirement"])
84
- sequential_permission_names1(elem, ident, "recommendation",
85
- @labels["recommendation"])
88
+ def sequential_permission_children(block, lbl)
89
+ c = ReqCounter.new
90
+ block.xpath(ns(REQ_CHILDREN)).noblank.each do |t|
91
+ m = @reqt_models.model(t["model"])
92
+ klass, label = reqt2class_nested_label(t, m)
93
+ id = "#{lbl}#{hierfigsep}#{c.increment(label, t).print}"
94
+ sequential_permission_body(id, t, label, klass, m)
95
+ sequential_permission_children(t, id)
96
+ end
86
97
  end
87
98
 
88
- def sequential_permission_names1(block, lbl, klass, label)
89
- c = Counter.new
90
- block.xpath(ns("./#{klass}")).reject { |n| blank?(n["id"]) }.each do |t|
91
- id = "#{lbl}#{hierfigsep}#{c.increment(t).print}"
92
- @anchors[t["id"]] =
93
- anchor_struct(id, t, label, klass, t["unnumbered"])
94
- sequential_permission_names2(t, id)
99
+ def sequential_permission_body(id, block, label, klass, model)
100
+ @anchors[block["id"]] = model.postprocess_anchor_struct(
101
+ block, anchor_struct(id, block,
102
+ label, klass, block["unnumbered"])
103
+ )
104
+
105
+ model.permission_parts(block, id, label, klass).each do |n|
106
+ @anchors[n[:id]] = anchor_struct(n[:number], n[:elem], n[:label],
107
+ n[:klass], false)
95
108
  end
96
109
  end
97
110
 
111
+ def reqt2class_label(block, model)
112
+ model.req_class_paths.each do |n|
113
+ v1 = ns("/#{n[:xpath]}").sub(%r{^/}, "")
114
+ block.at("./self::#{v1}") and return [n[:klass], @labels[n[:label]]]
115
+ end
116
+ [nil, nil]
117
+ end
118
+
119
+ def reqt2class_nested_label(block, model)
120
+ model.req_nested_class_paths.each do |n|
121
+ v1 = ns("/#{n[:xpath]}").sub(%r{^/}, "")
122
+ block.at("./self::#{v1}") and return [n[:klass], @labels[n[:label]]]
123
+ end
124
+ [nil, nil]
125
+ end
126
+
98
127
  def sequential_asset_names(clause)
99
128
  sequential_table_names(clause)
100
129
  sequential_figure_names(clause)
101
130
  sequential_formula_names(clause)
102
- sequential_permission_names(clause, "permission", @labels["permission"])
103
- sequential_permission_names(clause, "requirement",
104
- @labels["requirement"])
105
- sequential_permission_names(clause, "recommendation",
106
- @labels["recommendation"])
131
+ sequential_permission_names(clause)
107
132
  end
108
133
 
109
134
  def hierarchical_figure_names(clause, num)
110
135
  c = Counter.new
111
136
  j = 0
112
137
  clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]"))
113
- .each do |t|
138
+ .noblank.each do |t|
114
139
  # next if labelled_ancestor(t) && t.ancestors("figure").empty?
115
140
 
116
141
  j = subfigure_increment(j, c, t)
117
- label = "#{num}#{hiersep}#{c.print}" +
118
- (j.zero? ? "" : "#{hierfigsep}#{j}")
119
- next if t["id"].nil? || t["id"].empty?
120
-
121
- @anchors[t["id"]] = anchor_struct(label, nil, @labels["figure"],
122
- "figure", t["unnumbered"])
142
+ hierarchical_figure_body(num, j, c, t)
123
143
  end
124
144
  end
125
145
 
146
+ def hierarchical_figure_body(num, subfignum, counter, block)
147
+ label = "#{num}#{hiersep}#{counter.print}" +
148
+ (subfignum.zero? ? "" : "#{hierfigsep}#{subfignum}")
149
+
150
+ @anchors[block["id"]] = anchor_struct(label, nil, @labels["figure"],
151
+ "figure", block["unnumbered"])
152
+ end
153
+
126
154
  def hierarchical_table_names(clause, num)
127
155
  c = Counter.new
128
- clause.xpath(ns(".//table")).reject { |n| blank?(n["id"]) }.each do |t|
156
+ clause.xpath(ns(".//table")).noblank.each do |t|
129
157
  next if labelled_ancestor(t)
130
158
 
131
159
  @anchors[t["id"]] =
@@ -138,19 +166,12 @@ module IsoDoc
138
166
  hierarchical_table_names(clause, num)
139
167
  hierarchical_figure_names(clause, num)
140
168
  hierarchical_formula_names(clause, num)
141
- hierarchical_permission_names(clause, num, "permission",
142
- @labels["permission"])
143
- hierarchical_permission_names(clause, num, "requirement",
144
- @labels["requirement"])
145
- hierarchical_permission_names(clause, num, "recommendation",
146
- @labels["recommendation"])
169
+ hierarchical_permission_names(clause, num)
147
170
  end
148
171
 
149
172
  def hierarchical_formula_names(clause, num)
150
173
  c = Counter.new
151
- clause.xpath(ns(".//formula")).reject do |n|
152
- blank?(n["id"])
153
- end.each do |t|
174
+ clause.xpath(ns(".//formula")).noblank.each do |t|
154
175
  @anchors[t["id"]] = anchor_struct(
155
176
  "#{num}#{hiersep}#{c.increment(t).print}", nil,
156
177
  t["inequality"] ? @labels["inequality"] : @labels["formula"],
@@ -159,33 +180,37 @@ module IsoDoc
159
180
  end
160
181
  end
161
182
 
162
- def hierarchical_permission_names(clause, num, klass, label)
163
- c = Counter.new
164
- clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}"))
165
- .reject { |n| blank?(n["id"]) }.each do |t|
166
- id = "#{num}#{hiersep}#{c.increment(t).print}"
167
- @anchors[t["id"]] =
168
- anchor_struct(id, nil, label, klass, t["unnumbered"])
169
- hierarchical_permission_names2(t, id)
183
+ def hierarchical_permission_names(clause, num)
184
+ c = ReqCounter.new
185
+ clause.xpath(ns(FIRST_LVL_REQ)).noblank.each do |t|
186
+ m = @reqt_models.model(t["model"])
187
+ klass, label = reqt2class_label(t, m)
188
+ id = "#{num}#{hiersep}#{c.increment(label, t).print}"
189
+ hierarchical_permission_body(id, t, label, klass, m)
190
+ hierarchical_permission_children(t, id)
170
191
  end
171
192
  end
172
193
 
173
- def hierarchical_permission_names2(elem, ident)
174
- hierarchical_permission_names1(elem, ident, "permission",
175
- @labels["permission"])
176
- hierarchical_permission_names1(elem, ident, "requirement",
177
- @labels["requirement"])
178
- hierarchical_permission_names1(elem, ident, "recommendation",
179
- @labels["recommendation"])
194
+ def hierarchical_permission_children(block, lbl)
195
+ c = ReqCounter.new
196
+ block.xpath(ns(REQ_CHILDREN)).noblank.each do |t|
197
+ m = @reqt_models.model(t["model"])
198
+ klass, label = reqt2class_nested_label(t, m)
199
+ id = "#{lbl}#{hierfigsep}#{c.increment(label, t).print}"
200
+ hierarchical_permission_body(id, t, label, klass, m)
201
+ hierarchical_permission_children(t, id)
202
+ end
180
203
  end
181
204
 
182
- def hierarchical_permission_names1(block, lbl, klass, label)
183
- c = Counter.new
184
- block.xpath(ns("./#{klass}")).reject { |n| blank?(n["id"]) }.each do |t|
185
- id = "#{lbl}#{hierfigsep}#{c.increment(t).print}"
186
- @anchors[t["id"]] =
187
- anchor_struct(id, nil, label, klass, t["unnumbered"])
188
- hierarchical_permission_names2(t, id)
205
+ def hierarchical_permission_body(id, block, label, klass, model)
206
+ @anchors[block["id"]] = model.postprocess_anchor_struct(
207
+ block, anchor_struct(id, nil,
208
+ label, klass, block["unnumbered"])
209
+ )
210
+
211
+ model.permission_parts(block, id, label, klass).each do |n|
212
+ @anchors[n[:id]] = anchor_struct(n[:number], nil, n[:label],
213
+ n[:klass], false)
189
214
  end
190
215
  end
191
216
  end
data/lib/isodoc/xref.rb CHANGED
@@ -24,6 +24,12 @@ module IsoDoc
24
24
  @i18n = i18n
25
25
  @labels = @i18n.get
26
26
  @klass.i18n = @i18n
27
+ @reqt_models = Metanorma::Requirements
28
+ .new({
29
+ default: "default", lang: lang, script: script,
30
+ labels: @i18n.get
31
+ })
32
+ @i18n
27
33
  @parse_settings = {}
28
34
  end
29
35
 
@@ -54,6 +54,14 @@ table: جدول
54
54
  requirement: مطلب
55
55
  recommendation: توصية
56
56
  permission: إذن
57
+ recommendationtest: اختبار التوصية
58
+ requirementtest: اختبار المتطلبات
59
+ permissiontest: اختبار الإذن
60
+ recommendationclass: فئة التوصيات
61
+ requirementclass: فئة المتطلبات
62
+ permissionclass: فئة الأذونات
63
+ abstracttest: اختبار تجريدي
64
+ conformanceclass: فئة المطابقة
57
65
  key: مفتاح
58
66
  example: مثال
59
67
  example_xref: مثال