Commit b859ada4 authored by Sylvester Keil's avatar Sylvester Keil

Merge pull request #8 from gousiosg/master

New tag to print a formatted citation
parents 49c165c1 ebdbacc1
......@@ -177,6 +177,34 @@ For example, this could be rendered as:
</cite>
</blockquote>
#### Displaying formatted references
If you want to display the full formatted reference entry, you can use the
`reference` tag. For example, given the following Bibtex entry,
@book{ruby,
title = {The Ruby Programming Language},
author = {Flanagan, David and Matsumoto, Yukihiro},
year = {2008},
publisher = {O'Reilly Media}
}
using `{% reference ruby %}` anywhere in your page, it will print
Flanagan, D & Yukihiro, M. (2008). *The Ruby Programming Language.*. O'Reilly Media
(provided that you use the default formatting style)
The `reference` tag accepts a second optional argument that specifies the
absolute path of the Bibtex file to use as input. Using it, you can override
the file from which the bib entries are read. This can be handy if you
want to use a special Bibtex file as input for a specific page. As an example,
the tag
`{% reference ruby,/home/foo/bar.bib %}`
will attempt to read the key `ruby` from file `/home/foo/bar.bib`. It will not
fallback to the default Bibtex file.
### Detail Pages
......
......@@ -13,4 +13,5 @@ require 'jekyll/scholar/tags/bibliography'
require 'jekyll/scholar/tags/cite'
require 'jekyll/scholar/tags/cite_details'
require 'jekyll/scholar/tags/quote'
require 'jekyll/scholar/tags/print_cite'
require 'jekyll/scholar/generators/details'
module Jekyll
class Scholar
class ReferenceTag < Liquid::Tag
include Scholar::Utilities
attr_reader :key, :file
def initialize(tag_name, arguments, tokens)
super
@config = Scholar.defaults.dup
@key, @file = arguments.strip.split(/\s*,\s*/, 2)
end
def render(context)
set_context_to context
bib = unless file.nil?
BibTeX.open(file, { :filter => :latex })
else
set_context_to context
bibliography
end
entry = bib[key]
if bib.key?(key)
CiteProc.process entry.to_citeproc,
:style => config['style'],
:locale => config['locale'],
:format => 'html'
else
"(missing reference)"
end
rescue
"(#{key})"
end
end
end
end
Liquid::Template.register_tag('reference', Jekyll::Scholar::ReferenceTag)
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