class Gollum::Filter::PandocBib

When using pandoc, put relevant bibliography metadata extracted in the YAML filter back in the document so it gets passed on to pandoc.

Constants

ALL_BIB_KEYS
BIB_KEYS
BIB_PATH_KEYS

Public Instance Methods

extract(data) click to toggle source
# File lib/gollum-lib/filter/pandoc_bib.rb, line 15
def extract(data)
  return data unless supported_format? && bibliography_metadata_present?
  @bib_metadata.select! {|key, _value| BIB_KEYS.include?(key)}

  BIB_PATH_KEYS.each do |bibliography_key|
    if path = @markup.metadata[bibliography_key]
      next unless file = @markup.wiki.file(path)
      @bib_metadata[bibliography_key] = path_for_bibfile(file)
    end
  end
  @bib_metadata.empty? ? data : "#{@bib_metadata.to_yaml}---\n#{data}"
end
process(data) click to toggle source
# File lib/gollum-lib/filter/pandoc_bib.rb, line 11
def process(data)
  data
end

Private Instance Methods

bibliography_metadata_present?() click to toggle source
# File lib/gollum-lib/filter/pandoc_bib.rb, line 48
def bibliography_metadata_present?
    return false unless @markup.metadata
    @bib_metadata = @markup.wiki.metadata.merge(@markup.metadata)
    @bib_metadata.keys.any? {|key| ALL_BIB_KEYS.include?(key)}
end
path_for_bibfile(file) click to toggle source
# File lib/gollum-lib/filter/pandoc_bib.rb, line 30
def path_for_bibfile(file)
  if @markup.wiki.repo_is_bare
    path = Pathname.new("#{::File.join(::Dir.tmpdir, file.sha)}#{::File.extname(file.path)}")
      unless path.exist?
        path.open('w') do |copy_file|
          copy_file.write(file.raw_data)
        end
      end
    path.to_s
  else
    ::File.expand_path(::File.join(@markup.wiki.path, file.path))
  end
end
supported_format?() click to toggle source
# File lib/gollum-lib/filter/pandoc_bib.rb, line 44
def supported_format?
  @markup.format == :markdown
end