Skip to content

Commit

Permalink
Support multiple locator labels
Browse files Browse the repository at this point in the history
See #147
  • Loading branch information
inukshuk committed Apr 25, 2016
1 parent a4adcb4 commit 0143eb4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
9 changes: 7 additions & 2 deletions README.md
Expand Up @@ -361,13 +361,18 @@ like: `...as Matz explains (2008, p. 42)`.

#### 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
If you would like to add page numbers or similar locators to your citation,
use the `-l` or `--locator` option. For example, `{% cite ruby --locator 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 %}`.

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

If you want to display the full formatted reference entry, you can use the
Expand Down
35 changes: 34 additions & 1 deletion features/citation.feature
Expand Up @@ -250,6 +250,39 @@ Feature: Citations
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 --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":
"""
Expand All @@ -260,7 +293,7 @@ Feature: Citations
When I run jekyll
Then the _site directory 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
Scenario: Multiple citations using citation numbers
Expand Down
12 changes: 7 additions & 5 deletions lib/jekyll/scholar/utilities.rb
Expand Up @@ -18,9 +18,7 @@ class Scholar
module Utilities


attr_reader :config, :site, :context,
:prefix, :text, :offset, :max, :label

attr_reader :config, :site, :context, :prefix, :text, :offset, :max


def split_arguments(arguments)
Expand Down Expand Up @@ -71,7 +69,7 @@ def optparse(arguments)
end

opts.on('-L', '--label LABEL') do |label|
@label = label
labels << label
end

opts.on('-o', '--offset OFFSET') do |offset|
Expand Down Expand Up @@ -112,6 +110,10 @@ def locators
@locators ||= []
end

def labels
@labels ||= []
end

def bibtex_files
@bibtex_files ||= [config['bibliography']]
end
Expand Down Expand Up @@ -568,7 +570,7 @@ def renderer(force = false)
end

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.uniq!

Expand Down

0 comments on commit 0143eb4

Please sign in to comment.