Commit b515a535 authored by David Moxey's avatar David Moxey

Merge remote-tracking branch 'upstream/master'

parents b0b74cfb 733e79b2
...@@ -255,6 +255,23 @@ For example, this could be rendered as: ...@@ -255,6 +255,23 @@ For example, this could be rendered as:
</cite> </cite>
</blockquote> </blockquote>
#### Multiple citation
You can cite multiple items in a single citation by referencing all ids
of the items you wish to quote separated by spaces. For example,
`{% cite ruby microscope %}` would produce a cite tag like:
<a href="#ruby">(Flanagan &amp; Matsumoto 2008; Shaughnessy 2013)</a>
#### Page numbers and locators
If you would like to add page numbers to your citation, you can use the
`-l` or `--locator` option. For example, `{% cite ruby -l 23-5 %}` would
produce a citation like `(Matsumoto, 2008, pp. 23-5)`.
When quoting multiple items (see above) you can add multiple locators after
the list of ids. For example, `{% cite ruby microscope -l 2 -l 24 & 32 %}`.
#### Displaying formatted references #### Displaying formatted references
If you want to display the full formatted reference entry, you can use the If you want to display the full formatted reference entry, you can use the
...@@ -446,7 +463,7 @@ License ...@@ -446,7 +463,7 @@ License
Jekyll-Scholar is distributed under the same license as Jekyll. Jekyll-Scholar is distributed under the same license as Jekyll.
Copyright (c) 2011-2013 [Sylvester Keil](http://sylvester.keil.or.at/) Copyright (c) 2011-2014 [Sylvester Keil](http://sylvester.keil.or.at/)
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal of this software and associated documentation files (the 'Software'), to deal
......
...@@ -204,7 +204,7 @@ Feature: BibTeX ...@@ -204,7 +204,7 @@ Feature: BibTeX
""" """
--- ---
--- ---
{% bibliography --style mla %} {% bibliography --style modern-language-association %}
""" """
When I run jekyll When I run jekyll
Then the _site directory should exist Then the _site directory should exist
......
...@@ -111,3 +111,107 @@ Feature: Citations ...@@ -111,3 +111,107 @@ Feature: Citations
Then the _site directory should exist Then the _site directory should exist
And the "_site/scholar.html" file should exist And the "_site/scholar.html" file should exist
And I should see "#a-ruby" in "_site/scholar.html" And I should see "#a-ruby" in "_site/scholar.html"
@tags @cite
Scenario: Multiple Citations
Given I have a scholar configuration with:
| key | value |
| source | ./_bibliography |
| bibliography | my_references |
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}
}
@book{microscope,
title = {Ruby Under a Microscope},
author = {Pat Shaughnessy},
year = {2013},
publisher = {No Starch Press}
}
"""
And I have a page "scholar.html":
"""
---
---
{% cite ruby microscope %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
And I should see "Flanagan &amp; Matsumoto, 2008; Shaughnessy, 2013" in "_site/scholar.html"
@tags @cite @locator
Scenario: Multiple Citations with locators
Given I have a scholar configuration with:
| key | value |
| source | ./_bibliography |
| bibliography | my_references |
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}
}
@book{microscope,
title = {Ruby Under a Microscope},
author = {Pat Shaughnessy},
year = {2013},
publisher = {No Starch Press}
}
"""
And I have a page "scholar.html":
"""
---
---
{% cite ruby microscope -l 2-3 --locator 23 & 42 %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
And I should see "Matsumoto, 2008, pp. 2-3; Shaughnessy, 2013, pp. 23 &amp; 42" in "_site/scholar.html"
@tags @cite @citation_number
Scenario: Multiple citations using citation numbers
Given I have a scholar configuration with:
| key | value |
| source | ./_bibliography |
| bibliography | my_references |
| style | ieee |
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}
}
@book{microscope,
title = {Ruby Under a Microscope},
author = {Pat Shaughnessy},
year = {2013},
publisher = {No Starch Press}
}
"""
And I have a page "scholar.html":
"""
---
---
{% cite ruby microscope %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
And I should see "\[1\], \[2\]" in "_site/scholar.html"
Feature: Cited-only Bibliographies
As a scholar who likes to blog
I want to cite references on my website
And generate bibliographies for the cited items
Scenario: Cited-only references from a single bibliography
Given I have a scholar configuration with:
| key | value |
| source | ./_bibliography |
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}
},
@book{smalltalk,
title = {Smalltalk Best Practice Patterns},
author = {Kent Beck},
year = {1996},
publisher = {Prentice Hall}
}
"""
And I have a page "scholar.html":
"""
---
---
{% cite smalltalk %}
{% bibliography --cited %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
And I should not see "<i>The Ruby Programming Language</i>" in "_site/scholar.html"
And I should see "<i>Smalltalk Best Practice Patterns</i>" in "_site/scholar.html"
Scenario: No-cited items result in empty bibliography
Given I have a scholar configuration with:
| key | value |
| source | ./_bibliography |
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}
},
@book{smalltalk,
title = {Smalltalk Best Practice Patterns},
author = {Kent Beck},
year = {1996},
publisher = {Prentice Hall}
}
"""
And I have a page "scholar.html":
"""
---
---
{% bibliography --cited %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
And I should not see "<i>The Ruby Programming Language</i>" in "_site/scholar.html"
And I should not see "<i>Smalltalk Best Practice Patterns</i>" in "_site/scholar.html"
...@@ -44,7 +44,6 @@ Then(/^the (.*) directory should exist$/) do |dir| ...@@ -44,7 +44,6 @@ Then(/^the (.*) directory should exist$/) do |dir|
end end
Then(/^I should see "(.*)" in "(.*)"$/) do |text, file| Then(/^I should see "(.*)" in "(.*)"$/) do |text, file|
puts File.open(file).readlines.join
assert_match Regexp.new(text), File.open(file).readlines.join assert_match Regexp.new(text), File.open(file).readlines.join
end end
......
Given /^I have a "([^"]*)" directory/ do |dir| Given(/^I have a "([^"]*)" directory/) do |dir|
FileUtils.mkdir(dir) FileUtils.mkdir(dir)
end 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| File.open(file, 'w') do |f|
f.write(string) f.write(string)
end end
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| File.open('_config.yml', 'w') do |f|
f.write("#{key}:\n") f.write("#{key}:\n")
table.hashes.each do |row| table.hashes.each do |row|
...@@ -18,7 +18,7 @@ Given /^I have a configuration file with "([^\"]*)" set to:$/ do |key, table| ...@@ -18,7 +18,7 @@ Given /^I have a configuration file with "([^\"]*)" set to:$/ do |key, table|
end end
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| File.open('_config.yml', 'w') do |f|
f.write("scholar:\n") f.write("scholar:\n")
table.hashes.each do |row| table.hashes.each do |row|
...@@ -28,7 +28,7 @@ Given /^I have a scholar configuration with:$/ do |table| ...@@ -28,7 +28,7 @@ Given /^I have a scholar configuration with:$/ do |table|
end 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('') data = File.open(file).readlines.join('')
m1 = data.match(p1) m1 = data.match(p1)
......
Before do 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) Dir.chdir(TEST_DIR)
end end
......
...@@ -26,7 +26,8 @@ Gem::Specification.new do |s| ...@@ -26,7 +26,8 @@ Gem::Specification.new do |s|
s.rubyforge_project = s.name s.rubyforge_project = s.name
s.add_runtime_dependency('jekyll', '~> 1.0') s.add_runtime_dependency('jekyll', '~> 1.0')
s.add_runtime_dependency('citeproc-ruby', '~> 0.0.6') s.add_runtime_dependency('citeproc-ruby', '~> 1.0')
s.add_runtime_dependency('csl-styles', '~> 1.0')
s.add_runtime_dependency('bibtex-ruby', '~> 3.0') s.add_runtime_dependency('bibtex-ruby', '~> 3.0')
s.files = `git ls-files`.split("\n") s.files = `git ls-files`.split("\n")
......
...@@ -4,7 +4,8 @@ require 'jekyll' ...@@ -4,7 +4,8 @@ require 'jekyll'
require 'optparse' require 'optparse'
require 'bibtex' require 'bibtex'
require 'citeproc' require 'citeproc/ruby'
require 'csl/styles'
require 'jekyll/scholar/version' require 'jekyll/scholar/version'
require 'jekyll/scholar/defaults' require 'jekyll/scholar/defaults'
......
module Jekyll module Jekyll
class Scholar class Scholar
class BibTeXConverter < Converter class BibTeXConverter < Converter
include Scholar::Utilities
safe true safe true
priority :highest priority :highest
attr_reader :config attr_reader :config
@pattern = (/bib(tex)?$/i).freeze @pattern = (/bib(tex)?$/i).freeze
@extension = '.html'.freeze @extension = '.html'.freeze
class << self class << self
attr_reader :pattern, :extension attr_reader :pattern, :extension
end end
def initialize(config = {}) def initialize(config = {})
super super
@config['scholar'] = Scholar.defaults.merge(@config['scholar'] || {}) @config['scholar'] = Scholar.defaults.merge(@config['scholar'] || {})
@markdown = Jekyll::Converters::Markdown.new(config) @markdown = Jekyll::Converters::Markdown.new(config)
end end
def matches(extension) def matches(extension)
extension =~ BibTeXConverter.pattern extension =~ BibTeXConverter.pattern
end end
def output_ext(extension) def output_ext(extension)
BibTeXConverter.extension BibTeXConverter.extension
end end
def convert(content) 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) if b.respond_to?(:to_citeproc)
CiteProc.process b.to_citeproc, :style => config['style'], render_bibliography b
:locale => config['locale'], :format => 'html'
else else
b.is_a?(BibTeX::MetaContent) ? b.to_s : '' b.is_a?(BibTeX::MetaContent) ? b.to_s : ''
end end
end end
@markdown.convert(content.join("\n")) @markdown.convert(content.join("\n"))
end end
end end
end end
end end
\ No newline at end of file
...@@ -38,15 +38,6 @@ module Jekyll ...@@ -38,15 +38,6 @@ module Jekyll
end end
end end
private
def citeproc
@citeproc ||= CiteProc::Processor.new do |p|
p.style = config['style']
p.format = 'html'
p.locale = config['locale']
end
end
end end
end end
......
...@@ -10,14 +10,14 @@ module Jekyll ...@@ -10,14 +10,14 @@ module Jekyll
super super
@config = Scholar.defaults.dup @config = Scholar.defaults.dup
@key, arguments = arguments.strip.split(/\s+/, 2) @keys, arguments = split_arguments(arguments)
optparse(arguments) optparse(arguments)
end end
def render(context) def render(context)
set_context_to context set_context_to context
cite key cite keys
end end
end end
...@@ -25,4 +25,4 @@ module Jekyll ...@@ -25,4 +25,4 @@ module Jekyll
end end
end end
Liquid::Template.register_tag('cite', Jekyll::Scholar::CiteTag) Liquid::Template.register_tag('cite', Jekyll::Scholar::CiteTag)
\ No newline at end of file
...@@ -8,14 +8,16 @@ module Jekyll ...@@ -8,14 +8,16 @@ module Jekyll
super super
@config = Scholar.defaults.dup @config = Scholar.defaults.dup
@key, arguments = arguments.strip.split(/\s+/, 2) @keys, arguments = split_arguments arguments
optparse(arguments) optparse(arguments)
end end
def render(context) def render(context)
set_context_to context set_context_to context
cite_details key, text keys.map { |key|
cite_details key, text
}.join("\n")
end end
end end
......
...@@ -3,32 +3,32 @@ module Jekyll ...@@ -3,32 +3,32 @@ module Jekyll
class QuoteTag < Liquid::Block class QuoteTag < Liquid::Block
include Scholar::Utilities include Scholar::Utilities
attr_reader :pages attr_reader :pages
def initialize(tag_name, arguments, tokens) def initialize(tag_name, arguments, tokens)
super super
@config = Scholar.defaults.dup @config = Scholar.defaults.dup
@key, arguments = arguments.strip.split(/\s+/, 2) @keys, arguments = split_arguments arguments
end end
def render(context) def render(context)
set_context_to context set_context_to context
quote = super.strip.gsub(/\n\n/, '</p><p>').gsub(/\n/, '<br/>') quote = super.strip.gsub(/\n\n/, '</p><p>').gsub(/\n/, '<br/>')
quote = content_tag :p, quote quote = content_tag :p, quote
citation = cite key citation = cite keys
quote << content_tag(:cite, citation) quote << content_tag(:cite, citation)
content_tag :blockquote, quote content_tag :blockquote, quote
end end
end end
end end
end end
Liquid::Template.register_tag('quote', Jekyll::Scholar::QuoteTag) Liquid::Template.register_tag('quote', Jekyll::Scholar::QuoteTag)
\ No newline at end of file
...@@ -8,16 +8,16 @@ module Jekyll ...@@ -8,16 +8,16 @@ module Jekyll
super super
@config = Scholar.defaults.dup @config = Scholar.defaults.dup
@key, arguments = arguments.strip.split(/\s+/, 2) @keys, arguments = split_arguments arguments
optparse(arguments) optparse(arguments)
end end
def render(context) def render(context)
set_context_to context set_context_to context
reference_tag bibliography[key] keys.map { |key|
rescue reference_tag bibliography[key]
"(#{key})" }.join("\n")
end end
end end
......
module Jekyll module Jekyll
class Scholar 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 # Utility methods used by several Scholar plugins. The methods in this
# module may depend on the presence of #config, #bibtex_files, and # module may depend on the presence of #config, #bibtex_files, and
# #site readers # #site readers
module Utilities module Utilities
attr_reader :config, :site, :query, attr_reader :config, :site, :query,
:context, :prefix, :key, :text :context, :prefix, :keys, :text
def split_arguments(arguments)