Finalize #180

Fixes #161
parent f4550644
...@@ -5,12 +5,7 @@ module Jekyll ...@@ -5,12 +5,7 @@ module Jekyll
# Load styles into static memory. # Load styles into static memory.
# They should be thread safe as long as they are # They should be thread safe as long as they are
# treated as being read-only. # treated as being read-only.
STYLES = Hash.new do |h, k| STYLES = {}
style = CSL::Style.load k
style = style.independent_parent unless style.independent?
h[k.to_s] = style
end
# 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_files, and # module may depend on the presence of #config, #bibtex_files, and
...@@ -598,12 +593,12 @@ module Jekyll ...@@ -598,12 +593,12 @@ module Jekyll
item.label = label unless label.nil? item.label = label unless label.nil?
item item
}, style_cache(style).citation }, styles(style).citation
end end
def render_bibliography(entry, index = nil) def render_bibliography(entry, index = nil)
renderer.render citation_item_for(entry, index), renderer.render citation_item_for(entry, index),
style_cache(style).bibliography styles(style).bibliography
end end
def citation_item_for(entry, citation_number = nil) def citation_item_for(entry, citation_number = nil)
...@@ -694,23 +689,27 @@ module Jekyll ...@@ -694,23 +689,27 @@ module Jekyll
self self
end end
# Try to resolve local style paths def load_style(uri)
# relative to Jekyll's source directory begin
def style_cache(style_name) style = CSL::Style.load uri
style = rescue CSL::ParseError => error
if site && site.source # Try to resolve local style paths
site_relative_style = File.join(site.source, style_name) # relative to Jekyll's source directory
site_relative_style = File.join(site.source, uri)
if Pathname.new(style_name).relative? && File.exist?(site_relative_style) raise error unless File.exist?(site_relative_style)
site_relative_style style = CSL::Style.load site_relative_style
else end
style_name
end if style.independent?
else style
style_name else
end style.independent_parent
end
end
STYLES[style] def styles(style)
STYLES[style] ||= load_style(style)
end end
end end
......
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