Commit 9c258e1c authored by Sylvester Keil's avatar Sylvester Keil

improved utility functions

#1
parent 5fa5e079
...@@ -12,23 +12,22 @@ module Jekyll ...@@ -12,23 +12,22 @@ module Jekyll
end end
def render(context) def render(context)
@site = context.registers[:site] set_context_to context
config.merge!(site.config['scholar'] || {})
references = entries.map do |e| references = entries.map do |entry|
reference = CiteProc.process e.to_citeproc, :style => config['style'], reference = CiteProc.process entry.to_citeproc, :style => config['style'],
:locale => config['locale'], :format => 'html' :locale => config['locale'], :format => 'html'
reference = "<span id='#{e.key}'>#{reference}</span>" reference = content_tag :span, reference, :id => entry.key
if generate_details? if generate_details?
reference << "<a href='#{details_link_for(e)}'>#{config['details_link']}</a>" reference << link_to(details_link_for(entry), config['details_link'])
end end
"<li>#{reference}</li>" content_tag :li, reference
end end
"<ol>\n#{references.join("\n")}\n</ol>" content_tag :ol, references.join("\n")
end end
end end
......
...@@ -14,15 +14,15 @@ module Jekyll ...@@ -14,15 +14,15 @@ module Jekyll
end end
def render(context) def render(context)
config.merge!(context.registers[:site].config['scholar'] || {}) set_context_to context
entry = bibliography[key] entry = bibliography[key]
if entry if entry
c = CiteProc.process entry.to_citeproc, :style => config['style'], citation = CiteProc.process entry.to_citeproc, :style => config['style'],
:locale => config['locale'], :format => 'html', :mode => :citation :locale => config['locale'], :format => 'html', :mode => :citation
"<a href='##{entry.key}'>#{c}</a>" link_to "##{entry.key}", citation
else else
"(missing reference)" "(missing reference)"
end end
......
...@@ -53,14 +53,39 @@ module Jekyll ...@@ -53,14 +53,39 @@ module Jekyll
[name, 'html'].join('.') [name, 'html'].join('.')
end end
def details_link_for(entry) def details_link_for(entry, base = site.config['baseurl'] || '/')
[site.source, details_path, details_file_for(entry)].join('/') [base, details_path, details_file_for(entry)].compact.join('/')
end end
def details_path def details_path
config['details_dir'] config['details_dir']
end end
def content_tag(name, content_or_attributes, attributes = {})
if content_or_attributes.is_a?(Hash)
content, attributes = nil, content_or_attributes
else
content = content_or_attributes
end
attributes = attributes.map { |k,v| %Q(#{k}="#{v}") }
if content.nil?
"<#{[name, attributes].flatten.compact.join(' ')}/>"
else
"<#{[name, attributes].flatten.compact.join(' ')}>#{content}</#{name}>"
end
end
def link_to(href, content, attributes = {})
content_tag :a, content || href, attributes.merge(:href => href)
end
def set_context_to(context)
@site = context.registers[:site]
config.merge!(site.config['scholar'] || {})
end
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