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

improved utility functions

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