Commit bac7a87d authored by Sylvester Keil's avatar Sylvester Keil

Allow local override of group_order

See #129
parent 4ef567dc
......@@ -335,10 +335,12 @@ Feature: Grouping BibTeX Bibliographies
Then I should not see "<h2 class=\"bibliography\">2007</h2>" in "_site/scholar.html"
And I should not see "<h2 class=\"bibliography\">2008</h2>" in "_site/scholar.html"
@tags @grouping
@tags @grouping @wip
Scenario: Local grouping override - grouping by year
Given I have a scholar configuration with:
| group_by | none |
| key | value |
| group_by | none |
| group_order | ascending |
And I have a "_bibliography" directory
And I have a file "_bibliography/references.bib":
"""
......@@ -359,10 +361,11 @@ Feature: Grouping BibTeX Bibliographies
"""
---
---
{% bibliography -f references --group_by year %}
{% bibliography -f references --group_by year --group_order descending %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
Then I should see "<h2 class=\"bibliography\">2007</h2>" in "_site/scholar.html"
And I should see "<h2 class=\"bibliography\">2008</h2>" in "_site/scholar.html"
And "2008" should come before "2007" in "_site/scholar.html"
......@@ -89,12 +89,16 @@ module Jekyll
@group_by = group_by
end
opts.on('-G', '--group_order ORDER') do |group_order|
self.group_order = group_order
end
opts.on('-T', '--template TEMPLATE') do |template|
@bibliography_template = template
end
end
argv = arguments.split(/(\B-[cCfqrptTsglomA]|\B--(?:cited(_in_order)?|file|query|relative|prefix|text|style|group_by|template|locator|offset|max|suppress_author|))/)
argv = arguments.split(/(\B-[cCfqrptTsgGlomA]|\B--(?:cited(_in_order)?|file|query|relative|prefix|text|style|group_(?:by|order)|template|locator|offset|max|suppress_author|))/)
parser.parse argv.map(&:strip).reject(&:empty?)
end
......@@ -181,7 +185,7 @@ module Jekyll
end
.find { |c| c != 0 } || 0
end
sorted
end
......@@ -211,20 +215,21 @@ module Jekyll
end
def group(ungrouped)
def grouper(items,keys,order)
groups = items
.group_by do |item|
group_value(keys.first,item)
end
def grouper(items, keys, order)
groups = items.group_by do |item|
group_value(keys.first, item)
end
if keys.count == 1
groups
else
groups.merge(groups) do |key,items|
grouper(items,keys.drop(1),order.drop(1))
groups.merge(groups) do |key, items|
grouper(items, keys.drop(1), order.drop(1))
end
end
end
grouper(ungrouped,group_keys,group_order)
grouper(ungrouped, group_keys, group_order)
end
def group_keys
......@@ -237,9 +242,12 @@ module Jekyll
end
def group_order
return @group_order unless @group_order.nil?
self.group_order = config['group_order'] if @group_order.nil?
@group_order
end
@group_order = Array(config['group_order'])
def group_order=(value)
@group_order = Array(value)
.map { |key| key.to_s.split(/\s*,\s*/) }
.flatten
end
......
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