Module: IsoDoc::XrefGen::Sections
- Included in:
- IsoDoc::Xref
- Defined in:
- lib/isodoc/xref/clause_order.rb,
lib/isodoc/xref/xref_sect_gen.rb
Constant Summary collapse
- SUBCLAUSES =
"./clause | ./references | ./term | ./terms | ./definitions".freeze
Instance Method Summary collapse
- #annex_anchor_names(xml) ⇒ Object
- #annex_name_anchors(clause, num, level) ⇒ Object
-
#annex_name_anchors1(clause, num, level) ⇒ Object
subclauses of Annexes.
- #annex_name_lbl(clause, num) ⇒ Object
- #annex_names(clause, num) ⇒ Object
- #annex_names1(clause, parentnum, num, level) ⇒ Object
-
#asset_anchor_names(doc) ⇒ Object
preempt clause notes with all other types of note (ISO default).
- #back_anchor_names(xml) ⇒ Object
- #back_clauses_anchor_names(xml) ⇒ Object
- #back_names(clause) ⇒ Object
- #clause_number_semx(parentnum, clause, num) ⇒ Object
- #clause_order(docxml) ⇒ Object
- #clause_order_annex(_docxml) ⇒ Object
- #clause_order_back(_docxml) ⇒ Object
- #clause_order_main(docxml) ⇒ Object
- #clause_order_preface(_docxml) ⇒ Object
- #clause_title(clause, use_elem_name: false) ⇒ Object
- #clausesep ⇒ Object
-
#initial_anchor_names(xml) ⇒ Object
NOTE: references processing has moved to Presentation XML.
- #main_anchor_names(xml) ⇒ Object
- #middle_section_asset_names(doc) ⇒ Object
- #preface_anchor_names(xml) ⇒ Object
- #preface_name_anchors(clause, level, title) ⇒ Object
-
#preface_names(clause) ⇒ Object
in StanDoc, prefaces have no numbering; they are referenced only by title.
- #preface_names1(clause, title, parent_title, level) ⇒ Object
- #section_name_anchors(clause, num, level) ⇒ Object
- #section_names(clause, num, lvl) ⇒ Object
- #section_names1(clause, parentnum, num, level) ⇒ Object
- #unnumbered_names(clause) ⇒ Object
- #unnumbered_section_name?(clause) ⇒ Boolean
Instance Method Details
#annex_anchor_names(xml) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 13 def annex_anchor_names(xml) i = Counter.new("@") clause_order_annex(xml).each do |a| xml.xpath(ns(a[:path])).each do |c| unnumbered_section_name?(c) and next annex_names(c, i.increment(c).print) a[:multi] or break end end end |
#annex_name_anchors(clause, num, level) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 206 def annex_name_anchors(clause, num, level) label = num level == 1 && clause.name == "annex" and label = annex_name_lbl(clause, label) xref = labelled_autonum(@labels["annex"], num) c = clause_title(clause) and title = semx(clause, c, "title") @anchors[clause["id"]] = { label:, xref:, title:, elem: @labels["annex"], type: "clause", subtype: "annex", value: num.to_s, level: } end |
#annex_name_anchors1(clause, num, level) ⇒ Object
subclauses of Annexes
243 244 245 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 243 def annex_name_anchors1(clause, num, level) annex_name_anchors(clause, num, level) end |
#annex_name_lbl(clause, num) ⇒ Object
195 196 197 198 199 200 201 202 203 204 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 195 def annex_name_lbl(clause, num) obl = "(#{@labels['inform_annex']})" clause["obligation"] == "normative" and obl = "(#{@labels['norm_annex']})" obl = "<span class='fmt-obligation'>#{l10n obl}</fmt>" title = Common::case_with_markup(@labels["annex"], "capital", @script) s = labelled_autonum(title, num) "<strong><span class='fmt-caption-label'>#{s}</span></strong><br/>#{obl}" end |
#annex_names(clause, num) ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 218 def annex_names(clause, num) label = semx(clause, num) annex_name_anchors(clause, label, 1) if @klass.single_term_clause?(clause) annex_names1(clause.at(ns("./references | ./terms | ./definitions")), nil, num.to_s, 1) else clause.xpath(ns(SUBCLAUSES)) .each_with_object(clause_counter(0)) do |c, i| annex_names1(c, label, i.increment(c).print, 2) end end hierarchical_asset_names(clause, label) end |
#annex_names1(clause, parentnum, num, level) ⇒ Object
233 234 235 236 237 238 239 240 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 233 def annex_names1(clause, parentnum, num, level) lbl = clause_number_semx(parentnum, clause, num) annex_name_anchors1(clause, lbl, level) i = clause_counter(0) clause.xpath(ns(SUBCLAUSES)).each do |c| annex_names1(c, lbl, i.increment(c).print, level + 1) end end |
#asset_anchor_names(doc) ⇒ Object
preempt clause notes with all other types of note (ISO default)
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 62 def asset_anchor_names(doc) (@parse_settings.empty? || @parse_settings[:assets]) or return middle_section_asset_names(doc) termnote_anchor_names(doc) termexample_anchor_names(doc) note_anchor_names(doc.xpath(ns("//table | //figure"))) sections = doc.xpath(ns(sections_xpath)) note_anchor_names(sections) admonition_anchor_names(sections) example_anchor_names(sections) list_anchor_names(sections) deflist_anchor_names(sections) bookmark_anchor_names(doc) end |
#back_anchor_names(xml) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 6 def back_anchor_names(xml) if @parse_settings.empty? || @parse_settings[:clauses] annex_anchor_names(xml) back_clauses_anchor_names(xml) end end |
#back_clauses_anchor_names(xml) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 24 def back_clauses_anchor_names(xml) clause_order_back(xml).each do |a| xml.xpath(ns(a[:path])).each do |c| back_names(c) a[:multi] or break end end end |
#back_names(clause) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 94 def back_names(clause) unnumbered_names(clause) sequential_asset_names( Nokogiri::XML::NodeSet.new(clause.document, [clause]), container: true, ) end |
#clause_number_semx(parentnum, clause, num) ⇒ Object
153 154 155 156 157 158 159 160 161 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 153 def clause_number_semx(parentnum, clause, num) if clause["branch-number"] semx(clause, clause["branch-number"]) elsif parentnum.nil? semx(clause, num) else "#{parentnum}#{delim_wrap(clausesep)}#{semx(clause, num)}" end end |
#clause_order(docxml) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/isodoc/xref/clause_order.rb', line 4 def clause_order(docxml) { preface: clause_order_preface(docxml), main: clause_order_main(docxml), annex: clause_order_annex(docxml), back: clause_order_back(docxml) } end |
#clause_order_annex(_docxml) ⇒ Object
28 29 30 |
# File 'lib/isodoc/xref/clause_order.rb', line 28 def clause_order_annex(_docxml) [{ path: "//annex", multi: true }] end |
#clause_order_back(_docxml) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/isodoc/xref/clause_order.rb', line 32 def clause_order_back(_docxml) [ { path: @klass.bibliography_xpath }, { path: "//indexsect", multi: true }, { path: "//colophon/*", multi: true }, ] end |
#clause_order_main(docxml) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/isodoc/xref/clause_order.rb', line 15 def clause_order_main(docxml) [ { path: "//sections/clause[@type = 'scope']" }, { path: @klass.norm_ref_xpath }, { path: "//sections/terms | " \ "//sections/clause[descendant::terms]", multi: true }, { path: "//sections/definitions | " \ "//sections/clause[descendant::definitions]" \ "[not(descendant::terms)]", multi: true }, { path: @klass.middle_clause(docxml), multi: true }, ] end |
#clause_order_preface(_docxml) ⇒ Object
11 12 13 |
# File 'lib/isodoc/xref/clause_order.rb', line 11 def clause_order_preface(_docxml) [{ path: "//preface/*", multi: true }] end |
#clause_title(clause, use_elem_name: false) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 77 def clause_title(clause, use_elem_name: false) ret = clause.at(ns("./title"))&.text if use_elem_name && ret.blank? @i18n.labels[clause.name]&.capitalize || clause.name.capitalize else ret end end |
#clausesep ⇒ Object
182 183 184 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 182 def clausesep "." end |
#initial_anchor_names(xml) ⇒ Object
NOTE: references processing has moved to Presentation XML
35 36 37 38 39 40 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 35 def initial_anchor_names(xml) if @parse_settings.empty? || @parse_settings[:clauses] preface_anchor_names(xml) main_anchor_names(xml) end end |
#main_anchor_names(xml) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 51 def main_anchor_names(xml) n = clause_counter clause_order_main(xml).each do |a| xml.xpath(ns(a[:path])).each do |c| section_names(c, n, 1) a[:multi] or break end end end |
#middle_section_asset_names(doc) ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 133 def middle_section_asset_names(doc) middle_sections = "//clause[@type = 'scope'] | #{@klass.norm_ref_xpath} | " \ "//sections/terms | //preface/* | " \ "//sections/definitions | //clause[parent::sections]" sequential_asset_names(doc.xpath(ns(middle_sections))) end |
#preface_anchor_names(xml) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 42 def preface_anchor_names(xml) clause_order_preface(xml).each do |a| xml.xpath(ns(a[:path])).each do |c| preface_names(c) a[:multi] or break end end end |
#preface_name_anchors(clause, level, title) ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 125 def preface_name_anchors(clause, level, title) xref = semx(clause, title, clause.name) @anchors[clause["id"]] = { label: nil, level:, xref:, title: nil, type: "clause", elem: @labels["clause"] } end |
#preface_names(clause) ⇒ Object
in StanDoc, prefaces have no numbering; they are referenced only by title
90 91 92 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 90 def preface_names(clause) unnumbered_names(clause) end |
#preface_names1(clause, title, parent_title, level) ⇒ Object
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 114 def preface_names1(clause, title, parent_title, level) label = title || parent_title preface_name_anchors(clause, level, title || parent_title) clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i| t = c.at(ns("./title")) preface_names1(c, t ? semx(c, t.text, c.name) : nil, "#{label} #{semx(c, i + 1)}", level + 1) end end |
#section_name_anchors(clause, num, level) ⇒ Object
186 187 188 189 190 191 192 193 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 186 def section_name_anchors(clause, num, level) xref = labelled_autonum(@labels["clause"], num) label = num c = clause_title(clause) and title = semx(clause, c, "title") @anchors[clause["id"]] = { label:, xref:, title:, level:, type: "clause", elem: @labels["clause"] } end |
#section_names(clause, num, lvl) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 141 def section_names(clause, num, lvl) unnumbered_section_name?(clause) and return num num.increment(clause) lbl = semx(clause, num.print) section_name_anchors(clause, lbl, lvl) clause.xpath(ns(SUBCLAUSES)) .each_with_object(clause_counter(0)) do |c, i| section_names1(c, lbl, i.increment(c).print, lvl + 1) end num end |
#section_names1(clause, parentnum, num, level) ⇒ Object
163 164 165 166 167 168 169 170 171 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 163 def section_names1(clause, parentnum, num, level) unnumbered_section_name?(clause) and return num lbl = clause_number_semx(parentnum, clause, num) section_name_anchors(clause, lbl, level) i = clause_counter(0) clause.xpath(ns(SUBCLAUSES)).each do |c| section_names1(c, lbl, i.increment(c).print, level + 1) end end |
#unnumbered_names(clause) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 102 def unnumbered_names(clause) clause.nil? and return title = clause_title(clause, use_elem_name: true) preface_name_anchors(clause, 1, title) clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i| t = c.at(ns("./title")) tt = "#{semx(clause, title, clause.name)}" \ "<span class='fmt-comma'>,</span> #{semx(c, i + 1)}" preface_names1(c, t ? semx(c, t.text, c.name) : nil, tt, 2) end end |
#unnumbered_section_name?(clause) ⇒ Boolean
173 174 175 176 177 178 179 180 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 173 def unnumbered_section_name?(clause) clause.nil? and return true if clause["unnumbered"] == "true" unnumbered_names(clause) return true end false end |