Module: IsoDoc::Function::References
- Included in:
- Common
- Defined in:
- lib/isodoc/function/references.rb
Constant Summary collapse
- 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
- BIBLIOGRAPHY_XPATH =
"//bibliography/clause[title = 'Bibliography'] | "\ "//bibliography/references[title = 'Bibliography']".freeze
Instance Method Summary collapse
- #biblio_list(f, div, bibliography) ⇒ Object
- #bibliography(isoxml, out) ⇒ Object
- #bibliography_parse(node, out) ⇒ Object
- #date_note_process(b, ref) ⇒ Object
- #docid_l10n(x) ⇒ Object
- #format_ref(ref, isopub, date) ⇒ Object
-
#implicit_reference(b) ⇒ Object
reference not to be rendered because it is deemed implicit in the standards environment.
- #iso_bibitem_entry(list, b, ordinal, biblio) ⇒ Object
- #iso_bibitem_entry_attrs(b, biblio) ⇒ Object
- #iso_bibitem_ref_code(b) ⇒ Object
- #iso_title(b) ⇒ Object
-
#noniso_bibitem(list, b, ordinal, bibliography) ⇒ Object
TODO generate formatted ref if not present.
- #norm_ref(isoxml, out, num) ⇒ Object
- #norm_ref_preface(f, div) ⇒ Object
- #prefix_bracketed_ref(ref, text) ⇒ Object
- #ref_entry_code(r, ordinal, t) ⇒ Object
- #reference_format(b, r) ⇒ Object
- #reference_names(ref) ⇒ Object
- #split_bibitems(f) ⇒ Object
Instance Method Details
#biblio_list(f, div, bibliography) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/isodoc/function/references.rb', line 106 def biblio_list(f, div, bibliography) bibitems = split_bibitems(f) bibitems[:iso].each_with_index do |b, i| iso_bibitem_entry(div, b, (i + 1), bibliography) end bibitems[:noniso].each_with_index do |b, i| noniso_bibitem(div, b, (i + 1 + bibitems[:iso].size), bibliography) end end |
#bibliography(isoxml, out) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/isodoc/function/references.rb', line 144 def bibliography(isoxml, out) f = isoxml.at(ns(BIBLIOGRAPHY_XPATH)) || return page_break(out) out.div do |div| div.h1 @bibliography_lbl, **{ class: "Section3" } f.elements.reject do |e| ["reference", "title", "bibitem"].include? e.name end.each { |e| parse(e, div) } biblio_list(f, div, true) end end |
#bibliography_parse(node, out) ⇒ Object
156 157 158 159 160 161 162 163 164 165 |
# File 'lib/isodoc/function/references.rb', line 156 def bibliography_parse(node, out) title = node&.at(ns("./title"))&.text || "" out.div do |div| div.h2 title, **{ class: "Section3" } node.elements.reject do |e| ["reference", "title", "bibitem"].include? e.name end.each { |e| parse(e, div) } biblio_list(node, div, true) end end |
#date_note_process(b, ref) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/isodoc/function/references.rb', line 19 def date_note_process(b, ref) date_note = b.at(ns("./note[text()][contains(.,'ISO DATE:')]")) return if date_note.nil? date_note.content = date_note.content.gsub(/ISO DATE: /, "") date_note.children.first.replace("<p>#{date_note.content}</p>") footnote_parse(date_note, ref) end |
#docid_l10n(x) ⇒ Object
4 5 6 7 |
# File 'lib/isodoc/function/references.rb', line 4 def docid_l10n(x) return x if x.nil? x.gsub(/All Parts/, @all_parts_lbl) end |
#format_ref(ref, isopub, date) ⇒ Object
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/isodoc/function/references.rb', line 167 def format_ref(ref, isopub, date) if isopub return ref unless date on = date.at(ns("./on")) return ref if on&.text == "--" return ref + ": #{date_range(date)}" end return "[#{ref}]" if /^\d+$/.match?(ref) && !/^\[.*\]$/.match?(ref) ref end |
#implicit_reference(b) ⇒ Object
reference not to be rendered because it is deemed implicit in the standards environment
39 40 41 |
# File 'lib/isodoc/function/references.rb', line 39 def implicit_reference(b) false end |
#iso_bibitem_entry(list, b, ordinal, biblio) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/isodoc/function/references.rb', line 48 def iso_bibitem_entry(list, b, ordinal, biblio) return if implicit_reference(b) list.p **attr_code(iso_bibitem_entry_attrs(b, biblio)) do |ref| prefix_bracketed_ref(ref, ordinal) if biblio ref << iso_bibitem_ref_code(b) date_note_process(b, ref) ref << ", " ref.i { |i| i << " #{iso_title(b)}" } end end |
#iso_bibitem_entry_attrs(b, biblio) ⇒ Object
27 28 29 |
# File 'lib/isodoc/function/references.rb', line 27 def iso_bibitem_entry_attrs(b, biblio) { id: b["id"], class: biblio ? "Biblio" : "NormRef" } end |
#iso_bibitem_ref_code(b) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/isodoc/function/references.rb', line 9 def iso_bibitem_ref_code(b) isocode = b.at(ns("./docidentifier")).text isodate = b.at(ns("./date[@type = 'published']")) iso_allparts = b.at(ns("./allParts")) reference = docid_l10n(isocode) reference += ": #{date_range(isodate)}" if isodate reference += " (all parts)" if iso_allparts&.text == "true" reference end |
#iso_title(b) ⇒ Object
31 32 33 34 35 |
# File 'lib/isodoc/function/references.rb', line 31 def iso_title(b) title = b.at(ns("./title[@language = '#{@language}']")) title = b.at(ns("./title")) unless title title.text end |
#noniso_bibitem(list, b, ordinal, bibliography) ⇒ Object
TODO generate formatted ref if not present
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/isodoc/function/references.rb', line 75 def noniso_bibitem(list, b, ordinal, bibliography) list.p **attr_code("id": b["id"], class: "Biblio") do |r| if bibliography id = docid_l10n(b.at(ns("./docidentifier")).text.gsub(/[\[\]]/, "")) ref_entry_code(r, ordinal, id) else r << "#{iso_bibitem_ref_code(b)}, " end reference_format(b, r) end end |
#norm_ref(isoxml, out, num) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/isodoc/function/references.rb', line 127 def norm_ref(isoxml, out, num) q = "//bibliography/references[title = 'Normative References' or "\ "title = 'Normative references']" f = isoxml.at(ns(q)) or return num out.div do |div| num = num + 1 clause_name("#{num}.", @normref_lbl, div, nil) norm_ref_preface(f, div) biblio_list(f, div, false) end num end |
#norm_ref_preface(f, div) ⇒ Object
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/isodoc/function/references.rb', line 116 def norm_ref_preface(f, div) refs = f.elements.select do |e| ["reference", "bibitem"].include? e.name end pref = if refs.empty? then @norm_empty_pref else @norm_with_refs_pref end div.p pref end |
#prefix_bracketed_ref(ref, text) ⇒ Object
43 44 45 46 |
# File 'lib/isodoc/function/references.rb', line 43 def prefix_bracketed_ref(ref, text) ref << "[#{text}]" insert_tab(ref, 1) end |
#ref_entry_code(r, ordinal, t) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/isodoc/function/references.rb', line 59 def ref_entry_code(r, ordinal, t) if /^\d+$/.match?(t) prefix_bracketed_ref(r, t) else prefix_bracketed_ref(r, ordinal) r << "#{t}, " end end |
#reference_format(b, r) ⇒ Object
68 69 70 71 72 |
# File 'lib/isodoc/function/references.rb', line 68 def reference_format(b, r) title = b.at(ns("./formattedref")) || b.at(ns("./title[@language = '#{@language}']")) || b.at(ns("./title")) title&.children&.each { |n| parse(n, r) } end |
#reference_names(ref) ⇒ Object
178 179 180 181 182 183 184 185 |
# File 'lib/isodoc/function/references.rb', line 178 def reference_names(ref) isopub = ref.at(ns(ISO_PUBLISHER_XPATH)) docid = ref.at(ns("./docidentifier")) # return ref_names(ref) unless docid date = ref.at(ns("./date[@type = 'published']")) reference = format_ref(docid_l10n(docid.text), isopub, date) @anchors[ref["id"]] = { xref: reference } end |
#split_bibitems(f) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/isodoc/function/references.rb', line 93 def split_bibitems(f) iso_bibitem = [] non_iso_bibitem = [] f.xpath(ns("./bibitem")).each do |x| if x.at(ns(ISO_PUBLISHER_XPATH)).nil? non_iso_bibitem << x else iso_bibitem << x end end { iso: iso_bibitem, noniso: non_iso_bibitem } end |