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, level) ⇒ Object
- #annex_name_lbl(clause, num) ⇒ Object
- #annex_names(clause, num) ⇒ Object
- #annex_names1(clause, num, level) ⇒ Object
-
#asset_anchor_names(doc) ⇒ Object
preempt clause notes with all other types of note (ISO default).
- #back_anchor_names(xml) ⇒ Object
- #clause_names(docxml, num) ⇒ Object
- #clause_title(clause, use_elem_name: false) ⇒ Object
- #initial_anchor_names(doc) ⇒ Object
- #middle_section_asset_names(doc) ⇒ 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
- #reference_names(ref) ⇒ Object
- #references(docxml) ⇒ Object
- #section_name_anchors(clause, num, level) ⇒ Object
- #section_names(clause, num, lvl) ⇒ Object
- #section_names1(clause, num, level) ⇒ Object
Instance Method Details
#annex_name_anchors(clause, num, level) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 145 def annex_name_anchors(clause, num, level) label = num level == 1 && clause.name == "annex" and label = annex_name_lbl(clause, num) @anchors[clause["id"]] = { label: label, elem: @labels["annex"], type: "clause", subtype: "annex", value: num.to_s, level: level, title: clause_title(clause), xref: "#{@labels['annex']} #{num}" } end |
#annex_name_lbl(clause, num) ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 137 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
157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 157 def annex_names(clause, num) annex_name_anchors(clause, num, 1) if @klass.single_term_clause?(clause) annex_names1(clause.at(ns("./references | ./terms | ./definitions")), num.to_s, 1) else clause.xpath(ns(SUBCLAUSES)).each_with_object(Counter.new) do |c, i| annex_names1(c, "#{num}.#{i.increment(c).print}", 2) end end hierarchical_asset_names(clause, num) end |
#annex_names1(clause, num, level) ⇒ Object
170 171 172 173 174 175 176 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 170 def annex_names1(clause, num, level) annex_name_anchors(clause, num, level) i = Counter.new clause.xpath(ns(SUBCLAUSES)).each do |c| annex_names1(c, "#{num}.#{i.increment(c).print}", level + 1) end end |
#asset_anchor_names(doc) ⇒ Object
preempt clause notes with all other types of note (ISO default)
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 42 def asset_anchor_names(doc) @parse_settings.empty? or return middle_section_asset_names(doc) termnote_anchor_names(doc) termexample_anchor_names(doc) note_anchor_names(doc.xpath(ns("//table | //figure"))) note_anchor_names(doc.xpath(ns(sections_xpath))) admonition_anchor_names(doc.xpath(ns(sections_xpath))) example_anchor_names(doc.xpath(ns(sections_xpath))) list_anchor_names(doc.xpath(ns(sections_xpath))) deflist_anchor_names(doc.xpath(ns(sections_xpath))) bookmark_anchor_names(doc) end |
#back_anchor_names(xml) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 4 def back_anchor_names(xml) if @parse_settings.empty? || @parse_settings[:clauses] i = Counter.new("@") xml.xpath(ns("//annex")).each do |c| annex_names(c, i.increment(c).print) end xml.xpath(ns(@klass.bibliography_xpath)).each do |b| preface_names(b) end xml.xpath(ns("//colophon/clause")).each { |b| preface_names(b) } end references(xml) if @parse_settings.empty? || @parse_settings[:refs] end |
#clause_names(docxml, num) ⇒ Object
104 105 106 107 108 109 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 104 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 |
#clause_title(clause, use_elem_name: false) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 56 def clause_title(clause, use_elem_name: false) ret = clause.at(ns("./title"))&.text if use_elem_name && !ret clause.name.capitalize else ret end end |
#initial_anchor_names(doc) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 24 def initial_anchor_names(doc) if @parse_settings.empty? || @parse_settings[:clauses] 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) end end |
#middle_section_asset_names(doc) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 96 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_name_anchors(clause, level, title) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 89 def preface_name_anchors(clause, level, title) @anchors[clause["id"]] = { label: nil, level: level, xref: title, title: nil, type: "clause", elem: @labels["clause"] } end |
#preface_names(clause) ⇒ Object
in StanDoc, prefaces have no numbering; they are referenced only by title
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 69 def preface_names(clause) return if clause.nil? preface_name_anchors(clause, 1, clause_title(clause, use_elem_name: true)) clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i| preface_names1(c, c.at(ns("./title"))&.text, "#{clause_title(clause)}, #{i + 1}", 2) end end |
#preface_names1(clause, title, parent_title, level) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 80 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| preface_names1(c, c.at(ns("./title"))&.text, "#{label} #{i + 1}", level + 1) end end |
#reference_names(ref) ⇒ Object
184 185 186 187 188 189 190 191 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 184 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
18 19 20 21 22 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 18 def references(docxml) docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref| reference_names(ref) end end |
#section_name_anchors(clause, num, level) ⇒ Object
130 131 132 133 134 135 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 130 def section_name_anchors(clause, num, level) @anchors[clause["id"]] = { label: num, xref: l10n("#{@labels['clause']} #{num}"), title: clause_title(clause), level: level, type: "clause", elem: @labels["clause"] } end |
#section_names(clause, num, lvl) ⇒ Object
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 111 def section_names(clause, num, lvl) clause.nil? and return num num.increment(clause) section_name_anchors(clause, num.print, lvl) clause.xpath(ns(SUBCLAUSES)).each_with_object(Counter.new) do |c, i| section_names1(c, "#{num.print}.#{i.increment(c).print}", lvl + 1) end num end |
#section_names1(clause, num, level) ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 122 def section_names1(clause, num, level) section_name_anchors(clause, num, level) i = Counter.new clause.xpath(ns(SUBCLAUSES)).each do |c| section_names1(c, "#{num}.#{i.increment(c).print}", level + 1) end end |