Skip to content

Commit

Permalink
bibliography rendering refactor; #114
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Aug 18, 2019
1 parent 60ed06b commit 3560330
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 37 deletions.
49 changes: 13 additions & 36 deletions lib/isodoc/function/references.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def docid_l10n(x)
def nonstd_bibitem(list, b, ordinal, bibliography)
list.p **attr_code(iso_bibitem_entry_attrs(b, bibliography)) do |r|
id = bibitem_ref_code(b)
require "byebug"; byebug
if bibliography
ref_entry_code(r, ordinal, id)
else
Expand All @@ -24,7 +23,6 @@ def nonstd_bibitem(list, b, ordinal, bibliography)


def std_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 << bibitem_ref_code(b)
Expand All @@ -46,9 +44,10 @@ def ref_entry_code(r, ordinal, t)
end

def bibitem_ref_code(b)
isocode = b.at(ns("./docidentifier")).text.sub(/^\[/, "").sub(/\]$/, "")
prefix = b&.at(ns("./docidentifier/@type"))&.text
docid_prefix(prefix, isocode)
id = b.at(ns("./docidentifier[not(@type = 'DOI' or @type = 'metanorma')]"))
id ||= b.at(ns("./docidentifier[not(@type = 'DOI')]"))
id ||= b.at(ns("./docidentifier")) or return "(NO ID)"
docid_prefix(id["type"], id.text.sub(/^\[/, "").sub(/\]$/, ""))
end

def docid_prefix(prefix, docid)
Expand All @@ -58,7 +57,7 @@ def docid_prefix(prefix, docid)

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

def date_note_process(b, ref)
Expand Down Expand Up @@ -109,37 +108,18 @@ def reference_format(b, r)
"xmlns:name = 'International Organization for Standardization' or "\
"xmlns:name = 'International Electrotechnical Commission']".freeze

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

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

def is_standard(b)
code = b.at(ns("./docidentifier")).text.sub(/^\[/, "").sub(/\]$/, "")
prefix = b&.at(ns("./docidentifier/@type"))&.text
!(prefix.nil? && /^\[?\d+\]?$/.match(code))
ret = false
b.xpath(ns("./docidentifier")).each do |id|
next if id["type"].nil? || %w(metanorma DOI).include?(id["type"])
ret = true
end
ret
end

def biblio_list(f, div, bibliography)
f.xpath(ns("./bibitem")).each_with_index do |b, i|
next if implicit_reference(b)
if(is_standard(b))
std_bibitem_entry(div, b, i + 1, bibliography)
else
Expand All @@ -152,10 +132,7 @@ 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
pref = refs.empty? ? @norm_empty_pref : @norm_with_refs_pref
div.p pref
end

Expand Down
2 changes: 1 addition & 1 deletion spec/isodoc/ref_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
</bibitem>
<bibitem id="ref10">
<formattedref format="application/x-isodoc+xml"><smallcap>Standard No I.C.C 167</smallcap>. <em>Determination of the protein content in cereal and cereal products for food and animal feeding stuffs according to the Dumas combustion method</em> (see <link target="http://www.icc.or.at"/>)</formattedref>
<docidentifier>[10]</docidentifier>
<docidentifier type="metanorma">[10]</docidentifier>
</bibitem>
<bibitem id="ref11">
<title>Internet Calendaring and Scheduling Core Object Specification (iCalendar)</title>
Expand Down

0 comments on commit 3560330

Please sign in to comment.