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 ...@@ -335,10 +335,12 @@ Feature: Grouping BibTeX Bibliographies
Then I should not see "<h2 class=\"bibliography\">2007</h2>" in "_site/scholar.html" 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" 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 Scenario: Local grouping override - grouping by year
Given I have a scholar configuration with: 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 "_bibliography" directory
And I have a file "_bibliography/references.bib": And I have a file "_bibliography/references.bib":
""" """
...@@ -359,10 +361,11 @@ Feature: Grouping BibTeX Bibliographies ...@@ -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 When I run jekyll
Then the _site directory should exist Then the _site directory should exist
And the "_site/scholar.html" file should exist And the "_site/scholar.html" file should exist
Then I should see "<h2 class=\"bibliography\">2007</h2>" in "_site/scholar.html" 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 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 ...@@ -89,12 +89,16 @@ module Jekyll
@group_by = group_by @group_by = group_by
end end
opts.on('-G', '--group_order ORDER') do |group_order|
self.group_order = group_order
end
opts.on('-T', '--template TEMPLATE') do |template| opts.on('-T', '--template TEMPLATE') do |template|
@bibliography_template = template @bibliography_template = template
end end
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?) parser.parse argv.map(&:strip).reject(&:empty?)
end end
...@@ -181,7 +185,7 @@ module Jekyll ...@@ -181,7 +185,7 @@ module Jekyll
end end
.find { |c| c != 0 } || 0 .find { |c| c != 0 } || 0
end end
sorted sorted
end end
...@@ -211,20 +215,21 @@ module Jekyll ...@@ -211,20 +215,21 @@ module Jekyll
end end
def group(ungrouped) def group(ungrouped)
def grouper(items,keys,order) def grouper(items, keys, order)
groups = items groups = items.group_by do |item|
.group_by do |item| group_value(keys.first, item)
group_value(keys.first,item) end
end
if keys.count == 1 if keys.count == 1
groups groups
else else
groups.merge(groups) do |key,items| groups.merge(groups) do |key, items|
grouper(items,keys.drop(1),order.drop(1)) grouper(items, keys.drop(1), order.drop(1))
end end
end end
end end
grouper(ungrouped,group_keys,group_order)
grouper(ungrouped, group_keys, group_order)
end end
def group_keys def group_keys
...@@ -237,9 +242,12 @@ module Jekyll ...@@ -237,9 +242,12 @@ module Jekyll
end end
def group_order 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*/) } .map { |key| key.to_s.split(/\s*,\s*/) }
.flatten .flatten
end 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