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
- SECTIONS_XPATH =
"//foreword | //introduction | //acknowledgements | //preface/clause | "\ "//preface/terms | preface/definitions | preface/references | "\ "//sections/terms | //annex | "\ "//sections/clause | //sections/definitions | "\ "//bibliography/references | //bibliography/clause".freeze
- CHILD_NOTES_XPATH =
"./*[not(self::xmlns:clause) and not(self::xmlns:appendix) and "\ "not(self::xmlns:terms) and not(self::xmlns:definitions)]//xmlns:note | "\ "./xmlns:note".freeze
- CHILD_EXAMPLES_XPATH =
"./*[not(self::xmlns:clause) and not(self::xmlns:appendix) and "\ "not(self::xmlns:terms) and not(self::xmlns:definitions)]//"\ "xmlns:example | ./xmlns:example".freeze
- CHILD_SECTIONS =
"./clause | ./appendix | ./terms | ./definitions | ./references"
- FIRST_LVL_REQ =
"[not(ancestor::permission or ancestor::requirement or "\ "ancestor::recommendation)]".freeze
Instance Method Summary collapse
- #amend_autonums(a) ⇒ Object
- #amend_preprocess(xmldoc) ⇒ Object
- #example_anchor_names(sections) ⇒ Object
- #hierarchical_asset_names(clause, num) ⇒ Object
- #hierarchical_figure_names(clause, num) ⇒ Object
- #hierarchical_formula_names(clause, num) ⇒ Object
- #hierarchical_permission_names(clause, num, klass, label) ⇒ Object
- #hierarchical_permission_names1(block, lbl, klass, label) ⇒ Object
- #hierarchical_permission_names2(t, id) ⇒ Object
- #hierarchical_table_names(clause, num) ⇒ Object
- #hierfigsep ⇒ Object
- #hiersep ⇒ Object
- #list_anchor_names(sections) ⇒ Object
- #list_item_anchor_names(list, list_anchor, depth, prev_label, refer_list) ⇒ Object
- #note_anchor_names(sections) ⇒ Object
- #sequential_asset_names(clause) ⇒ Object
- #sequential_figure_names(clause) ⇒ Object
- #sequential_formula_names(clause) ⇒ Object
- #sequential_permission_names(clause, klass, label) ⇒ Object
- #sequential_permission_names1(block, lbl, klass, label) ⇒ Object
- #sequential_permission_names2(t, id) ⇒ Object
- #sequential_table_names(clause) ⇒ Object
- #subfigure_increment(j, c, t) ⇒ Object
- #termexample_anchor_names(docxml) ⇒ Object
- #termnote_anchor_names(docxml) ⇒ Object
- #termnote_label(n) ⇒ Object
Instance Method Details
#amend_autonums(a) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/isodoc/xref/xref_gen.rb', line 20 def amend_autonums(a) autonum = {} a.xpath(ns("./autonumber")).each do |n| autonum[n["type"]] = n.text end autonum end |
#amend_preprocess(xmldoc) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# 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] and i == 0 and e["number"] = autonum[b] !autonum[b] and e["unnumbered"] = "true" end end end end |
#example_anchor_names(sections) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/isodoc/xref/xref_gen.rb', line 95 def example_anchor_names(sections) sections.each do |s| notes = s.xpath(CHILD_EXAMPLES_XPATH) c = Counter.new notes.each do |n| next if @anchors[n["id"]] next if n["id"].nil? || n["id"].empty? idx = notes.size == 1 && !n["number"] ? "" : " #{c.increment(n).print}" @anchors[n["id"]] = anchor_struct(idx, n, @labels["example_xref"], "example", n["unnumbered"]) end example_anchor_names(s.xpath(ns(CHILD_SECTIONS))) end end |
#hierarchical_asset_names(clause, num) ⇒ Object
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 115 def hierarchical_asset_names(clause, num) hierarchical_table_names(clause, num) hierarchical_figure_names(clause, num) hierarchical_formula_names(clause, num) (clause, num, "permission", @labels["permission"]) (clause, num, "requirement", @labels["requirement"]) (clause, num, "recommendation", @labels["recommendation"]) end |
#hierarchical_figure_names(clause, num) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 91 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) ⇒ Object
126 127 128 129 130 131 132 133 134 135 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 126 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) ⇒ Object
137 138 139 140 141 142 143 144 145 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 137 def (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"]) (t, id) end end |
#hierarchical_permission_names1(block, lbl, klass, label) ⇒ Object
153 154 155 156 157 158 159 160 161 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 153 def (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"]) (t, id) end end |
#hierarchical_permission_names2(t, id) ⇒ Object
147 148 149 150 151 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 147 def (t, id) (t, id, "permission", @labels["permission"]) (t, id, "requirement", @labels["requirement"]) (t, id, "recommendation", @labels["recommendation"]) end |
#hierarchical_table_names(clause, num) ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 105 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 ⇒ Object
7 8 9 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 7 def hierfigsep "-" end |
#hiersep ⇒ Object
3 4 5 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 3 def hiersep "." end |
#list_anchor_names(sections) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/isodoc/xref/xref_gen.rb', line 110 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? idx = notes.size == 1 && !n["number"] ? "" : " #{c.increment(n).print}" @anchors[n["id"]] = anchor_struct(idx, 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) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/isodoc/xref/xref_gen.rb', line 125 def list_item_anchor_names(list, list_anchor, depth, prev_label, refer_list) c = Counter.new list.xpath(ns("./li")).each do |li| label = c.increment(li).listlabel(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) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/isodoc/xref/xref_gen.rb', line 74 def note_anchor_names(sections) sections.each do |s| notes = s.xpath(CHILD_NOTES_XPATH) c = Counter.new notes.each do |n| next if @anchors[n["id"]] || n["id"].nil? || n["id"].empty? idx = notes.size == 1 && !n["number"] ? "" : " #{c.increment(n).print}" @anchors[n["id"]] = anchor_struct(idx, n, @labels["note_xref"], "note", false) end note_anchor_names(s.xpath(ns(CHILD_SECTIONS))) end end |
#sequential_asset_names(clause) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 82 def sequential_asset_names(clause) sequential_table_names(clause) sequential_figure_names(clause) sequential_formula_names(clause) (clause, "permission", @labels["permission"]) (clause, "requirement", @labels["requirement"]) (clause, "recommendation", @labels["recommendation"]) end |
#sequential_figure_names(clause) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# 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) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 42 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) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 56 def (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"]) (t, id) end end |
#sequential_permission_names1(block, lbl, klass, label) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 72 def (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"]) (t, id) end end |
#sequential_permission_names2(t, id) ⇒ Object
66 67 68 69 70 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 66 def (t, id) (t, id, "permission", @labels["permission"]) (t, id, "requirement", @labels["requirement"]) (t, id, "recommendation", @labels["recommendation"]) end |
#sequential_table_names(clause) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 33 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(j, c, t) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/isodoc/xref/xref_gen_seq.rb', line 11 def subfigure_increment(j, c, t) if t.parent.name == "figure" then j += 1 else j = 0 c.increment(t) end j end |
#termexample_anchor_names(docxml) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/isodoc/xref/xref_gen.rb', line 46 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| return if n["id"].nil? || n["id"].empty? c.increment(n) idx = examples.size == 1 && !n["number"] ? "" : c.print @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) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/isodoc/xref/xref_gen.rb', line 32 def termnote_anchor_names(docxml) docxml.xpath(ns("//term[descendant::termnote]")).each do |t| c = Counter.new t.xpath(ns(".//termnote")).each do |n| return 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(n) ⇒ Object
28 29 30 |
# File 'lib/isodoc/xref/xref_gen.rb', line 28 def termnote_label(n) @labels["termnote"].gsub(/%/, n.to_s) end |