Commit 004f7d08 authored by Sylvester Keil's avatar Sylvester Keil

add max option

parent 6c6b1142
......@@ -37,3 +37,37 @@ Feature: BibTeX
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 @max
Scenario: Limit number of entries
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 --max 1 %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
And I should not see "Programming Ruby" in "_site/scholar.html"
And I should see "The Ruby Programming Language" in "_site/scholar.html"
......@@ -21,6 +21,8 @@ module Jekyll
cited_references.include? e.key
end if cited_only?
references = references.take(max.to_i) if limit_entries?
bibliography = references.each_with_index.map { |entry, index|
reference = bibliography_tag(entry, index + 1)
......
......@@ -15,7 +15,7 @@ module Jekyll
module Utilities
attr_reader :config, :site, :query,
:context, :prefix, :keys, :text
:context, :prefix, :keys, :text, :max
def split_arguments(arguments)
......@@ -56,6 +56,10 @@ module Jekyll
locators << locator
end
opts.on('-m', '--max MAX') do |max|
@max = max
end
opts.on('-s', '--style STYLE') do |style|
@style = style
end
......@@ -65,7 +69,7 @@ module Jekyll
end
end
argv = arguments.split(/(\B-[cfqptTsl]|\B--(?:cited|file|query|prefix|text|style|template|locator|))/)
argv = arguments.split(/(\B-[cfqptTslm]|\B--(?:cited|file|query|prefix|text|style|template|locator|max|))/)
parser.parse argv.map(&:strip).reject(&:empty?)
end
......@@ -119,6 +123,10 @@ module Jekyll
sort bibliography[query || config['query']]
end
def limit_entries?
!max.nil?
end
def sort(unsorted)
return unsorted if config['sort_by'] == 'none'
......
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