isodoc 2.2.0 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/isodoc.gemspec +5 -5
  3. data/lib/isodoc/class_utils.rb +1 -4
  4. data/lib/isodoc/convert.rb +56 -42
  5. data/lib/isodoc/function/references.rb +1 -1
  6. data/lib/isodoc/function/reqt.rb +17 -88
  7. data/lib/isodoc/function/table.rb +1 -1
  8. data/lib/isodoc/function/to_word_html.rb +6 -5
  9. data/lib/isodoc/function/utils.rb +4 -0
  10. data/lib/isodoc/i18n.rb +3 -18
  11. data/lib/isodoc/init.rb +20 -0
  12. data/lib/isodoc/pdf_convert.rb +0 -1
  13. data/lib/isodoc/presentation_function/block.rb +23 -6
  14. data/lib/isodoc/presentation_function/image.rb +68 -19
  15. data/lib/isodoc/presentation_function/refs.rb +102 -0
  16. data/lib/isodoc/presentation_function/section.rb +1 -80
  17. data/lib/isodoc/presentation_function/terms.rb +9 -13
  18. data/lib/isodoc/presentation_xml_convert.rb +1 -0
  19. data/lib/isodoc/version.rb +1 -1
  20. data/lib/isodoc/xref/xref_counter.rb +12 -0
  21. data/lib/isodoc/xref/xref_gen.rb +17 -5
  22. data/lib/isodoc/xref/xref_gen_seq.rb +106 -81
  23. data/lib/isodoc/xref.rb +6 -0
  24. data/lib/isodoc/xslfo_convert.rb +0 -2
  25. data/lib/isodoc-yaml/i18n-ar.yaml +0 -2
  26. data/lib/isodoc-yaml/i18n-de.yaml +0 -2
  27. data/lib/isodoc-yaml/i18n-en.yaml +9 -2
  28. data/lib/isodoc-yaml/i18n-es.yaml +0 -2
  29. data/lib/isodoc-yaml/i18n-fr.yaml +0 -2
  30. data/lib/isodoc-yaml/i18n-ru.yaml +0 -2
  31. data/lib/isodoc-yaml/i18n-zh-Hans.yaml +0 -2
  32. data/lib/relaton/render/general.rb +5 -19
  33. metadata +42 -34
  34. data/lib/isodoc/base_style/all.css +0 -227
  35. data/lib/isodoc/base_style/blocks.css +0 -0
  36. data/lib/isodoc/base_style/coverpage.css +0 -0
  37. data/lib/isodoc/base_style/defaults.css +0 -0
  38. data/lib/isodoc/base_style/metanorma_word.css +0 -47
  39. data/lib/isodoc/base_style/nav.css +0 -0
  40. data/lib/isodoc/base_style/reset.css +0 -125
  41. data/lib/isodoc/base_style/typography.css +0 -0
@@ -0,0 +1,102 @@
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
+ ins = bibitem.at(ns(".//docidentifier")).previous_element
85
+ mn = bibitem.at(ns(".//docidentifier[@type = 'metanorma']")) and
86
+ /^\[?\d+\]?$/.match?(mn.text) and
87
+ mn.remove # ignore numbers already inserted
88
+ unless bibliography_bibitem_number_skip(bibitem)
89
+ idx += 1
90
+ ins.next =
91
+ "<docidentifier type='metanorma-ordinal'>[#{idx}]</docidentifier>"
92
+ end
93
+ idx
94
+ end
95
+
96
+ def docid_prefixes(docxml)
97
+ docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
98
+ i.children = @xrefs.klass.docid_prefix(i["type"], i.text)
99
+ end
100
+ end
101
+ end
102
+ 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,85 +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
- docxml.xpath(ns("//references[bibitem/@hidden = 'true']")).each do |x|
85
- x.at(ns("./bibitem[not(@hidden = 'true')]")) and next
86
- x["hidden"] = "true"
87
- end
88
- @xrefs.parse_inclusions(refs: true).parse(docxml)
89
- end
90
-
91
- def bibitem(xml)
92
- @xrefs.klass.implicit_reference(xml) and
93
- xml["hidden"] = "true"
94
- bibrender(xml)
95
- end
96
-
97
- def bibrender(xml)
98
- if f = xml.at(ns("./formattedref"))
99
- bibrender_formattedref(f, xml)
100
- else bibrender_relaton(xml)
101
- end
102
- end
103
-
104
- def bibrender_formattedref(formattedref, xml)
105
- code = render_identifier(bibitem_ref_code(xml))
106
- (code[:sdo] && xml["suppress_identifier"] != "true") and
107
- formattedref << " [#{code[:sdo]}] "
108
- end
109
-
110
- def bibrender_relaton(xml)
111
- bib = xml.dup
112
- bib["suppress_identifier"] == true and
113
- bib.xpath(ns("./docidentifier")).each(&:remove)
114
- xml.children =
115
- "#{bibrenderer.render(bib.to_xml)}"\
116
- "#{xml.xpath(ns('./docidentifier | ./uri | ./note')).to_xml}"
117
- end
118
-
119
- def bibrenderer
120
- ::Relaton::Render::IsoDoc::General.new(language: @lang)
121
- end
122
-
123
- def bibliography_bibitem_number_skip(bibitem)
124
- @xrefs.klass.implicit_reference(bibitem) ||
125
- bibitem.at(ns(".//docidentifier[@type = 'metanorma']")) ||
126
- bibitem.at(ns(".//docidentifier[@type = 'metanorma-ordinal']")) ||
127
- bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
128
- end
129
-
130
- def bibliography_bibitem_number(docxml)
131
- i = 0
132
- docxml.xpath(ns("//references[@normative = 'false']/bibitem")).each do |b|
133
- i = bibliography_bibitem_number1(b, i)
134
- end
135
- @xrefs.references docxml
136
- end
137
-
138
- def bibliography_bibitem_number1(bibitem, idx)
139
- if mn = bibitem.at(ns(".//docidentifier[@type = 'metanorma']"))
140
- /^\[?\d\]?$/.match?(mn&.text) and
141
- idx = mn.text.sub(/^\[/, "").sub(/\]$/, "").to_i
142
- end
143
- unless bibliography_bibitem_number_skip(bibitem)
144
-
145
- idx += 1
146
- bibitem.at(ns(".//docidentifier")).previous =
147
- "<docidentifier type='metanorma-ordinal'>[#{idx}]</docidentifier>"
148
- end
149
- idx
150
- end
151
-
152
- def docid_prefixes(docxml)
153
- docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
154
- i.children = @xrefs.klass.docid_prefix(i["type"], i.text)
155
- end
156
- end
157
-
158
79
  def index(docxml)
159
80
  docxml.xpath(ns("//index | //index-xref | //indexsect")).each(&:remove)
160
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)
@@ -92,9 +91,7 @@ module IsoDoc
92
91
  end
93
92
 
94
93
  def designation(docxml)
95
- docxml.xpath(ns("//term")).each do |t|
96
- merge_second_preferred(t)
97
- end
94
+ docxml.xpath(ns("//term")).each { |t| merge_second_preferred(t) }
98
95
  docxml.xpath(ns("//preferred | //admitted | //deprecates")).each do |p|
99
96
  designation1(p)
100
97
  end
@@ -194,7 +191,6 @@ module IsoDoc
194
191
  end
195
192
  end
196
193
 
197
- # introduce name element
198
194
  def termnote1(elem)
199
195
  lbl = l10n(@xrefs.anchor(elem["id"], :label) || "???")
200
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.2.0".freeze
2
+ VERSION = "2.2.3".freeze
3
3
  end
@@ -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], 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], 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 = @klass.requirements_processor
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
 
@@ -1,5 +1,3 @@
1
- require "metanorma"
2
-
3
1
  module IsoDoc
4
2
  class XslfoPdfConvert < ::IsoDoc::Convert
5
3
  MN_OPTIONS_KEY = :mn2pdf
@@ -86,8 +86,6 @@ month_october: أكتوبر
86
86
  month_november: نوفمبر
87
87
  month_december: ديسمبر
88
88
  obligation: التزام
89
- subject: موضوع
90
- inherits: يرث
91
89
  admonition:
92
90
  danger: خطر
93
91
  warning: تحذير
@@ -92,8 +92,6 @@ month_october: Oktober
92
92
  month_november: November
93
93
  month_december: Dezember
94
94
  obligation: Verbindlichkeit
95
- subject: Thema
96
- inherits: Erbt
97
95
  admonition: {
98
96
  danger: Gefahr,
99
97
  warning: Warnung,