From 0143eb4cdc94ec4eb3d85eb795590a6dedb1745d Mon Sep 17 00:00:00 2001 From: Sylvester Keil Date: Mon, 25 Apr 2016 11:33:45 +0200 Subject: [PATCH] Support multiple locator labels See #147 --- README.md | 9 +++++++-- features/citation.feature | 35 ++++++++++++++++++++++++++++++++- lib/jekyll/scholar/utilities.rb | 12 ++++++----- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0cb9cd1..7097471 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/features/citation.feature b/features/citation.feature index 22184ff..fa4cdc0 100644 --- a/features/citation.feature +++ b/features/citation.feature @@ -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": """ @@ -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 diff --git a/lib/jekyll/scholar/utilities.rb b/lib/jekyll/scholar/utilities.rb index 3fe1dc5..079a098 100644 --- a/lib/jekyll/scholar/utilities.rb +++ b/lib/jekyll/scholar/utilities.rb @@ -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) @@ -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| @@ -112,6 +110,10 @@ def locators @locators ||= [] end + def labels + @labels ||= [] + end + def bibtex_files @bibtex_files ||= [config['bibliography']] end @@ -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!