Commit 0143eb4c authored by Sylvester Keil's avatar Sylvester Keil
Browse files

Support multiple locator labels

See #147
parent a4adcb40
...@@ -361,13 +361,18 @@ like: `...as Matz explains (2008, p. 42)`. ...@@ -361,13 +361,18 @@ like: `...as Matz explains (2008, p. 42)`.
#### Page numbers and locators #### Page numbers and locators
If you would like to add page numbers to your citation, you can use the If you would like to add page numbers or similar locators to your citation,
`-l` or `--locator` option. For example, `{% cite ruby -l 23-5 %}` would use the `-l` or `--locator` option. For example, `{% cite ruby --locator 23-5 %}` would
produce a citation like `(Matsumoto, 2008, pp. 23-5)`. produce a citation like `(Matsumoto, 2008, pp. 23-5)`.
When quoting multiple items (see above) you can add multiple locators after 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 %}`. the list of ids. For example, `{% cite ruby microscope -l 2 -l 24 & 32 %}`.
Page is the default locator, however, you can indicate the type of locator
by adding a `-L` or `--label` option (one for each locator) for instance,
`{% cite ruby microscope --label chapter --locator 3 -L figure -l 24 & 32 %}`
produces something like: `(Matsumoto, 2008, chap. 3; Shaughnessy, 2013, figs. 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
......
...@@ -250,6 +250,39 @@ Feature: Citations ...@@ -250,6 +250,39 @@ Feature: Citations
year = {2008}, year = {2008},
publisher = {O'Reilly Media} 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 --label chapter --locator 2-3 -L figure -l 4,5 %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
And I should see "Matsumoto, 2008, chaps. 2-3; Shaughnessy, 2013, figs. 4,5" in "_site/scholar.html"
@tags @cite @locator @label
Scenario: Citations with multiple locator labels
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 = {Matsumoto, Yukihiro},
year = {2008},
publisher = {O'Reilly Media}
}
""" """
And I have a page "scholar.html": And I have a page "scholar.html":
""" """
...@@ -260,7 +293,7 @@ Feature: Citations ...@@ -260,7 +293,7 @@ Feature: Citations
When I run jekyll When I run jekyll
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 "Flanagan & Matsumoto, 2008, chap. 3" in "_site/scholar.html" And I should see "Matsumoto, 2008, chap. 3" in "_site/scholar.html"
@tags @cite @citation_number @tags @cite @citation_number
Scenario: Multiple citations using citation numbers Scenario: Multiple citations using citation numbers
......
...@@ -18,9 +18,7 @@ module Jekyll ...@@ -18,9 +18,7 @@ module Jekyll
module Utilities module Utilities
attr_reader :config, :site, :context, attr_reader :config, :site, :context, :prefix, :text, :offset, :max
:prefix, :text, :offset, :max, :label
def split_arguments(arguments) def split_arguments(arguments)
...@@ -71,7 +69,7 @@ module Jekyll ...@@ -71,7 +69,7 @@ module Jekyll
end end
opts.on('-L', '--label LABEL') do |label| opts.on('-L', '--label LABEL') do |label|
@label = label labels << label
end end
opts.on('-o', '--offset OFFSET') do |offset| opts.on('-o', '--offset OFFSET') do |offset|
...@@ -112,6 +110,10 @@ module Jekyll ...@@ -112,6 +110,10 @@ module Jekyll
@locators ||= [] @locators ||= []
end end
def labels
@labels ||= []
end
def bibtex_files def bibtex_files
@bibtex_files ||= [config['bibliography']] @bibtex_files ||= [config['bibliography']]
end end
...@@ -568,7 +570,7 @@ module Jekyll ...@@ -568,7 +570,7 @@ module Jekyll
end end
def render_citation(items) def render_citation(items)
renderer.render items.zip(locators).map { |entry, locator| renderer.render items.zip(locators.zip(labels)).map { |entry, (locator, label)|
cited_keys << entry.key cited_keys << entry.key
cited_keys.uniq! cited_keys.uniq!
......
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