Module: IsoDoc::XrefGen::Blocks

Included in:
IsoDoc::Xref
Defined in:
lib/isodoc/xref/xref_gen.rb,
lib/isodoc/xref/xref_gen_seq.rb

Constant Summary collapse

NUMBERED_BLOCKS =
%w(termnote termexample note example requirement
recommendation permission figure table formula
admonition sourcecode).freeze
FIGURE_NO_CLASS =
<<~XPATH.freeze
  .//figure[not(@class)] | .//figure[@class = 'pseudocode'] | .//sourcecode[not(ancestor::example)]
XPATH
FIRST_LVL_REQ_RULE =
<<~XPATH.freeze
  [not(ancestor::permission or ancestor::requirement or ancestor::recommendation)]
XPATH
FIRST_LVL_REQ =
<<~XPATH.freeze
  .//permission#{FIRST_LVL_REQ_RULE} | .//requirement#{FIRST_LVL_REQ_RULE} | .//recommendation#{FIRST_LVL_REQ_RULE}
XPATH
REQ_CHILDREN =
<<~XPATH.freeze
  ./permission | ./requirement | ./recommendation
XPATH

Instance Method Summary collapse

Instance Method Details

#admonition_anchor_names(sections) ⇒ Object



93
94
95
96
97
98
99
100
# File 'lib/isodoc/xref/xref_gen.rb', line 93

def admonition_anchor_names(sections)
  sections.each do |s|
    s.at(ns(".//admonition[@type = 'box']")) or next
    notes = s.xpath(child_asset_path("admonition[@type = 'box']"))
    admonition_anchor_names1(notes, Counter.new)
    admonition_anchor_names(s.xpath(ns(child_sections)))
  end
end

#admonition_anchor_names1(notes, counter) ⇒ Object



102
103
104
105
106
107
108
109
# File 'lib/isodoc/xref/xref_gen.rb', line 102

def admonition_anchor_names1(notes, counter)
  notes.noblank.each do |n|
    @anchors[n["id"]] ||=
      anchor_struct(increment_label(notes, n, counter), n,
                    @labels["box"], "admonition",
                    { container: true, unnumb: n["unnumbered"] })
  end
end

#amend_autonums(amend) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/isodoc/xref/xref_gen.rb', line 23

def amend_autonums(amend)
  autonum = {}
  amend.xpath(ns("./autonumber")).each do |n|
    autonum[n["type"]] = n.text
  end
  autonum
end

#amend_preprocess(xmldoc) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/isodoc/xref/xref_gen.rb', line 11

def amend_preprocess(xmldoc)
  xmldoc.xpath(ns("//amend[newcontent]")).each do |a|
    autonum = amend_autonums(a)
    NUMBERED_BLOCKS.each do |b|
      a.xpath(ns("./newcontent//#{b}")).each_with_index do |e, i|
        autonum[b] && i.zero? and e["number"] = autonum[b]
        !autonum[b] and e["unnumbered"] = "true"
      end
    end
  end
end

#bookmark_anchor_names(xml) ⇒ Object



251
252
253
254
255
256
257
258
259
# File 'lib/isodoc/xref/xref_gen.rb', line 251

def bookmark_anchor_names(xml)
  xml.xpath(ns(".//bookmark")).noblank.each do |n|
    _parent, id = id_ancestor(n)
    # container = bookmark_container(parent)
    @anchors[n["id"]] = { type: "bookmark", label: nil, value: nil,
                          xref: @anchors.dig(id, :xref) || "???",
                          container: @anchors.dig(id, :container) }
  end
end

#bookmark_container(parent) ⇒ Object



240
241
242
243
244
245
246
247
248
249
# File 'lib/isodoc/xref/xref_gen.rb', line 240

def bookmark_container(parent)
  if parent
    clause = parent.xpath(CLAUSE_ANCESTOR)&.last
    if clause["id"] == id
      nil
    else
      @anchors.dig(clause["id"], :xref)
    end
  end
end

#deflist_anchor_names(sections) ⇒ Object



188
189
190
191
192
193
194
195
# File 'lib/isodoc/xref/xref_gen.rb', line 188

def deflist_anchor_names(sections)
  sections.each do |s|
    notes = s.xpath(ns(".//dl")) - s.xpath(ns(".//clause//dl")) -
      s.xpath(ns(".//appendix//dl")) - s.xpath(ns(".//dl//dl"))
    deflist_anchor_names1(notes, Counter.new)
    deflist_anchor_names(s.xpath(ns(child_sections)))
  end
end

#deflist_anchor_names1(notes, counter) ⇒ Object



197
198
199
200
201
202
203
204
205
# File 'lib/isodoc/xref/xref_gen.rb', line 197

def deflist_anchor_names1(notes, counter)
  notes.noblank.each do |n|
    @anchors[n["id"]] =
      anchor_struct(increment_label(notes, n, counter), n,
                    @labels["deflist"], "deflist",
                    { unnumb: false, container: true })
    deflist_term_anchor_names(n, @anchors[n["id"]])
  end
end

#deflist_term_anchor_lbl(listitem, list_anchor) ⇒ Object



219
220
221
222
# File 'lib/isodoc/xref/xref_gen.rb', line 219

def deflist_term_anchor_lbl(listitem, list_anchor)
  s = semx(listitem, dt2xreflabel(listitem))
  %(#{list_anchor[:xref]}#{delim_wrap(":")} #{s}</semx>)
end

#deflist_term_anchor_names(list, list_anchor) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
# File 'lib/isodoc/xref/xref_gen.rb', line 207

def deflist_term_anchor_names(list, list_anchor)
  list.xpath(ns("./dt")).each do |li|
    label = deflist_term_anchor_lbl(li, list_anchor)
    li["id"] and @anchors[li["id"]] =
                   { xref: label, type: "deflistitem",
                     container: list_anchor[:container] }
    li.xpath(ns("./dl")).each do |dl|
      deflist_term_anchor_names(dl, list_anchor)
    end
  end
end

#dt2xreflabel(dterm) ⇒ Object



224
225
226
227
228
229
# File 'lib/isodoc/xref/xref_gen.rb', line 224

def dt2xreflabel(dterm)
  label = dterm.dup
  label.xpath(ns(".//p")).each { |x| x.replace(x.children) }
  label.xpath(ns(".//index")).each(&:remove)
  Common::to_xml(label.children)
end

#example_anchor_names(sections) ⇒ Object



111
112
113
114
115
116
117
# File 'lib/isodoc/xref/xref_gen.rb', line 111

def example_anchor_names(sections)
  sections.each do |s|
    notes = s.xpath(child_asset_path("example"))
    example_anchor_names1(notes, Counter.new)
    example_anchor_names(s.xpath(ns(child_sections)))
  end
end

#example_anchor_names1(notes, counter) ⇒ Object



119
120
121
122
123
124
125
126
# File 'lib/isodoc/xref/xref_gen.rb', line 119

def example_anchor_names1(notes, counter)
  notes.noblank.each do |n|
    @anchors[n["id"]] ||=
      anchor_struct(increment_label(notes, n, counter), n,
                    @labels["example_xref"], "example",
                    { unnumb: n["unnumbered"], container: true })
  end
end

#fig_subfig_label(label, sublabel) ⇒ Object



96
97
98
99
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 96

def fig_subfig_label(label, sublabel)
  label && sublabel or return
  "#{label}#{subfigure_separator}#{sublabel}"
end

#figure_anchor(elem, sublabel, label, klass, container: false) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 84

def figure_anchor(elem, sublabel, label, klass, container: false)
  if sublabel
    /<semx/.match?(label) or label = semx(elem.parent, label)
    subfigure_anchor(elem, sublabel, label, klass, container: false)
  else
    @anchors[elem["id"]] = anchor_struct(
      label, elem, @labels[klass] || klass.capitalize, klass,
      { unnumb: elem["unnumbered"], container: }
    )
  end
end

#hier_separator(markup: false) ⇒ Object



57
58
59
60
61
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 57

def hier_separator(markup: false)
  h = hiersep
  h.blank? || !markup or h = delim_wrap(h)
  h
end

#hierarchical_asset_names(clause, num) ⇒ Object



278
279
280
281
282
283
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 278

def hierarchical_asset_names(clause, num)
  hierarchical_table_names(clause, num)
  hierarchical_figure_names(clause, num)
  hierarchical_formula_names(clause, num)
  hierarchical_permission_names(clause, num)
end

#hierarchical_figure_class_names(clauses, num) ⇒ Object



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 248

def hierarchical_figure_class_names(clauses, num)
  c = {}
  j = 0
  nodeSet(clauses).each do |clause|
  clause.xpath(ns(".//figure[@class][not(@class = 'pseudocode')]"))
    .noblank.each do |t|
    # labelled_ancestor(t, %w(figure)) and next
    c[t["class"]] ||= Counter.new
    j = subfigure_increment(j, c[t["class"]], t)
    sublabel = subfigure_label(j)
    # hierarchical_figure_body(num, j, c[t["class"]], t, t["class"])
    #figure_anchor(t, sublabel, "#{num}#{hier_separator}#{c[t['class']].print}", t["class"])
    figure_anchor(t, sublabel, hiersemx(clause, num, c[t["class"]], t), t["class"])
  end
  end
end

#hierarchical_figure_names(clauses, num) ⇒ Object

these can take a NodeSet as argument; semx will point to members of the NodeSet, but numbering will be consecutive



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 231

def hierarchical_figure_names(clauses, num)
  c = Counter.new
  j = 0
  nodeSet(clauses).each do |clause|
  clause.xpath(ns(self.class::FIGURE_NO_CLASS)).noblank.each do |t|
    # labelled_ancestor(t, %w(figure)) and next
    j = subfigure_increment(j, c, t)
    sublabel = subfigure_label(j)
    # hierarchical_figure_body(num, j, c, t, "figure")
    #figure_anchor(t, sublabel, "#{num}#{hier_separator}#{c.print}", "figure")
    #require "debug"; binding.b
    figure_anchor(t, sublabel, hiersemx(clause, num, c, t), "figure")
  end
  hierarchical_figure_class_names(clause, num)
  end
end

#hierarchical_formula_names(clauses, num) ⇒ Object



285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 285

def hierarchical_formula_names(clauses, num)
  c = Counter.new
  nodeSet(clauses).each do |clause|
  clause.xpath(ns(".//formula")).noblank.each do |t|
    @anchors[t["id"]] = anchor_struct(
      #"#{num}#{hier_separator}#{c.increment(t).print}", t,
               hiersemx(clause, num, c.increment(t), t), t,
      t["inequality"] ? @labels["inequality"] : @labels["formula"],
      "formula", { unnumb: t["unnumbered"], container: false }
    )
  end
  end
end

#hierarchical_permission_body(id, parent_id, elem, label, klass, model) ⇒ Object

TODO remove



326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 326

def hierarchical_permission_body(id, parent_id, elem, label, klass, model)
  @anchors[elem["id"]] = model.postprocess_anchor_struct(
    elem, anchor_struct(id, elem,
                        label, klass, { unnumb: elem["unnumbered"], container: false })
  )
  x = "#{subreqt_separator(markup: true)}#{semx(elem, id)}"
  @anchors[elem["id"]][:label] = "#{semx(elem.parent, parent_id)}#{x}"
  @anchors[elem["id"]][:xref] = @anchors[elem.parent["id"]][:xref] + x
  model.permission_parts(elem, id, label, klass).each do |n|
    # we don't have an n["id"], so we allow n[:id] in anchor_struct
    @anchors[n[:id]] = anchor_struct(n[:number], n, n[:label],
                                     n[:klass], { unnumb: false, container: false })
  end
end

#hierarchical_permission_children(block, lbl) ⇒ Object

TODO remove



314
315
316
317
318
319
320
321
322
323
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 314

def hierarchical_permission_children(block, lbl)
  c = ReqCounter.new
  block.xpath(ns(REQ_CHILDREN)).noblank.each do |t|
    m = @reqt_models.model(t["model"])
    klass, label = reqt2class_nested_label(t, m)
    id = "#{lbl}#{subreqt_separator}#{c.increment(label, t).print}"
    sequential_permission_body(c.print, lbl, t, label, klass, m)
    hierarchical_permission_children(t, id)
  end
end

#hierarchical_permission_names(clauses, num) ⇒ Object



299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 299

def hierarchical_permission_names(clauses, num)
  c = ReqCounter.new
  nodeSet(clauses).each do |clause|
  clause.xpath(ns(FIRST_LVL_REQ)).noblank.each do |t|
    m = @reqt_models.model(t["model"])
    klass, label = reqt2class_label(t, m)
    #id = "#{num}#{hier_separator}#{c.increment(label, t).print}"
    id = hiersemx(clause, num, c.increment(label, t), t)
    sequential_permission_body(id, nil, t, label, klass, m, container: false)
    sequential_permission_children(t, id, klass, container: false)
  end
 end
end

#hierarchical_table_names(clauses, num) ⇒ Object



265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 265

def hierarchical_table_names(clauses, num)
  c = Counter.new
  nodeSet(clauses).each do |clause|
  clause.xpath(ns(".//table")).noblank.each do |t|
    # labelled_ancestor(t) and next
    @anchors[t["id"]] =
      #anchor_struct("#{num}#{hier_separator}#{c.increment(t).print}",
      anchor_struct(hiersemx(clause, num, c.increment(t), t),
                    t, @labels["table"], "table", { unnumb: t["unnumbered"], container: false })
  end
  end
end

#hierfigsepObject



10
11
12
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 10

def hierfigsep
  "-"
end

#hierreqtsepObject



14
15
16
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 14

def hierreqtsep
  "-"
end

#hiersepObject



6
7
8
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 6

def hiersep
  "."
end

#id_ancestor(node) ⇒ Object



231
232
233
234
235
236
237
238
# File 'lib/isodoc/xref/xref_gen.rb', line 231

def id_ancestor(node)
  parent = nil
  node.ancestors.each do |a|
    (a["id"] && (parent = a) && @anchors.dig(a["id"], :xref)) or next
    break
  end
  parent ? [parent, parent["id"]] : [nil, nil]
end

#increment_label(elems, node, counter, increment: true) ⇒ Object



39
40
41
42
43
# File 'lib/isodoc/xref/xref_gen.rb', line 39

def increment_label(elems, node, counter, increment: true)
  elems.size == 1 && !node["number"] and return ""
  counter.increment(node) if increment
  counter.print
end

#list_anchor_names(sections) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/isodoc/xref/xref_gen.rb', line 128

def list_anchor_names(sections)
  sections.each do |s|
    notes = s.xpath(ns(".//ol")) - s.xpath(ns(".//clause//ol")) -
      s.xpath(ns(".//appendix//ol")) - s.xpath(ns(".//ol//ol"))
    c = list_counter(0, {})
    notes.noblank.each do |n|
      @anchors[n["id"]] =
        anchor_struct(increment_label(notes, n, c), n,
                      @labels["list"], "list",
                      { unnumb: false, container: true })
      list_item_anchor_names(n, @anchors[n["id"]], 1, "", notes.size != 1)
    end
    list_anchor_names(s.xpath(ns(child_sections)))
  end
end

#list_item_anchor_label(label, list_anchor, prev_label, refer_list) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
# File 'lib/isodoc/xref/xref_gen.rb', line 176

def list_item_anchor_label(label, list_anchor, prev_label, refer_list)
  prev_label.empty? or
    label = @klass.connectives_spans(@i18n.list_nested_xref
      .sub("%1", %[#{prev_label}#{delim_wrap(list_item_delim)}])
      .sub("%2", label))
  refer_list and
    label = @klass.connectives_spans(@i18n.list_nested_xref
      .sub("%1", list_anchor[:xref])
      .sub("%2", label))
  label
end

#list_item_anchor_names(list, list_anchor, depth, prev_label, refer_list) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/isodoc/xref/xref_gen.rb', line 148

def list_item_anchor_names(list, list_anchor, depth, prev_label,
refer_list)
  c = list_counter(list["start"] ? list["start"].to_i - 1 : 0, {})
  list.xpath(ns("./li")).each do |li|
    bare_label, label =
      list_item_value(li, c, depth,
                      { list_anchor:, prev_label:,
                        refer_list: depth == 1 ? refer_list : nil })
    li["id"] ||= "_#{UUIDTools::UUID.random_create}"
    @anchors[li["id"]] =
      { label: bare_label, bare_xref: "#{label})", type: "listitem",
        xref: %[#{label}#{delim_wrap(list_item_delim)}], refer_list:,
        container: list_anchor[:container] }
    (li.xpath(ns(".//ol")) - li.xpath(ns(".//ol//ol"))).each do |ol|
      list_item_anchor_names(ol, list_anchor, depth + 1, label,
                             refer_list)
    end
  end
end

#list_item_delimObject



144
145
146
# File 'lib/isodoc/xref/xref_gen.rb', line 144

def list_item_delim
  ")"
end

#list_item_value(entry, counter, depth, opts) ⇒ Object



168
169
170
171
172
173
174
# File 'lib/isodoc/xref/xref_gen.rb', line 168

def list_item_value(entry, counter, depth, opts)
  label = counter.increment(entry).listlabel(entry.parent, depth)
  s = semx(entry, label)
  [label,
   list_item_anchor_label(s, opts[:list_anchor], opts[:prev_label],
                          opts[:refer_list])]
end

#nodeSet(clauses) ⇒ Object



220
221
222
223
224
225
226
227
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 220

def nodeSet(clauses)
  case clauses
  when Nokogiri::XML::Node
    [clauses]
  when Nokogiri::XML::NodeSet
    clauses
  end
end

#note_anchor_names(sections) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/isodoc/xref/xref_gen.rb', line 75

def note_anchor_names(sections)
  sections.each do |s|
    notes = s.xpath(child_asset_path("note")) -
      s.xpath(ns(".//figure//note | .//table//note"))
    note_anchor_names1(notes, Counter.new)
    note_anchor_names(s.xpath(ns(child_sections)))
  end
end

#note_anchor_names1(notes, counter) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/isodoc/xref/xref_gen.rb', line 84

def note_anchor_names1(notes, counter)
  notes.noblank.each do |n|
    @anchors[n["id"]] =
      anchor_struct(increment_label(notes, n, counter), n,
                    @labels["note_xref"], "note",
                    { container: true, unnumb: false })
  end
end

#reqt2class_label(elem, model) ⇒ Object



195
196
197
198
199
200
201
202
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 195

def reqt2class_label(elem, model)
  elem["class"] and return [elem["class"], elem["class"]]
  model.req_class_paths.each do |n|
    v1 = ns("/#{n[:xpath]}").sub(%r{^/}, "")
    elem.at("./self::#{v1}") and return [n[:klass], n[:label]]
  end
  [nil, nil]
end

#reqt2class_nested_label(elem, model) ⇒ Object



204
205
206
207
208
209
210
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 204

def reqt2class_nested_label(elem, model)
  model.req_nested_class_paths.each do |n|
    v1 = ns("/#{n[:xpath]}").sub(%r{^/}, "")
    elem.at("./self::#{v1}") and return [n[:klass], n[:label]]
  end
  [nil, nil]
end

#sequential_asset_names(clause, container: false) ⇒ Object

container makes numbering be prefixed with the parent clause reference



213
214
215
216
217
218
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 213

def sequential_asset_names(clause, container: false)
  sequential_table_names(clause, container:)
  sequential_figure_names(clause, container:)
  sequential_formula_names(clause, container:)
  sequential_permission_names(clause, container:)
end

#sequential_figure_class_names(clause, container: false) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 43

def sequential_figure_class_names(clause, container: false)
  c = {}
  j = 0
  clause.xpath(ns(".//figure[@class][not(@class = 'pseudocode')]"))
    .each do |t|
    c[t["class"]] ||= Counter.new
    # labelled_ancestor(t, %w(figure)) and next
    j = subfigure_increment(j, c[t["class"]], t)
    sublabel = subfigure_label(j)
    figure_anchor(t, sublabel, c[t["class"]].print, t["class"],
                  container: container)
  end
end

#sequential_figure_names(clause, container: false) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 31

def sequential_figure_names(clause, container: false)
  c = Counter.new
  j = 0
  clause.xpath(ns(self.class::FIGURE_NO_CLASS)).noblank.each do |t|
    # labelled_ancestor(t, %w(figure)) and next # disable nested figure labelling
    j = subfigure_increment(j, c, t)
    sublabel = subfigure_label(j)
    figure_anchor(t, sublabel, c.print, "figure", container: container)
  end
  sequential_figure_class_names(clause, container:)
end

#sequential_formula_names(clause, container: false) ⇒ Object



128
129
130
131
132
133
134
135
136
137
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 128

def sequential_formula_names(clause, container: false)
  c = Counter.new
  clause.xpath(ns(".//formula")).noblank.each do |t|
    @anchors[t["id"]] = anchor_struct(
      c.increment(t).print, t,
      t["inequality"] ? @labels["inequality"] : @labels["formula"],
      "formula", { unnumb: t["unnumbered"], container: true }
    )
  end
end

#sequential_permission_body(id, parent_id, elem, label, klass, model, container: false) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 174

def sequential_permission_body(id, parent_id, elem, label, klass, model,
container: false)
  lbl = parent_id ? "#{parent_id}#{subreqt_separator}#{id}" : id
  @anchors[elem["id"]] = model.postprocess_anchor_struct(
    elem, anchor_struct(lbl, elem,
                        label, klass, { unnumb: elem["unnumbered"], container: })
  )
  @anchors[elem["id"]][:semx] = semx(elem, lbl)
  if parent_id
    x = "#{subreqt_separator(markup: true)}#{semx(elem, id)}"
    @anchors[elem["id"]][:semx] = @anchors[elem.parent["id"]][:semx] + x
    @anchors[elem["id"]][:label] =
      "<span class='fmt-element-name'>#{label}</span> #{@anchors[elem["id"]][:semx]}"
    @anchors[elem["id"]][:xref] =  "<span class='fmt-element-name'>#{label}</span> #{@anchors[elem["id"]][:semx]}"
  end
  model.permission_parts(elem, id, label, klass).each do |n|
    @anchors[n[:id]] = anchor_struct(n[:number], n[:elem], n[:label],
                                     n[:klass], { unnumb: false, container: })
  end
end

#sequential_permission_children(elem, lbl, klass, container: false) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 161

def sequential_permission_children(elem, lbl, klass, container: false)
  c = ReqCounter.new
  elem.xpath(ns(REQ_CHILDREN)).noblank.each do |t|
    m = @reqt_models.model(t["model"])
    klass, label = reqt2class_nested_label(t, m)
    ctr = c.increment(label, t).print
    id = "#{lbl}#{subreqt_separator}#{ctr}"
    sequential_permission_body(ctr, lbl, t, label, klass, m,
                               container:)
    sequential_permission_children(t, id, klass, container:)
  end
end

#sequential_permission_names(clause, container: true) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 149

def sequential_permission_names(clause, container: true)
  c = ReqCounter.new
  clause.xpath(ns(FIRST_LVL_REQ)).noblank.each do |t|
    m = @reqt_models.model(t["model"])
    klass, label = reqt2class_label(t, m)
    id = c.increment(label, t).print
    sequential_permission_body(id, nil, t, label, klass, m,
                               container:)
    sequential_permission_children(t, id, klass, container:)
  end
end

#sequential_table_names(clause, container: false) ⇒ Object



117
118
119
120
121
122
123
124
125
126
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 117

def sequential_table_names(clause, container: false)
  c = Counter.new
  clause.xpath(ns(".//table")).noblank.each do |t|
    # labelled_ancestor(t) and next
    @anchors[t["id"]] = anchor_struct(
      c.increment(t).print, t,
      @labels["table"], "table", { unnumb: t["unnumbered"], container: container }
    )
  end
end

#subfigure_anchor(elem, sublabel, label, klass, container: false) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 101

def subfigure_anchor(elem, sublabel, label, klass, container: false)
  figlabel = fig_subfig_label(label, sublabel)
  @anchors[elem["id"]] = anchor_struct(
    figlabel, elem, @labels[klass] || klass.capitalize, klass,
    { unnumb: elem["unnumbered"] }
  )
  if elem["unnumbered"] != "true"
    x = "#{subfigure_separator(markup: true)}#{semx(elem, sublabel)}"
    @anchors[elem["id"]][:label] = "#{label}#{x}" # "#{semx(elem.parent, label)}#{x}"
    @anchors[elem["id"]][:xref] = @anchors[elem.parent["id"]][:xref] + x +
      delim_wrap(subfigure_delim)
    x = @anchors[elem.parent["id"]][:container] and
    @anchors[elem["id"]][:container] = x
  end
end

#subfigure_delimObject



80
81
82
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 80

def subfigure_delim
  ""
end

#subfigure_increment(idx, counter, elem) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 18

def subfigure_increment(idx, counter, elem)
  if elem.parent.name == "figure" then idx += 1
  else
    idx = 0
    counter.increment(elem)
  end
  idx
end

#subfigure_label(subfignum) ⇒ Object



63
64
65
66
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 63

def subfigure_label(subfignum)
  subfignum.zero? and return
  subfignum.to_s
end

#subfigure_separator(markup: false) ⇒ Object



68
69
70
71
72
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 68

def subfigure_separator(markup: false)
  h = hierfigsep
  h.blank? || !markup or h = delim_wrap(h)
  h
end

#subreqt_separator(markup: false) ⇒ Object



74
75
76
77
78
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 74

def subreqt_separator(markup: false)
  h = hierreqtsep
  h.blank? || !markup or h = delim_wrap(h)
  h
end

#termexample_anchor_names(docxml) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/isodoc/xref/xref_gen.rb', line 59

def termexample_anchor_names(docxml)
  docxml.xpath(ns("//*[termexample]")).each do |t|
    examples = t.xpath(ns("./termexample"))
    c = Counter.new
    examples.noblank.each do |n|
      c.increment(n)
      idx = increment_label(examples, n, c, increment: false)
      @anchors[n["id"]] =
        { label: idx, type: "termexample",
          value: idx, elem: @labels["example_xref"],
          container: t["id"],
          xref: anchor_struct_xref(idx, n, @labels["example_xref"]) }
    end
  end
end

#termnote_anchor_names(docxml) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/isodoc/xref/xref_gen.rb', line 45

def termnote_anchor_names(docxml)
  docxml.xpath(ns("//*[termnote]")).each do |t|
    c = Counter.new
    t.xpath(ns("./termnote")).noblank.each do |n|
      c.increment(n)
      @anchors[n["id"]] =
        { label: termnote_label(n, c.print), type: "termnote",
          value: c.print, elem: @labels["termnote"],
          container: t["id"],
          xref: anchor_struct_xref(c.print, n, @labels["note_xref"]) }
    end
  end
end

#termnote_label(node, label) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/isodoc/xref/xref_gen.rb', line 31

def termnote_label(node, label)
  if label.blank?
    @labels["termnote"].gsub(/%\s?/, "")
  else
    @labels["termnote"].gsub("%", semx(node, label.to_s))
  end
end