Class: BibtexDataSource
- Inherits:
-
Nanoc3::DataSource
- Object
- Nanoc3::DataSource
- BibtexDataSource
- Defined in:
- lib/nanoc/data_sources/bibtex_data_source.rb
Instance Method Summary collapse
Instance Method Details
#extract_attributes(entry) ⇒ Object
36 37 38 39 40 |
# File 'lib/nanoc/data_sources/bibtex_data_source.rb', line 36 def extract_attributes entry attributes = { :key => entry.key } entry.each { |key, value| attributes[key] = value.convert(:latex) } attributes end |
#items ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/nanoc/data_sources/bibtex_data_source.rb', line 12 def items @files.map do |file| entries = BibTeX.open(file) entries.map do |entry| Nanoc3::Item.new to_bibtex(entry), extract_attributes(entry), entry.key end end.flatten! end |
#to_bibtex(entry) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/nanoc/data_sources/bibtex_data_source.rb', line 21 def to_bibtex entry contents = [ "@#{entry.type}{#{entry.key}," ] entry.each do |key, value| unless @exclude[key.to_s] unless value =~ /\s|\{|\}|"|,|:|-/ 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 |