Commit 50f6abef authored by Sylvester Keil's avatar Sylvester Keil

add backwards compatibility to #42

parent c01810f8
...@@ -2,11 +2,11 @@ module Jekyll ...@@ -2,11 +2,11 @@ module Jekyll
class Scholar class Scholar
# Utility methods used by several Scholar plugins. The methods in this # Utility methods used by several Scholar plugins. The methods in this
# module may depend on the presence of #config, #bibtex_file, and # module may depend on the presence of #config, #bibtex_files, and
# #site readers # #site readers
module Utilities module Utilities
attr_reader :bibtex_file, :config, :site, :query, attr_reader :config, :site, :query,
:context, :prefix, :key, :text :context, :prefix, :key, :text
def optparse(arguments) def optparse(arguments)
...@@ -18,8 +18,8 @@ module Jekyll ...@@ -18,8 +18,8 @@ module Jekyll
end end
opts.on('-f', '--file FILE') do |file| opts.on('-f', '--file FILE') do |file|
@bibtex_file ||= [] @bibtex_files ||= []
@bibtex_file << file @bibtex_files << file
end end
opts.on('-q', '--query QUERY') do |query| opts.on('-q', '--query QUERY') do |query|
...@@ -48,6 +48,15 @@ module Jekyll ...@@ -48,6 +48,15 @@ module Jekyll
parser.parse argv.map(&:strip).reject(&:empty?) parser.parse argv.map(&:strip).reject(&:empty?)
end end
def bibtex_files
@bibtex_files ||= [config['bibliography']]
end
# :nodoc: backwards compatibility
def bibtex_file
bibtex_files[0]
end
def bibtex_options def bibtex_options
config['bibtex_options'] ||= {} config['bibtex_options'] ||= {}
end end
...@@ -56,15 +65,23 @@ module Jekyll ...@@ -56,15 +65,23 @@ module Jekyll
config['bibtex_filters'] ||= [] config['bibtex_filters'] ||= []
end end
def bibtex_paths
@bibtex_paths ||= bibtex_files.map { |file|
extend_path file
}
end
# :nodoc: backwards compatibility
def bibtex_path def bibtex_path
@bibtex_path ||= extend_path(bibtex_file) bibtex_paths[0]
end end
def bibliography def bibliography
unless @bibliography unless @bibliography
tmp = "" @bibliography = BibTeX.parse(
bibtex_path.each{|s| tmp << IO.read(s)} bibtex_paths.reduce('') { |s, p| s << IO.read(p) },
@bibliography = BibTeX.parse(tmp, bibtex_options) bibtex_options
)
@bibliography.replace_strings if replace_strings? @bibliography.replace_strings if replace_strings?
end end
...@@ -112,22 +129,15 @@ module Jekyll ...@@ -112,22 +129,15 @@ module Jekyll
def extend_path(name) def extend_path(name)
if name.nil? || name.empty? if name.nil? || name.empty?
name = [config['bibliography']] name = config['bibliography']
end end
ret = []
name.each { |file|
# return as is if it is an absolute path # return as is if it is an absolute path
if file.start_with?('/') && File.exists?(file) return name if name.start_with?('/') && File.exists?(name)
ret << file
else p = File.join(config['source'], name)
p = File.join(config['source'], file)
p << '.bib' unless File.exists?(p) p << '.bib' unless File.exists?(p)
ret << p p
end
}
ret
end end
def reference_tag(entry) def reference_tag(entry)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment