Commit 56208901 authored by Sylvester Keil's avatar Sylvester Keil

added css classes to bibliography and links

parent 2b984387
......@@ -74,4 +74,4 @@ Feature: BibTeX
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
And I should see "<a href=\"/bibliography/ruby.html\">" in "_site/scholar.html"
And I should see "<a[^>]+href=\"/bibliography/ruby.html\">" in "_site/scholar.html"
......@@ -15,6 +15,9 @@ module Jekyll
details_layout bibtex.html
details_link Details
bibliography_class bibliography
details_link_class details
query @*
}].freeze
......
......@@ -17,21 +17,30 @@ module Jekyll
references = entries.map do |entry|
reference = CiteProc.process entry.to_citeproc, :style => config['style'],
:locale => config['locale'], :format => 'html'
reference = content_tag :span, reference, :id => entry.key
if generate_details?
reference << link_to(details_link_for(entry), config['details_link'])
reference << link_to(details_link_for(entry),
config['details_link'], :class => config['details_link_class'])
end
content_tag :li, reference
end
content_tag :ol, references.join("\n")
end
content_tag :ol, references.join("\n"), :class => config['bibliography_class']
end
end
private
def citeproc
@citeproc ||= CiteProc::Processor.new do |p|
p.style = config['style']
p.format = 'html'
p.locale = config['locale']
end
end
end
end
......
module Jekyll
class Scholar
# Utility methods used by several Scholar plugins. The methods in this
# module may depend on the presence of #config, #bibtex_file, and
# #site readers
module Utilities
attr_reader :bibtex_file, :config, :site
def bibtex_options
@bibtex_options ||= { :filter => :latex }
end
def bibtex_path
@bibtex_path ||= extend_path(bibtex_file)
end
def bibliography
@bibliography ||= BibTeX.open(bibtex_path, bibtex_options)
end
end
def entries
b = bibliography[config['query']]
......@@ -27,83 +27,85 @@ module Jekyll
b = b.sort_by { |e| e[config['sort_by']].to_s }
b.reverse! if config['order'] =~ /^(desc|reverse)/i
end
b
end
def extend_path(name)
if name.nil? || name.empty?
name = config['bibliography']
end
p = File.join(config['source'], name)
p << '.bib' unless File.exists?(p)
p
end
def generate_details?
site.layouts.key?(File.basename(config['details_layout'], '.html'))
end
def details_file_for(entry)
name = entry.key.to_s.dup
name.gsub!(/[:\s]+/, '_')
[name, 'html'].join('.')
end
def details_link_for(entry, base = base_url)
File.join(base, details_path, details_file_for(entry))
end
def base_url
@base_url ||= site.config['baseurl'] || site.config['base_url'] || ''
end
def details_path
config['details_dir']
end
def cite(key)
entry = bibliography[key]
if bibliography.key?(key)
citation = CiteProc.process entry.to_citeproc, :style => config['style'],
:locale => config['locale'], :format => 'html', :mode => :citation
link_to "##{entry.key}", citation.join
else
"(missing reference)"
end
rescue
"(#{key})"
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
\ No newline at end of file
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