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 ...@@ -36,6 +36,71 @@ Feature: BibTeX
And the "_site/bibliography/ruby.html" file should exist And the "_site/bibliography/ruby.html" file should exist
And I should see "The Ruby Programming Language" in "_site/bibliography/ruby.html" 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 @tags @details
Scenario: Links to Detail Pages are Generated Automatically Scenario: Links to Detail Pages are Generated Automatically
Given I have a scholar configuration with: Given I have a scholar configuration with:
......
...@@ -10,6 +10,9 @@ module Jekyll ...@@ -10,6 +10,9 @@ module Jekyll
'source' => './_bibliography', 'source' => './_bibliography',
'bibliography' => 'references.bib', 'bibliography' => 'references.bib',
'bibtex_options' => { :strip => false },
'bibtex_filters' => [ :latex ],
'details_dir' => 'bibliography', 'details_dir' => 'bibliography',
'details_layout' => 'bibtex.html', 'details_layout' => 'bibtex.html',
'details_link' => 'Details', 'details_link' => 'Details',
......
...@@ -26,9 +26,10 @@ module Jekyll ...@@ -26,9 +26,10 @@ module Jekyll
data['entry']['type'] = entry.type data['entry']['type'] = entry.type
data['entry']['bibtex'] = entry.to_s data['entry']['bibtex'] = entry.to_s
entry.fields.each do |key, value| 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
end end
......
...@@ -40,7 +40,11 @@ module Jekyll ...@@ -40,7 +40,11 @@ module Jekyll
end end
def bibtex_options def bibtex_options
@bibtex_options ||= { :strip => false } config['bibtex_options'] ||= {}
end
def bibtex_filters
config['bibtex_filters'] ||= []
end end
def bibtex_path def bibtex_path
...@@ -82,7 +86,7 @@ module Jekyll ...@@ -82,7 +86,7 @@ module Jekyll
def reference_tag(entry) def reference_tag(entry)
return missing_reference unless 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, reference = CiteProc.process entry.to_citeproc,
:style => config['style'], :locale => config['locale'], :format => 'html' :style => config['style'], :locale => config['locale'], :format => 'html'
...@@ -142,13 +146,15 @@ module Jekyll ...@@ -142,13 +146,15 @@ module Jekyll
context['cited'] << key context['cited'] << key
if bibliography.key?(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'], citation = CiteProc.process entry.to_citeproc, :style => config['style'],
:locale => config['locale'], :format => 'html', :mode => :citation :locale => config['locale'], :format => 'html', :mode => :citation
link_to "##{[prefix, entry.key].compact.join('-')}", citation.join link_to "##{[prefix, entry.key].compact.join('-')}", citation.join
else else
'(missing reference)' missing_reference
end end
rescue rescue
"(#{key})" "(#{key})"
...@@ -158,7 +164,7 @@ module Jekyll ...@@ -158,7 +164,7 @@ module Jekyll
if bibliography.key?(key) if bibliography.key?(key)
link_to details_link_for(bibliography[key]), text || config['details_link'] link_to details_link_for(bibliography[key]), text || config['details_link']
else else
'(missing reference)' missing_reference
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