Commit 15ef9e20 authored by egon w. stemle's avatar egon w. stemle

Add --offset filter option to accompany --max

parent 9ac906e3
......@@ -72,6 +72,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:
......
......@@ -29,7 +29,11 @@ module Jekyll
end
end
items = items.take(max.to_i) if limit_entries?
# this also allows for --max {...,-2,-1,0,1,...}
if max > -1
@max = offset + max - 1
end
items = items[offset..max]
bibliography = items.each_with_index.map { |entry, index|
reference = bibliography_tag(entry, index + 1)
......
......@@ -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)
......@@ -27,6 +27,8 @@ module Jekyll
end
def optparse(arguments)
@offset = 0 # set default
@max = -1 # set default
return if arguments.nil? || arguments.empty?
parser = OptionParser.new do |opts|
......@@ -63,8 +65,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 +82,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,10 +141,6 @@ module Jekyll
sort bibliography[query || config['query']]
end
def limit_entries?
!max.nil?
end
def sort(unsorted)
return unsorted if skip_sort?
......
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