Commit 2399deac authored by Sylvester Keil's avatar Sylvester Keil

make bibtex filters configurable

fixes #17

see #16
parent 0998721a
......@@ -36,6 +36,71 @@ Feature: BibTeX
And the "_site/bibliography/ruby.html" file should exist
And I should see "The Ruby Programming Language" in "_site/bibliography/ruby.html"
@generators
Scenario: LaTeX conversion is applied to everything except the bibtex field
Given I have a scholar configuration with:
| key | value |
| source | ./_bibliography |
| details_layout | details.html |
And I have a "_bibliography" directory
And I have a file "_bibliography/references.bib":
"""
@book{ruby,
title = {An Umlaut \"a!},
}
"""
And I have a "_layouts" directory
And I have a file "_layouts/details.html":
"""
---
---
<html>
<head></head>
<body>
Title: {{ page.entry.title }}
{{ page.entry.bibtex }}
</body>
</html>
"""
When I run jekyll
Then the _site directory should exist
And the "_site/bibliography/ruby.html" file should exist
And I should see "Title: An Umlaut ä!" in "_site/bibliography/ruby.html"
And I should see "title = {An Umlaut \\\"a!}" in "_site/bibliography/ruby.html"
@generators
Scenario: LaTeX conversion can be turned off
Given I have a scholar configuration with:
| key | value |
| source | ./_bibliography |
| details_layout | details.html |
| bibtex_filters | |
And I have a "_bibliography" directory
And I have a file "_bibliography/references.bib":
"""
@book{ruby,
title = {An Umlaut \"a!},
}
"""
And I have a "_layouts" directory
And I have a file "_layouts/details.html":
"""
---
---
<html>
<head></head>
<body>
Title: {{ page.entry.title }}
{{ page.entry.bibtex }}
</body>
</html>
"""
When I run jekyll
Then the _site directory should exist
And the "_site/bibliography/ruby.html" file should exist
And I should see "Title: An Umlaut \\\"a!" in "_site/bibliography/ruby.html"
And I should see "title = {An Umlaut \\\"a!}" in "_site/bibliography/ruby.html"
@tags @details
Scenario: Links to Detail Pages are Generated Automatically
Given I have a scholar configuration with:
......
......@@ -10,6 +10,9 @@ module Jekyll
'source' => './_bibliography',
'bibliography' => 'references.bib',
'bibtex_options' => { :strip => false },
'bibtex_filters' => [ :latex ],
'details_dir' => 'bibliography',
'details_layout' => 'bibtex.html',
'details_link' => 'Details',
......
......@@ -26,9 +26,10 @@ module Jekyll
data['entry']['type'] = entry.type
data['entry']['bibtex'] = entry.to_s
entry.fields.each do |key, value|
data['entry'][key.to_s] = value.convert(:latex).to_s
value = value.convert(*bibtex_filters) unless bibtex_filters.empty?
data['entry'][key.to_s] = value.to_s
end
end
......
......@@ -40,7 +40,11 @@ module Jekyll
end
def bibtex_options
@bibtex_options ||= { :strip => false }
config['bibtex_options'] ||= {}
end
def bibtex_filters
config['bibtex_filters'] ||= []
end
def bibtex_path
......@@ -82,7 +86,7 @@ module Jekyll
def reference_tag(entry)
return missing_reference unless entry
entry = entry.convert(:latex)
entry = entry.convert(*bibtex_filters) unless bibtex_filters.empty?
reference = CiteProc.process entry.to_citeproc,
:style => config['style'], :locale => config['locale'], :format => 'html'
......@@ -142,13 +146,15 @@ module Jekyll
context['cited'] << key
if bibliography.key?(key)
entry = bibliography[key].convert(:latex)
entry = bibliography[key]
entry = entry.convert(*bibtex_filters) unless bibtex_filters.empty?
citation = CiteProc.process entry.to_citeproc, :style => config['style'],
:locale => config['locale'], :format => 'html', :mode => :citation
link_to "##{[prefix, entry.key].compact.join('-')}", citation.join
else
'(missing reference)'
missing_reference
end
rescue
"(#{key})"
......@@ -158,7 +164,7 @@ module Jekyll
if bibliography.key?(key)
link_to details_link_for(bibliography[key]), text || config['details_link']
else
'(missing reference)'
missing_reference
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