Class: BibtexDataSource
- Inherits:
-
Nanoc::DataSource
- Object
- Nanoc::DataSource
- BibtexDataSource
- Defined in:
- lib/nanoc/data_sources/bibtex_data_source.rb
Instance Method Summary collapse
Instance Method Details
#extract_attributes(entry) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# 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 ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# 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) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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 ⇒ Object
6 7 8 9 10 |
# 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 |