diff --git a/features/filter.feature b/features/filter.feature index 26522154b4ee49821c7e039340a45b1c73e103bc..aac02a7dd424f9823c4d44d7d277b3bca7da318c 100644 --- a/features/filter.feature +++ b/features/filter.feature @@ -106,6 +106,40 @@ Feature: BibTeX And I should not see "Programming Ruby" in "_site/scholar.html" And I should see "The Ruby Programming Language" in "_site/scholar.html" + @tags @offset + Scenario: Start listing entries with an offset + 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{pickaxe, + title = {Programming Ruby 1.9: The Pragmatic Programmer's Guide}, + author = {Thomas, Dave and Fowler, Chad and Hunt, Andy}, + year = {2009}, + edition = 3, + publisher = {Pragmatic Bookshelf} + } + """ + And I have a page "scholar.html": + """ + --- + --- + {% bibliography --offset 1 %} + """ + When I run jekyll + Then the _site directory should exist + And the "_site/scholar.html" file should exist + And I should see "Programming Ruby" in "_site/scholar.html" + And I should not see "The Ruby Programming Language" in "_site/scholar.html" + @tags @urls Scenario: URLs as text Given I have a scholar configuration with: diff --git a/lib/jekyll/scholar/tags/bibliography.rb b/lib/jekyll/scholar/tags/bibliography.rb index b774f63275514ab2c526d7c1b4295804870afd39..5e1e0bdede9823ea2e2fb18382993344c806c428 100644 --- a/lib/jekyll/scholar/tags/bibliography.rb +++ b/lib/jekyll/scholar/tags/bibliography.rb @@ -42,7 +42,7 @@ module Jekyll cited_keys.clear end - items = items.take(max.to_i) if limit_entries? + items = items[offset..max] if limit_entries? bibliography = items.each_with_index.map { |entry, index| reference = bibliography_tag(entry, index + 1) diff --git a/lib/jekyll/scholar/utilities.rb b/lib/jekyll/scholar/utilities.rb index 7cb77827538ae3d45c0e3e7d27853b457f6296ca..8fa9602f9e471e4793d0657fb7e486ce257fc280 100644 --- a/lib/jekyll/scholar/utilities.rb +++ b/lib/jekyll/scholar/utilities.rb @@ -14,7 +14,7 @@ module Jekyll # #site readers module Utilities - attr_reader :config, :site, :context, :prefix, :text, :max + attr_reader :config, :site, :context, :prefix, :text, :offset, :max def split_arguments(arguments) @@ -63,8 +63,12 @@ module Jekyll locators << locator end + opts.on('-o', '--offset OFFSET') do |offset| + @offset = offset.to_i + end + opts.on('-m', '--max MAX') do |max| - @max = max + @max = max.to_i end opts.on('-s', '--style STYLE') do |style| @@ -76,7 +80,7 @@ module Jekyll end end - argv = arguments.split(/(\B-[cCfqptTslmA]|\B--(?:cited(_in_order)?|file|query|prefix|text|style|template|locator|max|suppress_author|))/) + argv = arguments.split(/(\B-[cCfqptTslomA]|\B--(?:cited(_in_order)?|file|query|prefix|text|style|template|locator|offset|max|suppress_author|))/) parser.parse argv.map(&:strip).reject(&:empty?) end @@ -135,8 +139,16 @@ module Jekyll sort bibliography[query || config['query']] end + def offset + @offset ||= 0 + end + + def max + @max.nil? ? -1 : @max + offset - 1 + end + def limit_entries? - !max.nil? + !offset.nil? || !max.nil? end def sort(unsorted)