Module: IsoDoc::Function::References
- Included in:
- Common
- Defined in:
- lib/isodoc/function/references.rb
Constant Summary collapse
- BIBLIOGRAPHY_XPATH =
"//bibliography/clause[.//references[@normative = 'false']] | "\ "//bibliography/references[@normative = 'false']".freeze
Instance Method Summary collapse
-
#bibitem_ref_code(b) ⇒ Object
returns [metanorma, non-metanorma, DOI/ISSN/ISBN] identifiers.
- #biblio_list(f, div, biblio) ⇒ Object
- #bibliography(isoxml, out) ⇒ Object
- #bibliography_parse(node, out) ⇒ Object
- #bracket_if_num(x) ⇒ Object
- #date_note_process(b, ref) ⇒ Object
-
#docid_l10n(x) ⇒ Object
This is highly specific to ISO, but it’s not a bad precedent for references anyway; keeping here instead of in IsoDoc::Iso for now.
- #docid_prefix(prefix, docid) ⇒ Object
- #format_ref(ref, prefix, isopub, date, allparts) ⇒ Object
-
#implicit_reference(b) ⇒ Object
reference not to be rendered because it is deemed implicit in the standards environment.
- #is_standard(b) ⇒ Object
- #iso_bibitem_entry_attrs(b, biblio) ⇒ Object
- #iso_title(b) ⇒ Object
-
#nonstd_bibitem(list, b, ordinal, biblio) ⇒ Object
TODO generate formatted ref if not present.
- #norm_ref(isoxml, out, num) ⇒ Object
- #omit_docid_prefix(prefix) ⇒ Object
- #pref_ref_code(b) ⇒ Object
- #prefix_bracketed_ref(ref, text) ⇒ Object
-
#ref_entry_code(r, ordinal, t, id) ⇒ Object
if t is just a number, only use that ([1] Non-Standard) else, use both ordinal, as prefix, and t.
- #reference_format(b, r) ⇒ Object
- #render_identifier(id) ⇒ Object
- #std_bibitem_entry(list, b, ordinal, biblio) ⇒ Object
Instance Method Details
#bibitem_ref_code(b) ⇒ Object
returns [metanorma, non-metanorma, DOI/ISSN/ISBN] identifiers
54 55 56 57 58 59 60 61 62 |
# File 'lib/isodoc/function/references.rb', line 54 def bibitem_ref_code(b) id = b.at(ns("./docidentifier[@type = 'metanorma']")) id1 = pref_ref_code(b) id2 = b.at(ns("./docidentifier[@type = 'DOI' or @type = 'ISSN' or @type = 'ISBN']")) return [id, id1, id2] if id || id1 || id2 id = Nokogiri::XML::Node.new("docidentifier", b.document) id << "(NO ID)" [nil, id, nil] end |
#biblio_list(f, div, biblio) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/isodoc/function/references.rb', line 142 def biblio_list(f, div, biblio) i = 0 f.children.each do |b| if b.name == "bibitem" next if implicit_reference(b) i += 1 (is_standard(b)) ? std_bibitem_entry(div, b, i, biblio) : nonstd_bibitem(div, b, i, biblio) else parse(b, div) unless %w(title).include? b.name end end end |
#bibliography(isoxml, out) ⇒ Object
170 171 172 173 174 175 176 177 |
# File 'lib/isodoc/function/references.rb', line 170 def bibliography(isoxml, out) f = isoxml.at(ns(BIBLIOGRAPHY_XPATH)) || return page_break(out) out.div do |div| div.h1 @bibliography_lbl, **{ class: "Section3" } biblio_list(f, div, true) end end |
#bibliography_parse(node, out) ⇒ Object
179 180 181 182 183 184 185 186 187 |
# File 'lib/isodoc/function/references.rb', line 179 def bibliography_parse(node, out) title = node&.at(ns("./title"))&.text || "" out.div do |div| @xrefs.anchor(node['id'], :label, false) and clause_parse_title(node, div, node.at(ns("./title")), out) or div.h2 title, **{ class: "Section3" } biblio_list(node, div, true) end end |
#bracket_if_num(x) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/isodoc/function/references.rb', line 64 def bracket_if_num(x) return nil if x.nil? x = x.text.sub(/^\[/, "").sub(/\]$/, "") return "[#{x}]" if /^\d+$/.match(x) x end |
#date_note_process(b, ref) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/isodoc/function/references.rb', line 91 def date_note_process(b, ref) date_note = b.at(ns("./note[@type = 'ISO DATE']")) return if date_note.nil? date_note.children.first.replace("<p>#{date_note.content}</p>") footnote_parse(date_note, ref) end |
#docid_l10n(x) ⇒ Object
This is highly specific to ISO, but it’s not a bad precedent for references anyway; keeping here instead of in IsoDoc::Iso for now
6 7 8 9 10 |
# File 'lib/isodoc/function/references.rb', line 6 def docid_l10n(x) return x if x.nil? x.gsub(/All Parts/i, @all_parts_lbl.downcase) if @all_parts_lbl x end |
#docid_prefix(prefix, docid) ⇒ Object
81 82 83 84 |
# File 'lib/isodoc/function/references.rb', line 81 def docid_prefix(prefix, docid) docid = "#{prefix} #{docid}" if prefix && !omit_docid_prefix(prefix) docid_l10n(docid) end |
#format_ref(ref, prefix, isopub, date, allparts) ⇒ Object
189 190 191 192 193 194 |
# File 'lib/isodoc/function/references.rb', line 189 def format_ref(ref, prefix, isopub, date, allparts) ref = docid_prefix(prefix, ref) return "[#{ref}]" if /^\d+$/.match(ref) && !prefix && !/^\[.*\]$/.match(ref) ref end |
#implicit_reference(b) ⇒ Object
reference not to be rendered because it is deemed implicit in the standards environment
112 113 114 |
# File 'lib/isodoc/function/references.rb', line 112 def implicit_reference(b) false end |
#is_standard(b) ⇒ Object
132 133 134 135 136 137 138 139 140 |
# File 'lib/isodoc/function/references.rb', line 132 def is_standard(b) ret = false b.xpath(ns("./docidentifier")).each do |id| next if id["type"].nil? || %w(metanorma DOI ISSN ISBN).include?(id["type"]) ret = true end ret end |
#iso_bibitem_entry_attrs(b, biblio) ⇒ Object
98 99 100 |
# File 'lib/isodoc/function/references.rb', line 98 def iso_bibitem_entry_attrs(b, biblio) { id: b["id"], class: biblio ? "Biblio" : "NormRef" } end |
#iso_title(b) ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/isodoc/function/references.rb', line 102 def iso_title(b) title = b.at(ns("./title[@language = '#{@lang}' and @type = 'main']")) || b.at(ns("./title[@language = '#{@lang}']")) || b.at(ns("./title[@type = 'main']")) || b.at(ns("./title")) title end |
#nonstd_bibitem(list, b, ordinal, biblio) ⇒ Object
TODO generate formatted ref if not present
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/isodoc/function/references.rb', line 13 def nonstd_bibitem(list, b, ordinal, biblio) list.p **attr_code(iso_bibitem_entry_attrs(b, biblio)) do |ref| ids = bibitem_ref_code(b) identifiers = render_identifier(ids) if biblio then ref_entry_code(ref, ordinal, identifiers, ids) else ref << "#{identifiers[0] || identifiers[1]}, " ref << "#{identifiers[1]}, " if identifiers[0] && identifiers[1] end reference_format(b, ref) end end |
#norm_ref(isoxml, out, num) ⇒ Object
156 157 158 159 160 161 162 163 164 165 |
# File 'lib/isodoc/function/references.rb', line 156 def norm_ref(isoxml, out, num) q = "//bibliography/references[@normative = 'true']" f = isoxml.at(ns(q)) or return num out.div do |div| num = num + 1 clause_name(num, @normref_lbl, div, nil) biblio_list(f, div, false) end num end |
#omit_docid_prefix(prefix) ⇒ Object
86 87 88 89 |
# File 'lib/isodoc/function/references.rb', line 86 def omit_docid_prefix(prefix) return true if prefix.nil? || prefix.empty? return %w(ISO IEC ITU W3C metanorma).include? prefix end |
#pref_ref_code(b) ⇒ Object
48 49 50 51 |
# File 'lib/isodoc/function/references.rb', line 48 def pref_ref_code(b) b.at(ns("./docidentifier[not(@type = 'DOI' or @type = 'metanorma' "\ "or @type = 'ISSN' or @type = 'ISBN' or @type = 'rfc-anchor')]")) end |
#prefix_bracketed_ref(ref, text) ⇒ Object
116 117 118 119 |
# File 'lib/isodoc/function/references.rb', line 116 def prefix_bracketed_ref(ref, text) ref << text.to_s insert_tab(ref, 1) end |
#ref_entry_code(r, ordinal, t, id) ⇒ Object
if t is just a number, only use that ([1] Non-Standard) else, use both ordinal, as prefix, and t
41 42 43 44 45 46 |
# File 'lib/isodoc/function/references.rb', line 41 def ref_entry_code(r, ordinal, t, id) prefix_bracketed_ref(r, t[0] || "[#{ordinal}]") if t[1] r << "#{t[1]}, " end end |
#reference_format(b, r) ⇒ Object
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/isodoc/function/references.rb', line 121 def reference_format(b, r) if ftitle = b.at(ns("./formattedref")) ftitle&.children&.each { |n| parse(n, r) } else title = iso_title(b) r.i do |i| title&.children&.each { |n| parse(n, i) } end end end |
#render_identifier(id) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/isodoc/function/references.rb', line 71 def render_identifier(id) [ bracket_if_num(id[0]), id[1].nil? ? nil : docid_prefix(id[1]["type"], id[1].text.sub(/^\[/, "").sub(/\]$/, "")), id[2].nil? ? nil : docid_prefix(id[2]["type"], id[2].text.sub(/^\[/, "").sub(/\]$/, "")), ] end |
#std_bibitem_entry(list, b, ordinal, biblio) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/isodoc/function/references.rb', line 26 def std_bibitem_entry(list, b, ordinal, biblio) list.p **attr_code(iso_bibitem_entry_attrs(b, biblio)) do |ref| ids = bibitem_ref_code(b) identifiers = render_identifier(ids) prefix_bracketed_ref(ref, "[#{ordinal}]") if biblio ref << "#{identifiers[0] || identifiers[1]}" ref << ", #{identifiers[1]}" if identifiers[0] && identifiers[1] date_note_process(b, ref) ref << ", " reference_format(b, ref) end end |