module IsoDoc::XrefGen::Blocks
Constants
- CHILD_EXAMPLES_XPATH
- CHILD_NOTES_XPATH
- CHILD_SECTIONS
- FIRST_LVL_REQ
- NUMBERED_BLOCKS
- SECTIONS_XPATH
Public Instance Methods
amend_autonums(amend)
click to toggle source
# File lib/isodoc/xref/xref_gen.rb, line 20 def amend_autonums(amend) autonum = {} amend.xpath(ns("./autonumber")).each do |n| autonum[n["type"]] = n.text end autonum end
amend_preprocess(xmldoc)
click to toggle source
# File lib/isodoc/xref/xref_gen.rb, line 8 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(docxml)
click to toggle source
# File lib/isodoc/xref/xref_gen.rb, line 184 def bookmark_anchor_names(docxml) docxml.xpath(ns(".//bookmark")).each do |n| next if n["id"].nil? || n["id"].empty? parent = nil n.ancestors.each do |a| next unless a["id"] && parent = @anchors.dig(a["id"], :xref) break end @anchors[n["id"]] = { type: "bookmark", label: nil, value: nil, xref: parent || "???" } end end
deflist_anchor_names(sections)
click to toggle source
# File lib/isodoc/xref/xref_gen.rb, line 154 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")) c = Counter.new notes.each do |n| next if n["id"].nil? || n["id"].empty? @anchors[n["id"]] = anchor_struct(increment_label(notes, n, c), n, @labels["deflist"], "deflist", false) deflist_term_anchor_names(n, @anchors[n["id"]]) end deflist_anchor_names(s.xpath(ns(CHILD_SECTIONS))) end end
deflist_term_anchor_names(list, list_anchor)
click to toggle source
# File lib/isodoc/xref/xref_gen.rb, line 171 def deflist_term_anchor_names(list, list_anchor) list.xpath(ns("./dt")).each do |li| label = li.text label = l10n("#{list_anchor[:xref]}: #{label}") 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
example_anchor_names(sections)
click to toggle source
# File lib/isodoc/xref/xref_gen.rb, line 109 def example_anchor_names(sections) sections.each do |s| c = Counter.new (notes = s.xpath(CHILD_EXAMPLES_XPATH)).each do |n| next if @anchors[n["id"]] || n["id"].nil? || n["id"].empty? @anchors[n["id"]] = anchor_struct(increment_label(notes, n, c), n, @labels["example_xref"], "example", n["unnumbered"]) end example_anchor_names(s.xpath(ns(CHILD_SECTIONS))) end end
hierarchical_asset_names(clause, num)
click to toggle source
# File lib/isodoc/xref/xref_gen_seq.rb, line 130 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, "permission", @labels["permission"]) hierarchical_permission_names(clause, num, "requirement", @labels["requirement"]) hierarchical_permission_names(clause, num, "recommendation", @labels["recommendation"]) end
hierarchical_figure_names(clause, num)
click to toggle source
# File lib/isodoc/xref/xref_gen_seq.rb, line 104 def hierarchical_figure_names(clause, num) c = Counter.new j = 0 clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]")) .each do |t| j = subfigure_increment(j, c, t) label = "#{num}#{hiersep}#{c.print}" + (j.zero? ? "" : "#{hierfigsep}#{j}") next if t["id"].nil? || t["id"].empty? @anchors[t["id"]] = anchor_struct(label, nil, @labels["figure"], "figure", t["unnumbered"]) end end
hierarchical_formula_names(clause, num)
click to toggle source
# File lib/isodoc/xref/xref_gen_seq.rb, line 142 def hierarchical_formula_names(clause, num) c = Counter.new clause.xpath(ns(".//formula")).each do |t| next if t["id"].nil? || t["id"].empty? @anchors[t["id"]] = anchor_struct( "#{num}#{hiersep}#{c.increment(t).print}", nil, t["inequality"] ? @labels["inequality"] : @labels["formula"], "formula", t["unnumbered"] ) end end
hierarchical_permission_names(clause, num, klass, label)
click to toggle source
# File lib/isodoc/xref/xref_gen_seq.rb, line 155 def hierarchical_permission_names(clause, num, klass, label) c = Counter.new clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}")).each do |t| next if t["id"].nil? || t["id"].empty? id = "#{num}#{hiersep}#{c.increment(t).print}" @anchors[t["id"]] = anchor_struct(id, nil, label, klass, t["unnumbered"]) hierarchical_permission_names2(t, id) end end
hierarchical_permission_names1(block, lbl, klass, label)
click to toggle source
# File lib/isodoc/xref/xref_gen_seq.rb, line 176 def hierarchical_permission_names1(block, lbl, klass, label) c = Counter.new block.xpath(ns("./#{klass}")).each do |t| next if t["id"].nil? || t["id"].empty? id = "#{lbl}#{hierfigsep}#{c.increment(t).print}" @anchors[t["id"]] = anchor_struct(id, nil, label, klass, t["unnumbered"]) hierarchical_permission_names2(t, id) end end
hierarchical_permission_names2(elem, ident)
click to toggle source
# File lib/isodoc/xref/xref_gen_seq.rb, line 167 def hierarchical_permission_names2(elem, ident) hierarchical_permission_names1(elem, ident, "permission", @labels["permission"]) hierarchical_permission_names1(elem, ident, "requirement", @labels["requirement"]) hierarchical_permission_names1(elem, ident, "recommendation", @labels["recommendation"]) end
hierarchical_table_names(clause, num)
click to toggle source
# File lib/isodoc/xref/xref_gen_seq.rb, line 119 def hierarchical_table_names(clause, num) c = Counter.new clause.xpath(ns(".//table")).each do |t| next if t["id"].nil? || t["id"].empty? @anchors[t["id"]] = anchor_struct("#{num}#{hiersep}#{c.increment(t).print}", nil, @labels["table"], "table", t["unnumbered"]) end end
hierfigsep()
click to toggle source
# File lib/isodoc/xref/xref_gen_seq.rb, line 7 def hierfigsep "-" end
hiersep()
click to toggle source
# File lib/isodoc/xref/xref_gen_seq.rb, line 3 def hiersep "." end
increment_label(elems, node, counter, increment = true)
click to toggle source
# File lib/isodoc/xref/xref_gen.rb, line 32 def increment_label(elems, node, counter, increment = true) return "" if elems.size == 1 && !node["number"] counter.increment(node) if increment " #{counter.print}" end
list_anchor_names(sections)
click to toggle source
# File lib/isodoc/xref/xref_gen.rb, line 123 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 = Counter.new notes.each do |n| next if n["id"].nil? || n["id"].empty? @anchors[n["id"]] = anchor_struct(increment_label(notes, n, c), n, @labels["list"], "list", false) 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_names(list, list_anchor, depth, prev_label, refer_list)
click to toggle source
# File lib/isodoc/xref/xref_gen.rb, line 139 def list_item_anchor_names(list, list_anchor, depth, prev_label, refer_list) c = Counter.new(list["start"] ? list["start"].to_i - 1 : 0) list.xpath(ns("./li")).each do |li| label = c.increment(li).listlabel(list, depth) label = "#{prev_label}.#{label}" unless prev_label.empty? label = "#{list_anchor[:xref]} #{label}" if refer_list li["id"] and @anchors[li["id"]] = { xref: "#{label})", type: "listitem", container: list_anchor[:container] } li.xpath(ns("./ol")).each do |ol| list_item_anchor_names(ol, list_anchor, depth + 1, label, false) end end end
note_anchor_names(sections)
click to toggle source
# File lib/isodoc/xref/xref_gen.rb, line 87 def note_anchor_names(sections) sections.each do |s| c = Counter.new (notes = s.xpath(CHILD_NOTES_XPATH)).each do |n| next if @anchors[n["id"]] || n["id"].nil? || n["id"].empty? @anchors[n["id"]] = anchor_struct(increment_label(notes, n, c), n, @labels["note_xref"], "note", false) end note_anchor_names(s.xpath(ns(CHILD_SECTIONS))) end end
sections_xpath()
click to toggle source
# File lib/isodoc/xref/xref_gen.rb, line 78 def sections_xpath SECTIONS_XPATH end
sequential_asset_names(clause)
click to toggle source
# File lib/isodoc/xref/xref_gen_seq.rb, line 94 def sequential_asset_names(clause) sequential_table_names(clause) sequential_figure_names(clause) sequential_formula_names(clause) sequential_permission_names(clause, "permission", @labels["permission"]) sequential_permission_names(clause, "requirement", @labels["requirement"]) sequential_permission_names(clause, "recommendation", @labels["recommendation"]) end
sequential_figure_names(clause)
click to toggle source
# File lib/isodoc/xref/xref_gen_seq.rb, line 20 def sequential_figure_names(clause) c = Counter.new j = 0 clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]")) .each do |t| j = subfigure_increment(j, c, t) label = c.print + (j.zero? ? "" : "-#{j}") next if t["id"].nil? || t["id"].empty? @anchors[t["id"]] = anchor_struct( label, nil, @labels["figure"], "figure", t["unnumbered"] ) end end
sequential_formula_names(clause)
click to toggle source
# File lib/isodoc/xref/xref_gen_seq.rb, line 47 def sequential_formula_names(clause) c = Counter.new clause.xpath(ns(".//formula")).each do |t| next if t["id"].nil? || t["id"].empty? @anchors[t["id"]] = anchor_struct( c.increment(t).print, t, t["inequality"] ? @labels["inequality"] : @labels["formula"], "formula", t["unnumbered"] ) end end
sequential_permission_names(clause, klass, label)
click to toggle source
# File lib/isodoc/xref/xref_gen_seq.rb, line 63 def sequential_permission_names(clause, klass, label) c = Counter.new clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}")).each do |t| next if t["id"].nil? || t["id"].empty? id = c.increment(t).print @anchors[t["id"]] = anchor_struct(id, t, label, klass, t["unnumbered"]) sequential_permission_names2(t, id) end end
sequential_permission_names1(block, lbl, klass, label)
click to toggle source
# File lib/isodoc/xref/xref_gen_seq.rb, line 83 def sequential_permission_names1(block, lbl, klass, label) c = Counter.new block.xpath(ns("./#{klass}")).each do |t| next if t["id"].nil? || t["id"].empty? id = "#{lbl}#{hierfigsep}#{c.increment(t).print}" @anchors[t["id"]] = anchor_struct(id, t, label, klass, t["unnumbered"]) sequential_permission_names2(t, id) end end
sequential_permission_names2(elem, ident)
click to toggle source
# File lib/isodoc/xref/xref_gen_seq.rb, line 74 def sequential_permission_names2(elem, ident) sequential_permission_names1(elem, ident, "permission", @labels["permission"]) sequential_permission_names1(elem, ident, "requirement", @labels["requirement"]) sequential_permission_names1(elem, ident, "recommendation", @labels["recommendation"]) end
sequential_table_names(clause)
click to toggle source
# File lib/isodoc/xref/xref_gen_seq.rb, line 35 def sequential_table_names(clause) c = Counter.new clause.xpath(ns(".//table")).each do |t| next if t["id"].nil? || t["id"].empty? @anchors[t["id"]] = anchor_struct( c.increment(t).print, nil, @labels["table"], "table", t["unnumbered"] ) end end
subfigure_increment(idx, counter, elem)
click to toggle source
# File lib/isodoc/xref/xref_gen_seq.rb, line 11 def subfigure_increment(idx, counter, elem) if elem.parent.name == "figure" then idx += 1 else idx = 0 counter.increment(elem) end idx end
termexample_anchor_names(docxml)
click to toggle source
# File lib/isodoc/xref/xref_gen.rb, line 54 def termexample_anchor_names(docxml) docxml.xpath(ns("//term[descendant::termexample]")).each do |t| examples = t.xpath(ns(".//termexample")) c = Counter.new examples.each do |n| next if n["id"].nil? || n["id"].empty? c.increment(n) idx = increment_label(examples, n, c, false) @anchors[n["id"]] = { type: "termexample", label: idx, value: c.print, xref: l10n("#{anchor(t['id'], :xref)}, "\ "#{@labels['example_xref']} #{c.print}") } end end end
termnote_anchor_names(docxml)
click to toggle source
# File lib/isodoc/xref/xref_gen.rb, line 39 def termnote_anchor_names(docxml) docxml.xpath(ns("//term[descendant::termnote]")).each do |t| c = Counter.new t.xpath(ns(".//termnote")).each do |n| next if n["id"].nil? || n["id"].empty? c.increment(n) @anchors[n["id"]] = { label: termnote_label(c.print), type: "termnote", value: c.print, xref: l10n("#{anchor(t['id'], :xref)}, "\ "#{@labels['note_xref']} #{c.print}") } end end end
termnote_label(note)
click to toggle source
# File lib/isodoc/xref/xref_gen.rb, line 28 def termnote_label(note) @labels["termnote"].gsub(/%/, note.to_s) end