Module: IsoDoc::XrefGen::Sections
- Included in:
- IsoDoc::Xref
- Defined in:
- lib/isodoc/xref/xref_sect_gen.rb
Constant Summary collapse
- SUBCLAUSES =
"./clause | ./references | ./term | ./terms | ./definitions".freeze
- ISO_PUBLISHER_XPATH =
"./contributor[xmlns:role/@type = 'publisher']/"\ "organization[abbreviation = 'ISO' or xmlns:abbreviation = 'IEC' or "\ "xmlns:name = 'International Organization for Standardization' or "\ "xmlns:name = 'International Electrotechnical Commission']".freeze
Instance Method Summary collapse
- #annex_name_anchors(clause, num) ⇒ Object
- #annex_name_lbl(clause, num) ⇒ Object
- #annex_names(clause, num) ⇒ Object
- #annex_names1(clause, num, level) ⇒ Object
- #back_anchor_names(docxml) ⇒ Object
- #clause_names(docxml, num) ⇒ Object
- #initial_anchor_names(doc) ⇒ Object
- #middle_section_asset_names(doc) ⇒ Object
- #preface_clause_name(clause) ⇒ 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
- #reference_names(ref) ⇒ Object
- #references(docxml) ⇒ Object
- #section_names(clause, num, lvl) ⇒ Object
- #section_names1(clause, num, level) ⇒ Object
- #single_annex_special_section(clause) ⇒ Object
Instance Method Details
#annex_name_anchors(clause, num) ⇒ Object
124 125 126 127 128 129 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 124 def annex_name_anchors(clause, num) { label: annex_name_lbl(clause, num), elem: @labels["annex"], type: "clause", value: num.to_s, level: 1, xref: "#{@labels['annex']} #{num}" } end |
#annex_name_lbl(clause, num) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 107 def annex_name_lbl(clause, num) obl = l10n("(#{@labels['inform_annex']})") clause["obligation"] == "normative" and obl = l10n("(#{@labels['norm_annex']})") title = Common::case_with_markup(@labels["annex"], "capital", @script) l10n("<strong>#{title} #{num}</strong><br/>#{obl}") end |
#annex_names(clause, num) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 131 def annex_names(clause, num) @anchors[clause["id"]] = annex_name_anchors(clause, num) if a = single_annex_special_section(clause) annex_names1(a, num.to_s, 1) else i = Counter.new clause.xpath(ns(SUBCLAUSES)).each do |c| annex_names1(c, "#{num}.#{i.increment(c).print}", 2) end end hierarchical_asset_names(clause, num) end |
#annex_names1(clause, num, level) ⇒ Object
144 145 146 147 148 149 150 151 152 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 144 def annex_names1(clause, num, level) @anchors[clause["id"]] = { xref: "#{@labels['annex']} #{num}", elem: @labels["annex"], label: num, level: level, type: "clause" } i = Counter.new clause.xpath(ns(SUBCLAUSES)).each do |c| annex_names1(c, "#{num}.#{i.increment(c).print}", level + 1) end end |
#back_anchor_names(docxml) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 4 def back_anchor_names(docxml) i = Counter.new("@") docxml.xpath(ns("//annex")).each do |c| annex_names(c, i.increment(c).print) end docxml.xpath(ns(@klass.bibliography_xpath)).each do |b| preface_names(b) end references(docxml) end |
#clause_names(docxml, num) ⇒ Object
77 78 79 80 81 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 77 def clause_names(docxml, num) docxml.xpath(ns(@klass.middle_clause(docxml))).each_with_index do |c, _i| section_names(c, num, 1) end end |
#initial_anchor_names(doc) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 21 def initial_anchor_names(doc) doc.xpath(ns("//preface/*")).each do |c| c.element? and preface_names(c) end # potentially overridden in middle_section_asset_names() sequential_asset_names(doc.xpath(ns("//preface/*"))) n = Counter.new n = section_names(doc.at(ns("//clause[@type = 'scope']")), n, 1) n = section_names(doc.at(ns(@klass.norm_ref_xpath)), n, 1) n = section_names(doc.at(ns("//sections/terms | "\ "//sections/clause[descendant::terms]")), n, 1) n = section_names(doc.at(ns("//sections/definitions")), n, 1) clause_names(doc, n) middle_section_asset_names(doc) termnote_anchor_names(doc) termexample_anchor_names(doc) end |
#middle_section_asset_names(doc) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 69 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_clause_name(clause) ⇒ Object
39 40 41 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 39 def preface_clause_name(clause) clause.at(ns("./title"))&.text || clause.name.capitalize end |
#preface_names(clause) ⇒ Object
in StanDoc, prefaces have no numbering; they are referenced only by title
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 47 def preface_names(clause) return if clause.nil? @anchors[clause["id"]] = { label: nil, level: 1, xref: preface_clause_name(clause), type: "clause", elem: @labels["clause"] } clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i| preface_names1(c, c.at(ns("./title"))&.text, "#{preface_clause_name(clause)}, #{i + 1}", 2) end end |
#preface_names1(clause, title, parent_title, level) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 59 def preface_names1(clause, title, parent_title, level) label = title || parent_title @anchors[clause["id"]] = { label: nil, level: level, xref: label, type: "clause", elem: @labels["clause"] } clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i| preface_names1(c, c.at(ns("./title"))&.text, "#{label} #{i + 1}", level + 1) end end |
#reference_names(ref) ⇒ Object
160 161 162 163 164 165 166 167 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 160 def reference_names(ref) ids = @klass.bibitem_ref_code(ref) identifiers = @klass.render_identifier(ids) reference = @klass .docid_l10n(identifiers[:metanorma] || identifiers[:sdo] || identifiers[:ordinal] || identifiers[:doi]) @anchors[ref["id"]] = { xref: reference } end |
#references(docxml) ⇒ Object
15 16 17 18 19 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 15 def references(docxml) docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref| reference_names(ref) end end |
#section_names(clause, num, lvl) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 83 def section_names(clause, num, lvl) return num if clause.nil? num.increment(clause) @anchors[clause["id"]] = { label: num.print, xref: l10n("#{@labels['clause']} #{num.print}"), level: lvl, type: "clause", elem: @labels["clause"] } i = Counter.new clause.xpath(ns(SUBCLAUSES)).each do |c| section_names1(c, "#{num.print}.#{i.increment(c).print}", lvl + 1) end num end |
#section_names1(clause, num, level) ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 97 def section_names1(clause, num, level) @anchors[clause["id"]] = { label: num, level: level, xref: l10n("#{@labels['clause']} #{num}"), type: "clause", elem: @labels["clause"] } i = Counter.new clause.xpath(ns(SUBCLAUSES)).each do |c| section_names1(c, "#{num}.#{i.increment(c).print}", level + 1) end end |
#single_annex_special_section(clause) ⇒ Object
115 116 117 118 119 120 121 122 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 115 def single_annex_special_section(clause) a = clause.xpath(ns("./references | ./terms | ./definitions")) a.size == 1 or return nil clause.xpath(ns("./clause | ./p | ./table | ./ol | ./ul | ./dl | "\ "./note | ./admonition | ./figure")).empty? or return nil a[0] end |