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

Instance Method Details

#biblio_list(f, div, bibliography) ⇒ Object



122
123
124
125
126
127
128
129
130
# File 'lib/isodoc/function/references.rb', line 122

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



160
161
162
163
164
165
166
167
168
169
170
# File 'lib/isodoc/function/references.rb', line 160

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



172
173
174
175
176
177
178
179
180
181
# File 'lib/isodoc/function/references.rb', line 172

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



28
29
30
31
32
33
34
# File 'lib/isodoc/function/references.rb', line 28

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

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
# 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)
end

#docid_prefix(prefix, docid) ⇒ Object



18
19
20
21
# File 'lib/isodoc/function/references.rb', line 18

def docid_prefix(prefix, docid)
  docid = "#{prefix} #{docid}" unless omit_docid_prefix(prefix)
  docid
end

#format_ref(ref, prefix, isopub, date, allparts) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/isodoc/function/references.rb', line 183

def format_ref(ref, prefix, isopub, date, allparts)
  if isopub
    #if date
    #on = date.at(ns("./on"))
    #ref += on&.text == "--" ? ":--" : "" # ":#{date_range(date)}"
    #ref += " (all parts)" if allparts
    # ref = docid_prefix(prefix, ref)
    #end
  end
  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



48
49
50
# File 'lib/isodoc/function/references.rb', line 48

def implicit_reference(b)
  false
end

#iso_bibitem_entry(list, b, ordinal, biblio) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/isodoc/function/references.rb', line 57

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



36
37
38
# File 'lib/isodoc/function/references.rb', line 36

def iso_bibitem_entry_attrs(b, biblio)
  { id: b["id"], class: biblio ? "Biblio" : "NormRef" }
end

#iso_bibitem_ref_code(b) ⇒ Object



11
12
13
14
15
16
# File 'lib/isodoc/function/references.rb', line 11

def iso_bibitem_ref_code(b)
  isocode = b.at(ns("./docidentifier")).text
  prefix = b&.at(ns("./docidentifier/@type"))&.text
  reference = docid_l10n(isocode)
  docid_prefix(prefix, reference)
end

#iso_title(b) ⇒ Object



40
41
42
43
44
# File 'lib/isodoc/function/references.rb', line 40

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



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/isodoc/function/references.rb', line 90

def noniso_bibitem(list, b, ordinal, bibliography)
  list.p **attr_code(iso_bibitem_entry_attrs(b, bibliography)) do |r|
    if bibliography
      id = docid_l10n(b.at(ns("./docidentifier")).text.gsub(/[\[\]]/, ""))
      prefix = b&.at(ns("./docidentifier/@type"))&.text
      ref_entry_code(r, ordinal, prefix, id)
    else
      r << "#{iso_bibitem_ref_code(b)}, "
    end
    reference_format(b, r)
  end
end

#norm_ref(isoxml, out, num) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/isodoc/function/references.rb', line 143

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



132
133
134
135
136
137
138
139
140
141
# File 'lib/isodoc/function/references.rb', line 132

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

#omit_docid_prefix(prefix) ⇒ Object



23
24
25
26
# File 'lib/isodoc/function/references.rb', line 23

def omit_docid_prefix(prefix)
  return true if prefix.nil? || prefix.empty?
  return ["ISO", "IEC"].include? prefix
end

#prefix_bracketed_ref(ref, text) ⇒ Object



52
53
54
55
# File 'lib/isodoc/function/references.rb', line 52

def prefix_bracketed_ref(ref, text)
  ref << "[#{text}]"
  insert_tab(ref, 1)
end

#ref_entry_code(r, ordinal, prefix, t) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/isodoc/function/references.rb', line 68

def ref_entry_code(r, ordinal, prefix, t)
  t = docid_prefix(prefix, t)
  if /^\d+$/.match(t) && !prefix
    prefix_bracketed_ref(r, t)
  else
    prefix_bracketed_ref(r, ordinal)
    r << "#{t}, "
  end
end

#reference_format(b, r) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/isodoc/function/references.rb', line 78

def reference_format(b, r)
  if ftitle = b.at(ns("./formattedref"))
    ftitle&.children&.each { |n| parse(n, r) }
  else
    title = b.at(ns("./title[@language = '#{@language}']")) || b.at(ns("./title"))
    r.i do |i|
      title&.children&.each { |n| parse(n, i) }
    end
  end
end

#reference_names(ref) ⇒ Object



197
198
199
200
201
202
203
204
205
206
# File 'lib/isodoc/function/references.rb', line 197

def reference_names(ref)
  isopub = ref.at(ns(ISO_PUBLISHER_XPATH))
  docid = ref.at(ns("./docidentifier"))
  prefix = ref.at(ns("./docidentifier/@type"))
  # return ref_names(ref) unless docid
  date = ref.at(ns("./date[@type = 'published']"))
  allparts = ref.at(ns("./allparts"))
  reference = format_ref(docid_l10n(docid.text), prefix&.text, isopub, date, allparts)
  @anchors[ref["id"]] = { xref: reference }
end

#split_bibitems(f) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/isodoc/function/references.rb', line 109

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