diff --git a/features/collections.feature b/features/collections.feature index 8b69ab67..5c75677f 100644 --- a/features/collections.feature +++ b/features/collections.feature @@ -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:
Use Jekyll.configuration
to build a full configuration for use w/Jekyll.
Whatever: foo.bar
\nJekyll.sanitized_path
is used to make sure your path is in your source.
Run your generators! default
\nCreate dat site.
\nRun your generators! default
" in "_site/index.html" + And I should see "Collections:Use Jekyll.configuration
to build a full configuration for use w/Jekyll.
Whatever: foo.bar
\nJekyll.sanitized_path
is used to make sure your path is in your source.
Run your generators! default
\nPage without title.
\nRun your generators! default
" 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:Page without title.
" 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" diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index 72d12868..5e96061f 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -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 diff --git a/test/source/_methods/site/initialize.md b/test/source/_methods/site/initialize.md index 9c23b967..af5641ce 100644 --- a/test/source/_methods/site/initialize.md +++ b/test/source/_methods/site/initialize.md @@ -1,5 +1,4 @@ --- -title: "Site#initialize" --- -Create dat site. +Page without title.