Module: BibtexHelper

Extended by:
BibtexHelper
Included in:
BibtexHelper
Defined in:
lib/middleman-bibtex.rb

Instance Method Summary collapse

Instance Method Details

#citation_entry(bib, key) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/middleman-bibtex.rb', line 26

def citation_entry(bib, key)
  unless entry = bib[key] then
    message = format('No entry for key %s', key)
    raise Middleman::Bibtex::KeyNotFound, message
  end
  entry.convert_latex.to_citeproc
end

#citation_formatted(entry, style, format) ⇒ Object



22
23
24
# File 'lib/middleman-bibtex.rb', line 22

def citation_formatted(entry, style, format)
  CiteProc.process(entry, :style => style, :format => format)
end

#citations_search(bib, search_key, author = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/middleman-bibtex.rb', line 9

def citations_search(bib, search_key, author = nil)
  entries_matching_key = bib.query(search_key)
  entries =
    if author then
      search_by_author(entries_matching_key, author)
    else
      entries_matching_key
    end
  entries
    .sort_by { |x| x.year.to_i }
    .map(&:key)
end

#search_by_author(entries, author) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/middleman-bibtex.rb', line 34

def search_by_author(entries, author)
  bib_author = BibTeX::Name.parse(author)
  entries.select do |e|
    e.respond_to?(:author) &&
      e.author &&
      e.author.include?(bib_author)
  end
end