Commit 7f3a3bf5 authored by Sylvester Keil's avatar Sylvester Keil

upgrade citeproc

parent 76d01e26
......@@ -204,7 +204,7 @@ Feature: BibTeX
"""
---
---
{% bibliography --style mla %}
{% bibliography --style modern-language-association %}
"""
When I run jekyll
Then the _site directory should exist
......
......@@ -44,7 +44,6 @@ Then(/^the (.*) directory should exist$/) do |dir|
end
Then(/^I should see "(.*)" in "(.*)"$/) do |text, file|
puts File.open(file).readlines.join
assert_match Regexp.new(text), File.open(file).readlines.join
end
......
Given /^I have a "([^"]*)" directory/ do |dir|
Given(/^I have a "([^"]*)" directory/) do |dir|
FileUtils.mkdir(dir)
end
Given /^I have a (?:page|file) "([^"]*)":$/ do |file, string|
Given(/^I have a (?:page|file) "([^"]*)":$/) do |file, string|
File.open(file, 'w') do |f|
f.write(string)
end
end
Given /^I have a configuration file with "([^\"]*)" set to:$/ do |key, table|
Given(/^I have a configuration file with "([^\"]*)" set to:$/) do |key, table|
File.open('_config.yml', 'w') do |f|
f.write("#{key}:\n")
table.hashes.each do |row|
......@@ -18,7 +18,7 @@ Given /^I have a configuration file with "([^\"]*)" set to:$/ do |key, table|
end
end
Given /^I have a scholar configuration with:$/ do |table|
Given(/^I have a scholar configuration with:$/) do |table|
File.open('_config.yml', 'w') do |f|
f.write("scholar:\n")
table.hashes.each do |row|
......@@ -28,7 +28,7 @@ Given /^I have a scholar configuration with:$/ do |table|
end
Then /^"(.*)" should come before "(.*)" in "(.*)"$/ do |p1, p2, file|
Then(/^"(.*)" should come before "(.*)" in "(.*)"$/) do |p1, p2, file|
data = File.open(file).readlines.join('')
m1 = data.match(p1)
......
Before do
FileUtils.mkdir_p(TEST_DIR) unless File.exist?(TEST_DIR)
FileUtils.rm_rf(TEST_DIR) if File.exist?(TEST_DIR)
FileUtils.mkdir_p(TEST_DIR)
Dir.chdir(TEST_DIR)
end
......
......@@ -26,7 +26,8 @@ Gem::Specification.new do |s|
s.rubyforge_project = s.name
s.add_runtime_dependency('jekyll', '~> 1.0')
s.add_runtime_dependency('citeproc-ruby', '~> 0.0.6')
s.add_runtime_dependency('citeproc-ruby', '~> 1.0.1')
s.add_runtime_dependency('csl-styles', '~> 1.0.1')
s.add_runtime_dependency('bibtex-ruby', '~> 3.0')
s.files = `git ls-files`.split("\n")
......
......@@ -4,7 +4,8 @@ require 'jekyll'
require 'optparse'
require 'bibtex'
require 'citeproc'
require 'citeproc/ruby'
require 'csl/styles'
require 'jekyll/scholar/version'
require 'jekyll/scholar/defaults'
......
module Jekyll
class Scholar
class BibTeXConverter < Converter
include Scholar::Utilities
safe true
priority :highest
attr_reader :config
attr_reader :config
@pattern = (/bib(tex)?$/i).freeze
@extension = '.html'.freeze
class << self
attr_reader :pattern, :extension
end
class << self
attr_reader :pattern, :extension
end
def initialize(config = {})
super
@config['scholar'] = Scholar.defaults.merge(@config['scholar'] || {})
@markdown = Jekyll::Converters::Markdown.new(config)
end
def matches(extension)
extension =~ BibTeXConverter.pattern
end
extension =~ BibTeXConverter.pattern
end
def output_ext(extension)
BibTeXConverter.extension
end
BibTeXConverter.extension
end
def convert(content)
content = BibTeX.parse(content, :strict => true, :include => [:meta_content], :filter => [:latex]).map do |b|
content = BibTeX.parse(content, :strict => true, :include => [:meta_content], :filter => [:latex]).map do |b|
if b.respond_to?(:to_citeproc)
CiteProc.process b.to_citeproc, :style => config['style'],
:locale => config['locale'], :format => 'html'
render_bibliography b
else
b.is_a?(BibTeX::MetaContent) ? b.to_s : ''
b.is_a?(BibTeX::MetaContent) ? b.to_s : ''
end
end
@markdown.convert(content.join("\n"))
end
end
end
end
\ No newline at end of file
end
module Jekyll
class Scholar
# Load styles into static memory.
# They should be thread safe as long as they are
# treated as being read-only.
STYLES = Hash.new do |h, k|
h[k.to_s] = CSL::Style.load k
end
# Utility methods used by several Scholar plugins. The methods in this
# module may depend on the presence of #config, #bibtex_files, and
# #site readers
......@@ -144,8 +152,7 @@ module Jekyll
return missing_reference unless entry
entry = entry.convert(*bibtex_filters) unless bibtex_filters.empty?
reference = CiteProc.process entry.to_citeproc,
:style => style, :locale => config['locale'], :format => 'html'
reference = render_bibliography entry
content_tag reference_tagname, reference,
:id => [prefix, entry.key].compact.join('-')
......@@ -248,6 +255,25 @@ module Jekyll
config['details_dir']
end
def renderer
@renderer ||= CiteProc::Ruby::Renderer.new :format => 'html',
:style => style, :locale => config['locale']
end
def render_citation(entry)
renderer.render [citation_item_for(entry)], STYLES[style].citation
end
def render_bibliography(entry)
renderer.render citation_item_for(entry), STYLES[style].bibliography
end
def citation_item_for(entry)
CiteProc::CitationItem.new id: entry.id do |c|
c.data = CiteProc::Item.new entry.to_citeproc
end
end
def cite(key)
context['cited'] ||= []
context['cited'] << key
......@@ -256,10 +282,7 @@ module Jekyll
entry = bibliography[key]
entry = entry.convert(*bibtex_filters) unless bibtex_filters.empty?
citation = CiteProc.process entry.to_citeproc, :style => style,
:locale => config['locale'], :format => 'html', :mode => :citation
link_to "##{[prefix, entry.key].compact.join('-')}", citation.join
link_to "##{[prefix, entry.key].compact.join('-')}", render_citation(entry)
else
missing_reference
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