Merge pull request #2345 from penibelst/sort-collection

This commit is contained in:
Parker Moore 2014-05-10 15:42:53 -04:00
commit 01c09fd7fa
3 changed files with 37 additions and 12 deletions

View File

@ -9,7 +9,7 @@ Feature: Collections
And I have a configuration file with "collections" set to "['methods']"
When I run jekyll build
Then the _site directory should exist
And I should see "Collections: <p>Use <code>Jekyll.configuration</code> to build a full configuration for use w/Jekyll.</p>\n\n<p>Whatever: foo.bar</p>\n<p><code>Jekyll.sanitized_path</code> is used to make sure your path is in your source.</p>\n<p>Run your generators! default</p>\n<p>Create dat site.</p>\n<p>Run your generators! default</p>" in "_site/index.html"
And I should see "Collections: <p>Use <code>Jekyll.configuration</code> to build a full configuration for use w/Jekyll.</p>\n\n<p>Whatever: foo.bar</p>\n<p><code>Jekyll.sanitized_path</code> is used to make sure your path is in your source.</p>\n<p>Run your generators! default</p>\n<p>Page without title.</p>\n<p>Run your generators! default</p>" in "_site/index.html"
And the "_site/methods/configuration.html" file should not exist
Scenario: Rendered collection
@ -64,8 +64,7 @@ Feature: Collections
And I have a "_config.yml" file with content:
"""
collections:
methods:
baz: bin
- methods
"""
When I run jekyll build
Then the _site directory should exist
@ -106,3 +105,27 @@ Feature: Collections
When I run jekyll build
Then the _site directory should exist
And I should see "Item count: 1" in "_site/index.html"
Scenario: Sort by title
Given I have an "index.html" page that contains "{% assign items = site.methods | sort: 'title' %}1. of {{ items.size }}: {{ items.first.output }}"
And I have fixture collections
And I have a "_config.yml" file with content:
"""
collections:
- methods
"""
When I run jekyll build
Then the _site directory should exist
And I should see "1. of 5: <p>Page without title.</p>" in "_site/index.html"
Scenario: Sort by relative_path
Given I have an "index.html" page that contains "Collections: {% assign methods = site.methods | sort: 'relative_path' %}{% for method in methods %}{{ method.title }}, {% endfor %}"
And I have fixture collections
And I have a "_config.yml" file with content:
"""
collections:
- methods
"""
When I run jekyll build
Then the _site directory should exist
And I should see "Collections: Jekyll.configuration, Jekyll.sanitized_path, Site#generate, , Site#generate," in "_site/index.html"

View File

@ -193,12 +193,12 @@ module Jekyll
# Sort an array of objects
#
# input - the object array
# key - key within each object to filter by
# property - property within each object to filter by
# nils ('first' | 'last') - nils appear before or after non-nil values
#
# Returns the filtered array of objects
def sort(input, key = nil, nils = "first")
if key.nil?
def sort(input, property = nil, nils = "first")
if property.nil?
input.sort
else
case
@ -212,13 +212,16 @@ module Jekyll
exit(1)
end
input.sort { |a, b|
if !a[key].nil? && b[key].nil?
input.sort { |apple, orange|
apple_property = item_property(apple, property)
orange_property = item_property(orange, property)
if !apple_property.nil? && orange_property.nil?
- order
elsif a[key].nil? && !b[key].nil?
elsif apple_property.nil? && !orange_property.nil?
+ order
else
a[key] <=> b[key]
apple_property <=> orange_property
end
}
end

View File

@ -1,5 +1,4 @@
---
title: "Site#initialize"
---
Create dat site.
Page without title.