class BibtexDataSource

Public Instance Methods

extract_attributes(entry) click to toggle source
# File lib/nanoc/data_sources/bibtex_data_source.rb, line 39
def extract_attributes entry
  entry = entry.convert(:latex) { |key| key != :url }
  attributes = {
    :bibtex => entry,
    :key    => entry.key,
    :type   => entry.type,
  }
  entry.each { |key, value| attributes[key] = value }
  attributes
end
items() click to toggle source
# File lib/nanoc/data_sources/bibtex_data_source.rb, line 12
def items
  @files.map do |file|
    stat = File.stat file
    file_checksum = stat.size.to_s + '-' + stat.mtime.to_i.to_s
    entries = BibTeX.open(file)
    entries.map do |entry|
      new_item lambda { to_bibtex entry }, lambda { extract_attributes entry },
               '/' + entry.key, checksum_data: file_checksum
    end
  end.flatten!
end
to_bibtex(entry) click to toggle source
# File lib/nanoc/data_sources/bibtex_data_source.rb, line 24
def to_bibtex entry
  contents = ["@#{entry.type}{#{entry.key},"]
  entry.each do |key, value|
    unless @exclude[key.to_s]
      if value =~ /^\d+$/ or (key == :month and value =~ /^[a-z]{1,3}$/)
        contents.push "  #{key} = #{value},"
      else
        contents.push "  #{key} = {#{value}},"
      end
    end
  end
  contents.push "}"
  contents.join "\n"
end
up() click to toggle source
# File lib/nanoc/data_sources/bibtex_data_source.rb, line 6
def up
  @files = Dir[@config[:path].sub(/\/?$/, '/*.bib')];
  @exclude = {}
  (@config[:exclude] || []).each { |value| @exclude[value] = true }
end