Module: IsoDoc::Function::References
- Included in:
- Common
- Defined in:
- lib/isodoc/function/references.rb
Instance Method Summary collapse
-
#bibitem_ref_code(b) ⇒ Object
returns [metanorma, non-metanorma, DOI/ISSN/ISBN] identifiers.
- #biblio_list(refs, div, biblio) ⇒ Object
- #bibliography(isoxml, out) ⇒ Object
- #bibliography_parse(node, out) ⇒ Object
- #bibliography_xpath ⇒ Object
- #bracket_if_num(num) ⇒ Object
- #date_note_process(b, ref) ⇒ Object
-
#docid_l10n(text) ⇒ 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(bib) ⇒ Object
reference not to be rendered because it is deemed implicit in the standards environment.
- #is_standard(bib) ⇒ Object
- #iso_bibitem_entry_attrs(b, biblio) ⇒ Object
- #iso_title(bib) ⇒ Object
-
#nonstd_bibitem(list, b, ordinal, biblio) ⇒ Object
TODO generate formatted ref if not present.
- #norm_ref(isoxml, out, num) ⇒ Object
- #norm_ref_xpath ⇒ 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(bib, 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 63 64 |
# 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(refs, div, biblio) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/isodoc/function/references.rb', line 155 def biblio_list(refs, div, biblio) i = 0 refs.children.each do |b| if b.name == "bibitem" next if implicit_reference(b) i += 1 if is_standard(b) then std_bibitem_entry(div, b, i, biblio) else nonstd_bibitem(div, b, i, biblio) end else parse(b, div) unless %w(title).include? b.name end end end |
#bibliography(isoxml, out) ⇒ Object
196 197 198 199 200 201 202 203 204 205 |
# File 'lib/isodoc/function/references.rb', line 196 def bibliography(isoxml, out) f = isoxml.at(ns(bibliography_xpath)) and f["hidden"] != "true" or return page_break(out) out.div do |div| div.h1 **{ class: "Section3" } do |h1| f&.at(ns("./title"))&.children&.each { |c2| parse(c2, h1) } end biblio_list(f, div, true) end end |
#bibliography_parse(node, out) ⇒ Object
207 208 209 210 211 212 213 214 |
# File 'lib/isodoc/function/references.rb', line 207 def bibliography_parse(node, out) node["hidden"] != true or return out.div do |div| clause_parse_title(node, div, node.at(ns("./title")), out, { class: "Section3" }) biblio_list(node, div, true) end end |
#bibliography_xpath ⇒ Object
190 191 192 193 194 |
# File 'lib/isodoc/function/references.rb', line 190 def bibliography_xpath "//bibliography/clause[.//references]"\ "[not(.//references[@normative = 'true'])] | "\ "//bibliography/references[@normative = 'false']" end |
#bracket_if_num(num) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/isodoc/function/references.rb', line 66 def bracket_if_num(num) return nil if num.nil? num = num.text.sub(/^\[/, "").sub(/\]$/, "") return "[#{num}]" if /^\d+$/.match?(num) num end |
#date_note_process(b, ref) ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/isodoc/function/references.rb', line 103 def date_note_process(b, ref) date_note = b.at(ns("./note[@type = 'Unpublished-Status']")) return if date_note.nil? date_note.children.first.replace("<p>#{date_note.content}</p>") footnote_parse(date_note, ref) end |
#docid_l10n(text) ⇒ 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
5 6 7 8 9 10 |
# File 'lib/isodoc/function/references.rb', line 5 def docid_l10n(text) return text if text.nil? text.gsub(/All Parts/i, @i18n.all_parts.downcase) if @i18n.all_parts text end |
#docid_prefix(prefix, docid) ⇒ Object
91 92 93 94 95 |
# File 'lib/isodoc/function/references.rb', line 91 def docid_prefix(prefix, docid) docid = "#{prefix} #{docid}" if prefix && !omit_docid_prefix(prefix) && !/^#{prefix}\b/.match(docid) docid_l10n(docid) end |
#format_ref(ref, prefix, _isopub, _date, _allparts) ⇒ Object
216 217 218 219 220 221 222 |
# File 'lib/isodoc/function/references.rb', line 216 def format_ref(ref, prefix, _isopub, _date, _allparts) ref = docid_prefix(prefix, ref) return "[#{ref}]" if ref && /^\d+$/.match(ref) && !prefix && !/^\[.*\]$/.match(ref) ref end |
#implicit_reference(bib) ⇒ Object
reference not to be rendered because it is deemed implicit in the standards environment
124 125 126 |
# File 'lib/isodoc/function/references.rb', line 124 def implicit_reference(bib) bib["hidden"] == "true" end |
#is_standard(bib) ⇒ Object
144 145 146 147 148 149 150 151 152 153 |
# File 'lib/isodoc/function/references.rb', line 144 def is_standard(bib) ret = false bib.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
111 112 113 |
# File 'lib/isodoc/function/references.rb', line 111 def iso_bibitem_entry_attrs(b, biblio) { id: b["id"], class: biblio ? "Biblio" : "NormRef" } end |
#iso_title(bib) ⇒ Object
115 116 117 118 119 120 |
# File 'lib/isodoc/function/references.rb', line 115 def iso_title(bib) bib.at(ns("./title[@language = '#{@lang}' and @type = 'main']")) || bib.at(ns("./title[@language = '#{@lang}']")) || bib.at(ns("./title[@type = 'main']")) || bib.at(ns("./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 25 |
# 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]).to_s ref << ", #{identifiers[1]}" if identifiers[0] && identifiers[1] end ref << ", " unless biblio && !identifiers[1] reference_format(b, ref) end end |
#norm_ref(isoxml, out, num) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/isodoc/function/references.rb', line 176 def norm_ref(isoxml, out, num) f = isoxml.at(ns(norm_ref_xpath)) and f["hidden"] != "true" or return num out.div do |div| num = num + 1 clause_name(num, f.at(ns("./title")), div, nil) if f.name == "clause" f.elements.each { |e| parse(e, div) unless e.name == "title" } else biblio_list(f, div, false) end end num end |
#norm_ref_xpath ⇒ Object
171 172 173 174 |
# File 'lib/isodoc/function/references.rb', line 171 def norm_ref_xpath "//bibliography/references[@normative = 'true'] | "\ "//bibliography/clause[.//references[@normative = 'true']]" end |
#omit_docid_prefix(prefix) ⇒ Object
97 98 99 100 101 |
# File 'lib/isodoc/function/references.rb', line 97 def omit_docid_prefix(prefix) return true if prefix.nil? || prefix.empty? %w(ISO IEC IEV ITU W3C csd metanorma rfc-anchor).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
128 129 130 131 |
# File 'lib/isodoc/function/references.rb', line 128 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
43 44 45 46 |
# File 'lib/isodoc/function/references.rb', line 43 def ref_entry_code(r, ordinal, t, _id) prefix_bracketed_ref(r, t[0] || "[#{ordinal}]") t[1] and r << (t[1]).to_s end |
#reference_format(bib, r) ⇒ Object
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/isodoc/function/references.rb', line 133 def reference_format(bib, r) if ftitle = bib.at(ns("./formattedref")) ftitle&.children&.each { |n| parse(n, r) } else title = iso_title(bib) r.i do |i| title&.children&.each { |n| parse(n, i) } end end end |
#render_identifier(id) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/isodoc/function/references.rb', line 75 def render_identifier(id) [ bracket_if_num(id[0]), if id[1].nil? nil else docid_prefix(id[1]["type"], id[1].text.sub(/^\[/, "").sub(/\]$/, "")) end, if id[2].nil? nil else docid_prefix(id[2]["type"], id[2].text.sub(/^\[/, "").sub(/\]$/, "")) end, ] end |
#std_bibitem_entry(list, b, ordinal, biblio) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/isodoc/function/references.rb', line 27 def std_bibitem_entry(list, b, ordinal, biblio) list.p **attr_code(iso_bibitem_entry_attrs(b, biblio)) do |ref| identifiers = render_identifier(bibitem_ref_code(b)) if biblio then ref_entry_code(ref, ordinal, identifiers, nil) else ref << (identifiers[0] || identifiers[1]).to_s ref << ", #{identifiers[1]}" if identifiers[0] && identifiers[1] end date_note_process(b, ref) ref << ", " unless biblio && !identifiers[1] reference_format(b, ref) end end |