Module: IsoDoc::XrefGen::Blocks
- Included in:
- IsoDoc::Xref
- Defined in:
- lib/isodoc/xref/xref_gen.rb,
lib/isodoc/xref/xref_gen_seq.rb,
lib/isodoc/xref/xref_list_gen.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
Instance Method Summary collapse
- #admonition_anchor_names(sections) ⇒ Object
- #admonition_anchor_names1(notes, counter) ⇒ Object
-
#amend_autonumber(node, blocktype, autonum, old_autonum, idx) ⇒ Object
only autonumber first instance of an asset in a subclause, if the autonumbering for that asset isn’t a continuation of its ancestor clause.
- #amend_autonums(amend) ⇒ Object
- #amend_blocks(amend, autonum, old_autonum, blocktype, subclause) ⇒ Object
- #amend_newcontent(subclause) ⇒ Object
- #amend_preprocess(xmldoc) ⇒ Object
- #amend_preprocess1(amend, subclause: false, autonum: {}) ⇒ Object
-
#bibitem_note_names(bib) ⇒ Object
processed from Presentation XML notes_inside_bibitem(), after notes moved: need docid from references processing.
- #bookmark_anchor_names(xml) ⇒ Object
- #bookmark_container(parent) ⇒ Object
- #deflist_anchor_names(sections) ⇒ Object
- #deflist_anchor_names1(notes, counter) ⇒ Object
- #deflist_term_anchor_lbl(listitem, list_anchor) ⇒ Object
- #deflist_term_anchor_names(list, list_anchor) ⇒ Object
- #dt2xreflabel(dterm) ⇒ Object
- #example_anchor_names(sections) ⇒ Object
- #example_anchor_names1(notes, counter) ⇒ Object
- #fig_subfig_label(label, sublabel) ⇒ Object
- #figure_anchor(elem, sublabel, label, klass, container: false) ⇒ Object
- #hierarchical_figure_class_names(clauses, num) ⇒ Object
-
#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.
- #hierarchical_formula_names(clauses, num) ⇒ Object
- #hierarchical_permission_names(clauses, num) ⇒ Object
- #hierarchical_table_names(clauses, num) ⇒ Object
- #id_ancestor(node) ⇒ Object
- #list_anchor_names(sections) ⇒ Object
- #list_item_anchor_label(label, list_anchor, prev_label, refer_list) ⇒ Object
- #list_item_anchor_names(list, list_anchor, depth, prev_label, refer_list) ⇒ Object
- #list_item_delim ⇒ Object
- #list_item_value(entry, counter, depth, opts) ⇒ Object
-
#nested_examples(asset, container: true) ⇒ Object
note within an asset: provision.
-
#nested_notes(asset, container: true) ⇒ Object
note within an asset: table, figure, provision.
- #note_anchor_names(sections) ⇒ Object
- #note_anchor_names1(notes, counter) ⇒ Object
- #para_anchor_names(sections) ⇒ Object
- #para_anchor_names1(notes, counter) ⇒ Object
- #reqt2class_label(elem, model) ⇒ Object
- #reqt2class_nested_label(elem, model) ⇒ Object
- #sequential_figure_class_names(clause, container: false) ⇒ Object
- #sequential_figure_names(clause, container: false) ⇒ Object
- #sequential_formula_names(clause, container: false) ⇒ Object
- #sequential_permission_body(id, parent_id, elem, label, klass, model, container: false) ⇒ Object
- #sequential_permission_body_parent_id(id, parent_id, elem, label, e) ⇒ Object
- #sequential_permission_children(elem, lbl, klass, container: false) ⇒ Object
- #sequential_permission_names(clause, container: true) ⇒ Object
- #sequential_table_names(clause, container: false) ⇒ Object
- #subfigure_anchor(elem, sublabel, label, klass, container: false) ⇒ Object
- #subfigure_increment(idx, counter, elem) ⇒ Object
- #subfigure_label(subfignum) ⇒ Object
- #termexample_anchor_names(docxml) ⇒ Object
- #termnote_anchor_names(docxml) ⇒ Object
- #termnote_label(node, label) ⇒ Object
Instance Method Details
#admonition_anchor_names(sections) ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/isodoc/xref/xref_gen.rb', line 137 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
146 147 148 149 150 151 152 153 |
# File 'lib/isodoc/xref/xref_gen.rb', line 146 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_autonumber(node, blocktype, autonum, old_autonum, idx) ⇒ Object
only autonumber first instance of an asset in a subclause, if the autonumbering for that asset isn’t a continuation of its ancestor clause
44 45 46 47 48 49 |
# File 'lib/isodoc/xref/xref_gen.rb', line 44 def amend_autonumber(node, blocktype, autonum, old_autonum, idx) autonum[blocktype] && idx.zero? && autonum[blocktype] != old_autonum[blocktype] and node["number"] = autonum[blocktype] !autonum[blocktype] and node["unnumbered"] = "true" end |
#amend_autonums(amend) ⇒ Object
26 27 28 29 30 |
# File 'lib/isodoc/xref/xref_gen.rb', line 26 def amend_autonums(amend) amend.xpath(ns("./autonumber")).each_with_object({}) do |n, m| m[n["type"]] = n.text end end |
#amend_blocks(amend, autonum, old_autonum, blocktype, subclause) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/isodoc/xref/xref_gen.rb', line 32 def amend_blocks(amend, autonum, old_autonum, blocktype, subclause) newc = amend_newcontent(subclause) (amend.xpath(ns(".#{newc}//#{blocktype}")) - amend.xpath(ns(".#{newc}/clause//#{blocktype}"))) .each_with_index do |e, i| amend_autonumber(e, blocktype, autonum, old_autonum, i) end end |
#amend_newcontent(subclause) ⇒ Object
51 52 53 |
# File 'lib/isodoc/xref/xref_gen.rb', line 51 def amend_newcontent(subclause) subclause ? "" : "/newcontent" end |
#amend_preprocess(xmldoc) ⇒ Object
8 9 10 11 12 |
# File 'lib/isodoc/xref/xref_gen.rb', line 8 def amend_preprocess(xmldoc) xmldoc.xpath(ns("//amend[newcontent]")).each do |a| amend_preprocess1(a) end end |
#amend_preprocess1(amend, subclause: false, autonum: {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/isodoc/xref/xref_gen.rb', line 14 def amend_preprocess1(amend, subclause: false, autonum: {}) newautonum = amend_autonums(amend).merge(autonum) NUMBERED_BLOCKS.each do |b| amend_blocks(amend, newautonum, autonum, b, subclause) end amend.xpath(ns(".#{amend_newcontent(subclause)}/clause")) .each_with_index do |c, i| amend_autonumber(c, "clause", newautonum, autonum, i) amend_preprocess1(c, subclause: true, autonum: newautonum) end end |
#bibitem_note_names(bib) ⇒ Object
processed from Presentation XML notes_inside_bibitem(), after notes moved: need docid from references processing
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/isodoc/xref/xref_gen.rb', line 79 def bibitem_note_names(bib) notes = bib.xpath(ns("./formattedref/note")) counter = Counter.new notes.noblank.each do |n| lbl = increment_label(notes, n, counter) @anchors[n["id"]] = { label: lbl, value: lbl, container: bib["id"], xref: anchor_struct_xref(lbl, n, @labels["note_xref"]), elem: @labels["note_xref"], type: "note" } end end |
#bookmark_anchor_names(xml) ⇒ Object
223 224 225 226 227 228 229 230 |
# File 'lib/isodoc/xref/xref_gen.rb', line 223 def bookmark_anchor_names(xml) xml.xpath(ns(".//bookmark")).noblank.each do |n| _parent, id = id_ancestor(n) @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
213 214 215 216 217 218 219 220 221 |
# File 'lib/isodoc/xref/xref_gen.rb', line 213 def bookmark_container(parent) if parent clause = parent.xpath(CLAUSE_ANCESTOR)&.last if clause["id"] == id then nil else @anchors.dig(clause["id"], :xref) end end end |
#deflist_anchor_names(sections) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/isodoc/xref/xref_list_gen.rb', line 63 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
72 73 74 75 76 77 78 79 80 |
# File 'lib/isodoc/xref/xref_list_gen.rb', line 72 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
94 95 96 97 |
# File 'lib/isodoc/xref/xref_list_gen.rb', line 94 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
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/isodoc/xref/xref_list_gen.rb', line 82 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
99 100 101 102 103 104 |
# File 'lib/isodoc/xref/xref_list_gen.rb', line 99 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
167 168 169 170 171 172 173 174 175 |
# File 'lib/isodoc/xref/xref_gen.rb', line 167 def example_anchor_names(sections) sections.each do |s| notes = s.xpath(child_asset_path("example")) - s.xpath(ns("//permission//note | " \ "//recommendation//note | //requirement//note")) example_anchor_names1(notes, Counter.new) example_anchor_names(s.xpath(ns(child_sections))) end end |
#example_anchor_names1(notes, counter) ⇒ Object
177 178 179 180 181 182 183 184 |
# File 'lib/isodoc/xref/xref_gen.rb', line 177 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
62 63 64 65 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 62 def fig_subfig_label(label, sublabel) label && sublabel or return "#{label}#{subfigure_separator}#{sublabel}" end |
#figure_anchor(elem, sublabel, label, klass, container: false) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 49 def figure_anchor(elem, sublabel, label, klass, container: false) if sublabel label&.include?("<semx") 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 nested_notes(elem) end |
#hierarchical_figure_class_names(clauses, num) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 192 def hierarchical_figure_class_names(clauses, num) j = 0 nodeSet(clauses).each_with_object({}) do |clause, c| clause.xpath(ns(".//figure[@class][not(@class = 'pseudocode')]")) .noblank.each do |t| c[t["class"]] ||= Counter.new j = subfigure_increment(j, c[t["class"]], t) sublabel = subfigure_label(j) 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
179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 179 def hierarchical_figure_names(clauses, num) j = 0 nodeSet(clauses).each_with_object(Counter.new) do |clause, c| 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) 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
218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 218 def hierarchical_formula_names(clauses, num) nodeSet(clauses).each_with_object(Counter.new) do |clause, c| clause.xpath(ns(".//formula")).noblank.each do |t| @anchors[t["id"]] = anchor_struct( hiersemx(clause, num, c.increment(t), t), t, t["inequality"] ? @labels["inequality"] : @labels["formula"], "formula", { unnumb: t["unnumbered"], container: false } ) @anchors[t["id"]][:bare_xref] = @anchors[t["id"]][:label] end end end |
#hierarchical_permission_names(clauses, num) ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 231 def (clauses, num) nodeSet(clauses).each_with_object(ReqCounter.new) do |clause, c| clause.xpath(ns(first_lvl_req)).noblank.each do |t| m = @reqt_models.model(t["model"]) klass, label = reqt2class_label(t, m) id = hiersemx(clause, num, c.increment(label, t), t) (id, nil, t, label, klass, m, container: false) (t, id, klass, container: false) end end end |
#hierarchical_table_names(clauses, num) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 206 def hierarchical_table_names(clauses, num) nodeSet(clauses).each_with_object(Counter.new) do |clause, c| clause.xpath(ns(".//table")).noblank.each do |t| @anchors[t["id"]] = anchor_struct(hiersemx(clause, num, c.increment(t), t), t, @labels["table"], "table", { unnumb: t["unnumbered"], container: false }) nested_notes(t) end end end |
#id_ancestor(node) ⇒ Object
204 205 206 207 208 209 210 211 |
# File 'lib/isodoc/xref/xref_gen.rb', line 204 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 |
#list_anchor_names(sections) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/isodoc/xref/xref_list_gen.rb', line 4 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
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/isodoc/xref/xref_list_gen.rb', line 51 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
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/isodoc/xref/xref_list_gen.rb', line 24 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| , label = list_item_value(li, c, depth, { list_anchor:, prev_label:, refer_list: depth == 1 ? refer_list : nil }) @anchors[li["id"]] = { 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_delim ⇒ Object
20 21 22 |
# File 'lib/isodoc/xref/xref_list_gen.rb', line 20 def list_item_delim ")" end |
#list_item_value(entry, counter, depth, opts) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/isodoc/xref/xref_list_gen.rb', line 43 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 |
#nested_examples(asset, container: true) ⇒ Object
note within an asset: provision
156 157 158 159 160 161 162 163 164 165 |
# File 'lib/isodoc/xref/xref_gen.rb', line 156 def nested_examples(asset, container: true) notes = asset.xpath(ns(".//example")) notes.noblank.each_with_object(Counter.new) do |n, counter| @anchors[n["id"]] ||= anchor_struct(increment_label(notes, n, counter), n, @labels["example_xref"], "example", { unnumb: n["unnumbered"] }) @anchors[n["id"]][:container] = container ? asset["id"] : nil end end |
#nested_notes(asset, container: true) ⇒ Object
note within an asset: table, figure, provision
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/isodoc/xref/xref_gen.rb', line 92 def nested_notes(asset, container: true) notes = asset.xpath(ns(".//note")) counter = Counter.new notes.noblank.each do |n| lbl = increment_label(notes, n, counter) @anchors[n["id"]] = { label: lbl, value: lbl, container: container ? asset["id"] : nil, xref: anchor_struct_xref(lbl, n, @labels["note_xref"]), elem: @labels["note_xref"], type: "note" }.compact end end |
#note_anchor_names(sections) ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/isodoc/xref/xref_gen.rb', line 118 def note_anchor_names(sections) sections.each do |s| notes = s.xpath(child_asset_path("note")) - s.xpath(ns(".//figure//note | .//table//note | //permission//note | " \ "//recommendation//note | //requirement//note")) note_anchor_names1(notes, Counter.new) note_anchor_names(s.xpath(ns(child_sections))) end end |
#note_anchor_names1(notes, counter) ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/isodoc/xref/xref_gen.rb', line 128 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 |
#para_anchor_names(sections) ⇒ Object
186 187 188 189 190 191 192 |
# File 'lib/isodoc/xref/xref_gen.rb', line 186 def para_anchor_names(sections) sections.each do |s| notes = s.xpath(ns("./p")) para_anchor_names1(notes, Counter.new) para_anchor_names(s.xpath(ns(child_sections))) end end |
#para_anchor_names1(notes, counter) ⇒ Object
194 195 196 197 198 199 200 201 202 |
# File 'lib/isodoc/xref/xref_gen.rb', line 194 def para_anchor_names1(notes, counter) notes.noblank.each do |n| counter.increment(n) @anchors[n["id"]] = anchor_struct(counter.print, n, @labels["para_xref"], "paragraph", { container: true, unnumb: false }) end end |
#reqt2class_label(elem, model) ⇒ Object
160 161 162 163 164 165 166 167 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 160 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
169 170 171 172 173 174 175 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 169 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_figure_class_names(clause, container: false) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 32 def sequential_figure_class_names(clause, container: false) j = 0 clause.xpath(ns(".//figure[@class][not(@class = 'pseudocode')]")) .each_with_object({}) do |t, c| c[t["class"]] ||= Counter.new 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
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 20 def sequential_figure_names(clause, container: false) j = 0 clause.xpath(ns(self.class::FIGURE_NO_CLASS)).noblank .each_with_object(Counter.new) do |t, c| # 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
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 95 def sequential_formula_names(clause, container: false) clause.xpath(ns(".//formula")).noblank .each_with_object(Counter.new) do |t, c| @anchors[t["id"]] = anchor_struct( c.increment(t).print, t, t["inequality"] ? @labels["inequality"] : @labels["formula"], "formula", { unnumb: t["unnumbered"], container: true } ) @anchors[t["id"]][:bare_xref] = @anchors[t["id"]][:label] end end |
#sequential_permission_body(id, parent_id, elem, label, klass, model, container: false) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 132 def (id, parent_id, elem, label, klass, model, container: false) lbl = parent_id ? "#{parent_id}#{subreqt_separator}#{id}" : id e = elem["id"] || elem["original-id"] @anchors[e] = model.postprocess_anchor_struct( elem, anchor_struct(lbl, elem, label, klass, { unnumb: elem["unnumbered"], container: }) ) nested_notes(elem) nested_examples(elem) @anchors[e][:semx] = semx(elem, lbl) (id, parent_id, elem, label, e) model.(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_body_parent_id(id, parent_id, elem, label, e) ⇒ Object
150 151 152 153 154 155 156 157 158 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 150 def (id, parent_id, elem, label, e) parent_id or return x = "#{subreqt_separator(markup: true)}#{semx(elem, id)}" @anchors[e][:semx] = @anchors[elem.parent["id"] || elem.parent["original-id"]][:semx] + x @anchors[e][:label] = "<span class='fmt-element-name'>#{label}</span> #{@anchors[e][:semx]}" @anchors[e][:xref] = @anchors[e][:label] end |
#sequential_permission_children(elem, lbl, klass, container: false) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 119 def (elem, lbl, klass, container: false) elem.xpath(ns(req_children)).noblank .each_with_object(ReqCounter.new) do |t, c| m = @reqt_models.model(t["model"]) klass, label = reqt2class_nested_label(t, m) ctr = c.increment(label, t).print id = "#{lbl}#{subreqt_separator}#{ctr}" (ctr, lbl, t, label, klass, m, container:) (t, id, klass, container:) end end |
#sequential_permission_names(clause, container: true) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 107 def (clause, container: true) clause.xpath(ns(first_lvl_req)).noblank .each_with_object(ReqCounter.new) do |t, c| m = @reqt_models.model(t["model"]) klass, label = reqt2class_label(t, m) id = c.increment(label, t).print (id, nil, t, label, klass, m, container:) (t, id, klass, container:) end end |
#sequential_table_names(clause, container: false) ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 84 def sequential_table_names(clause, container: false) clause.xpath(ns(".//table")).noblank .each_with_object(Counter.new) do |t, c| @anchors[t["id"]] = anchor_struct( c.increment(t).print, t, @labels["table"], "table", { unnumb: t["unnumbered"], container: container } ) nested_notes(t) end end |
#subfigure_anchor(elem, sublabel, label, klass, container: false) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 67 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" p = elem.at("./ancestor::xmlns:figure") x = "#{subfigure_separator(markup: true)}#{semx(elem, sublabel)}" @anchors[elem["id"]][:label] = "#{label}#{x}" @anchors[elem["id"]][:xref] = @anchors[p["id"]][:xref] + x + delim_wrap(subfigure_delim) x = @anchors[p["id"]][:container] and @anchors[elem["id"]][:container] = x end end |
#subfigure_increment(idx, counter, elem) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 7 def subfigure_increment(idx, counter, elem) if elem.ancestors.map(&:name).include?("figure") then idx += 1 else idx = 0 counter.increment(elem) end idx end |
#subfigure_label(subfignum) ⇒ Object
44 45 46 47 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 44 def subfigure_label(subfignum) subfignum.zero? and return subfignum.to_s end |
#termexample_anchor_names(docxml) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/isodoc/xref/xref_gen.rb', line 104 def termexample_anchor_names(docxml) docxml.xpath(ns("//*[termexample]")).each do |t| examples = t.xpath(ns("./termexample")) examples.noblank.each_with_object(Counter.new) do |n, c| 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
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/isodoc/xref/xref_gen.rb', line 63 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
55 56 57 58 59 60 61 |
# File 'lib/isodoc/xref/xref_gen.rb', line 55 def termnote_label(node, label) if label.blank? @labels["termnote"].gsub(/%\s?/, "") else @labels["termnote"].gsub("%", semx(node, label.to_s)) end end |