class Gollum::Filter::BibTeX

Render BibTeX files.

Public Instance Methods

extract(data) click to toggle source
# File lib/gollum-lib/filter/bibtex.rb, line 12
def extract(data)
  return data unless supported_format? && gems_available? && bib = ::BibTeX.parse(data).convert(:latex)
  style = find_csl_data('csl') || ::CSL::Style.default
  locale = find_csl_data('locale') || ::CSL::Locale.default

  begin
    style = ::CSL::Style.load(style)
    ::CSL::Locale.load(locale)
  rescue ::CSL::ParseError => error
    log_failure(error.to_s)
    return CGI.escapeHTML(data)
  end

  citeproc = ::CiteProc::Processor.new(style: style, locale: locale, format: 'html')
  citeproc.import(bib.to_citeproc)
  citeproc.bibliography.references.join('<br/>')
end
process(data) click to toggle source
# File lib/gollum-lib/filter/bibtex.rb, line 30
def process(data)
  data
end

Private Instance Methods

find_csl_data(key) click to toggle source
# File lib/gollum-lib/filter/bibtex.rb, line 50
def find_csl_data(key)
  path = @markup.metadata ? @markup.metadata[key] : nil
  file = path ? @markup.wiki.file(path) : nil
  file.nil? ? path : file.raw_data
end
gems_available?() click to toggle source
# File lib/gollum-lib/filter/bibtex.rb, line 46
def gems_available?
  ::Gollum::Markup.formats[:bib][:enabled]
end
log_failure(msg) click to toggle source
# File lib/gollum-lib/filter/bibtex.rb, line 36
def log_failure(msg)
  @markup.metadata = {} unless @markup.metadata
  @markup.metadata['errors'] = [] unless @markup.metadata['errors']
  @markup.metadata['errors'] << "Could not render the bibliography because no valid CSL or locale file was found in the wiki or in the CSL directory. Please commited a valid file, or install the csl-styles gem. The message from the parser was: #{msg.to_s}."
end
supported_format?() click to toggle source
# File lib/gollum-lib/filter/bibtex.rb, line 42
def supported_format?
  @markup.format == :bib
end