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_lbl(clause, num) ⇒ Object
- #annex_names(clause, num) ⇒ Object
- #annex_names1(clause, num, level) ⇒ Object
- #back_anchor_names(docxml) ⇒ Object
- #clause_names(docxml, sect_num) ⇒ Object
- #initial_anchor_names(d) ⇒ Object
- #middle_section_asset_names(d) ⇒ Object
- #preface_clause_name(c) ⇒ 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
- #section_names(clause, num, lvl) ⇒ Object
- #section_names1(clause, num, level) ⇒ Object
- #single_annex_special_section(clause) ⇒ Object
Instance Method Details
#annex_name_lbl(clause, num) ⇒ Object
103 104 105 106 107 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 103 def annex_name_lbl(clause, num) obl = l10n("(#{@labels["inform_annex"]})") obl = l10n("(#{@labels["norm_annex"]})") if clause["obligation"] == "normative" l10n("<b>#{@labels["annex"]} #{num}</b><br/>#{obl}") end |
#annex_names(clause, num) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 118 def annex_names(clause, num) @anchors[clause["id"]] = { label: annex_name_lbl(clause, num), type: "clause", xref: "#{@labels["annex"]} #{num}", level: 1 } if a = single_annex_special_section(clause) annex_names1(a, "#{num}", 1) else clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i| annex_names1(c, "#{num}.#{i + 1}", 2) end end hierarchical_asset_names(clause, num) end |
#annex_names1(clause, num, level) ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 132 def annex_names1(clause, num, level) @anchors[clause["id"]] = { label: num, xref: "#{@labels["annex"]} #{num}", level: level, type: "clause" } clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i| annex_names1(c, "#{num}.#{i + 1}", level + 1) end end |
#back_anchor_names(docxml) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 3 def back_anchor_names(docxml) docxml.xpath(ns("//annex")).each_with_index do |c, i| annex_names(c, (65 + i).chr.to_s) end docxml.xpath( ns("//bibliography/clause[.//references[@normative = 'false']] | "\ "//bibliography/references[@normative = 'false']" )).each do |b| preface_names(b) end docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref| reference_names(ref) end end |
#clause_names(docxml, sect_num) ⇒ Object
74 75 76 77 78 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 74 def clause_names(docxml, sect_num) docxml.xpath(ns(@klass.middle_clause)).each_with_index do |c, i| section_names(c, (i + sect_num), 1) end end |
#initial_anchor_names(d) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 18 def initial_anchor_names(d) d.xpath(ns("//preface/*")).each { |c| c.element? and preface_names(c) } # potentially overridden in middle_section_asset_names() sequential_asset_names(d.xpath(ns("//preface/*"))) n = section_names(d.at(ns("//clause[title = 'Scope']")), 0, 1) n = section_names(d.at(ns( "//bibliography/clause[.//references[@normative = 'true']] | "\ "//bibliography/references[@normative = 'true']")), n, 1) n = section_names(d.at(ns("//sections/terms | "\ "//sections/clause[descendant::terms]")), n, 1) n = section_names(d.at(ns("//sections/definitions")), n, 1) clause_names(d, n) middle_section_asset_names(d) termnote_anchor_names(d) termexample_anchor_names(d) end |
#middle_section_asset_names(d) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 66 def middle_section_asset_names(d) middle_sections = "//clause[title = 'Scope'] | "\ "//references[@normative = 'true'] | "\ "//sections/terms | //preface/* | "\ "//sections/definitions | //clause[parent::sections]" sequential_asset_names(d.xpath(ns(middle_sections))) end |
#preface_clause_name(c) ⇒ Object
35 36 37 38 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 35 def preface_clause_name(c) ret = c.at(ns("./title"))&.text || c.name.capitalize ret end |
#preface_names(clause) ⇒ Object
in StanDoc, prefaces have no numbering; they are referenced only by title
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 44 def preface_names(clause) return if clause.nil? @anchors[clause["id"]] = { label: nil, level: 1, xref: preface_clause_name(clause), type: "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
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 55 def preface_names1(clause, title, parent_title, level) label = title || parent_title @anchors[clause["id"]] = { label: nil, level: level, xref: label, type: "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
146 147 148 149 150 151 152 153 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 146 def reference_names(ref) isopub = ref.at(ns(ISO_PUBLISHER_XPATH)) ids = @klass.bibitem_ref_code(ref) identifiers = @klass.render_identifier(ids) date = ref.at(ns("./date[@type = 'published']")) reference = @klass.docid_l10n(identifiers[0] || identifiers[1]) @anchors[ref["id"]] = { xref: reference } end |
#section_names(clause, num, lvl) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 80 def section_names(clause, num, lvl) return num if clause.nil? num = num + 1 @anchors[clause["id"]] = { label: num.to_s, xref: l10n("#{@labels["clause"]} #{num}"), level: lvl, type: "clause" } clause.xpath(ns(SUBCLAUSES)). each_with_index do |c, i| section_names1(c, "#{num}.#{i + 1}", lvl + 1) end num end |
#section_names1(clause, num, level) ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 93 def section_names1(clause, num, level) @anchors[clause["id"]] = { label: num, level: level, xref: l10n("#{@labels["clause"]} #{num}"), type: "clause" } clause.xpath(ns(SUBCLAUSES)). each_with_index do |c, i| section_names1(c, "#{num}.#{i + 1}", level + 1) end end |
#single_annex_special_section(clause) ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/isodoc/xref/xref_sect_gen.rb', line 109 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")).size == 0 or return nil a[0] end |