diff --git a/features/bibtex.feature b/features/bibtex.feature
index a4975e3d7b8acfb6a682ae802a3aaaaec4445218..bfe6e7c4a9a54b639cd91100f88e3c75bce8ef61 100644
--- a/features/bibtex.feature
+++ b/features/bibtex.feature
@@ -90,6 +90,34 @@ Feature: BibTeX
And the "_site/scholar.html" file should exist
And I should see "The Ruby Programming Language" in "_site/scholar.html"
+ @tags @bibliography @config
+ Scenario: Simple Bibliography With Custom Template
+ Given I have a scholar configuration with:
+ | key | value |
+ | source | ./_bibliography |
+ | bibliography_template | [%{key}]%{reference} |
+ And I have a "_bibliography" directory
+ And I have a file "_bibliography/references.bib":
+ """
+ @book{ruby,
+ title = {The Ruby Programming Language},
+ author = {Flanagan, David and Matsumoto, Yukihiro},
+ year = {2008},
+ publisher = {O'Reilly Media}
+ }
+ """
+ And I have a page "scholar.html":
+ """
+ ---
+ ---
+ {% bibliography -f references %}
+ """
+ When I run jekyll
+ Then the _site directory should exist
+ And the "_site/scholar.html" file should exist
+ And I should see "The Ruby Programming Language" in "_site/scholar.html"
+ And I should see "\[ruby\]The Ruby" in "_site/scholar.html"
- @tags @reference
+ @tags @reference @missing
Scenario: Missing references
Given I have a scholar configuration with:
| key | value |
@@ -54,4 +54,33 @@ Feature: Formatted References
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
- And I should see "missing reference" in "_site/scholar.html"
+ And I should see "(missing reference)" in "_site/scholar.html"
+
+ @tags @reference @missing
+ Scenario: Missing references with a custom text
+ Given I have a scholar configuration with:
+ | key | value |
+ | source | ./_bibliography |
+ | bibliography | my_references |
+ | missing_reference | not found! |
+ And I have a "_bibliography" directory
+ And I have a file "_bibliography/my_references.bib":
+ """
+ @book{ruby,
+ title = {The Ruby Programming Language},
+ author = {Flanagan, David and Matsumoto, Yukihiro},
+ year = {2008},
+ publisher = {O'Reilly Media}
+ }
+ """
+ And I have a page "scholar.html":
+ """
+ ---
+ ---
+ {% reference java %}
+ """
+ When I run jekyll
+ Then the _site directory should exist
+ And the "_site/scholar.html" file should exist
+ And I should see "not found!" in "_site/scholar.html"
+ And I should not see "(missing reference)" in "_site/scholar.html"
diff --git a/lib/jekyll/scholar/defaults.rb b/lib/jekyll/scholar/defaults.rb
index 2ab145d0c2727659c40d267d9beffa4521081604..81551cc392a6db344126f8a9ea425546571c7a4b 100644
--- a/lib/jekyll/scholar/defaults.rb
+++ b/lib/jekyll/scholar/defaults.rb
@@ -1,26 +1,30 @@
module Jekyll
class Scholar
- @defaults = Hash[*%w{
+ @defaults = {
+ 'style' => 'apa',
+ 'locale' => 'en',
- style apa
- locale en
+ 'sort_by' => 'none',
+ 'order' => 'ascending',
- sort_by none
- order ascending
+ 'source' => './_bibliography',
+ 'bibliography' => 'references.bib',
- source ./_bibliography
- bibliography references.bib
+ 'details_dir' => 'bibliography',
+ 'details_layout' => 'bibtex.html',
+ 'details_link' => 'Details',
- details_dir bibliography
- details_layout bibtex.html
- details_link Details
-
- bibliography_class bibliography
- details_link_class details
+ 'bibliography_class' => 'bibliography',
+ 'bibliography_template' => '%{reference}',
- query @*
-
- }].freeze
+ 'reference_tagname' => 'span',
+ 'missing_reference' => '(missing reference)',
+
+ 'details_link_class' => 'details',
+
+ 'query' => '@*'
+
+ }.freeze
class << self
attr_reader :defaults
diff --git a/lib/jekyll/scholar/tags/bibliography.rb b/lib/jekyll/scholar/tags/bibliography.rb
index 6546542a7b6259b2bf4283d01e9fde170d3ed963..fbaf0a1b6de61461e46ebed5bfb9f3bc77612434 100644
--- a/lib/jekyll/scholar/tags/bibliography.rb
+++ b/lib/jekyll/scholar/tags/bibliography.rb
@@ -24,7 +24,7 @@ module Jekyll
end
references.map! do |entry|
- reference = reference_tag entry
+ reference = bibliography_tag entry
if generate_details?
reference << link_to(details_link_for(entry),
diff --git a/lib/jekyll/scholar/utilities.rb b/lib/jekyll/scholar/utilities.rb
index 57ebbeeafba8f06b12e5c1b7d628c8944cfafab0..50bc7fb18d3f3d880704dab3d86ae3064c8dee58 100644
--- a/lib/jekyll/scholar/utilities.rb
+++ b/lib/jekyll/scholar/utilities.rb
@@ -80,13 +80,35 @@ module Jekyll
end
def reference_tag(entry)
- return '(missing reference)' unless entry
+ return missing_reference unless entry
entry = entry.convert(:latex)
reference = CiteProc.process entry.to_citeproc,
:style => config['style'], :locale => config['locale'], :format => 'html'
- content_tag :span, reference, :id => [prefix, entry.key].compact.join('-')
+ content_tag reference_tagname, reference,
+ :id => [prefix, entry.key].compact.join('-')
+ end
+
+ def missing_reference
+ config['missing_reference']
+ end
+
+ def reference_tagname
+ config['reference_tagname'] || :span
+ end
+
+ def bibliography_template
+ config['bibliography_template'] || '%{reference}'
+ end
+
+ def bibliography_tag(entry)
+ return missing_reference unless entry
+
+ bibliography_template % {
+ :reference => reference_tag(entry),
+ :key => entry.key
+ }
end
def generate_details?