From ae7e4854748ea7e892e44c122a457080ff055ff0 Mon Sep 17 00:00:00 2001 From: Anatol Broder Date: Wed, 7 May 2014 23:35:06 +0200 Subject: [PATCH 01/12] Add hash_property --- lib/jekyll/filters.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index 72d12868..687ab02a 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -213,12 +213,12 @@ module Jekyll end input.sort { |a, b| - if !a[key].nil? && b[key].nil? + if !hash_property(a, key).nil? && hash_property(b, key).nil? - order - elsif a[key].nil? && !b[key].nil? + elsif hash_property(a, key).nil? && !hash_property(b, key).nil? + order else - a[key] <=> b[key] + hash_property(a, key) <=> hash_property(b, key) end } end @@ -250,5 +250,15 @@ module Jekyll item[property.to_s] end end + + def hash_property(hash, property) + if hash.respond_to?('[]'.freeze) + hash[property] + elsif hash.respond_to?(property) + hash.send(property) + else + nil + end + end end end From 9f6965c1b5706834ca35bd49e52affc1515409a3 Mon Sep 17 00:00:00 2001 From: Anatol Broder Date: Thu, 8 May 2014 00:31:42 +0200 Subject: [PATCH 02/12] Add scenario for sorting by title --- features/collections.feature | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/collections.feature b/features/collections.feature index 8b69ab67..1c3c8e23 100644 --- a/features/collections.feature +++ b/features/collections.feature @@ -101,7 +101,8 @@ Feature: Collections And I have a "_config.yml" file with content: """ collections: - - methods + methods: + output: true """ When I run jekyll build Then the _site directory should exist From d8e68bc0e12773d5a21409082517cbeec4099721 Mon Sep 17 00:00:00 2001 From: Anatol Broder Date: Thu, 8 May 2014 00:45:15 +0200 Subject: [PATCH 03/12] No output needed --- features/collections.feature | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/features/collections.feature b/features/collections.feature index 1c3c8e23..8b69ab67 100644 --- a/features/collections.feature +++ b/features/collections.feature @@ -101,8 +101,7 @@ Feature: Collections And I have a "_config.yml" file with content: """ collections: - methods: - output: true + - methods """ When I run jekyll build Then the _site directory should exist From 9ba89b9ab1568b095ee0474dfeef00f79e891e38 Mon Sep 17 00:00:00 2001 From: Anatol Broder Date: Thu, 8 May 2014 01:08:14 +0200 Subject: [PATCH 04/12] Try item_property --- lib/jekyll/filters.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index 687ab02a..50cfea48 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -252,6 +252,7 @@ module Jekyll end def hash_property(hash, property) + return item_property(hash, property) if hash.respond_to?('[]'.freeze) hash[property] elsif hash.respond_to?(property) From fd1778203dace01c549c8726fb21b326d24cce17 Mon Sep 17 00:00:00 2001 From: Anatol Broder Date: Thu, 8 May 2014 07:24:04 +0200 Subject: [PATCH 05/12] Make it fail --- lib/jekyll/filters.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index 50cfea48..0478eeff 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -252,7 +252,7 @@ module Jekyll end def hash_property(hash, property) - return item_property(hash, property) + return hash[property] if hash.respond_to?('[]'.freeze) hash[property] elsif hash.respond_to?(property) From d96f39360b80d3f59425fd011c25b97bb499ccfc Mon Sep 17 00:00:00 2001 From: Anatol Broder Date: Thu, 8 May 2014 07:42:47 +0200 Subject: [PATCH 06/12] Revert "Make it fail" This reverts commit c89e7539b86a483a2f8b14dd766ad90da1eb9773. --- lib/jekyll/filters.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index 0478eeff..50cfea48 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -252,7 +252,7 @@ module Jekyll end def hash_property(hash, property) - return hash[property] + return item_property(hash, property) if hash.respond_to?('[]'.freeze) hash[property] elsif hash.respond_to?(property) From df3c163eebbb23a10c32266da9ae653b4d5a604d Mon Sep 17 00:00:00 2001 From: Anatol Broder Date: Thu, 8 May 2014 07:47:43 +0200 Subject: [PATCH 07/12] Use item_property --- lib/jekyll/filters.rb | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index 50cfea48..67c8f264 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 @@ -213,12 +213,15 @@ module Jekyll end input.sort { |a, b| - if !hash_property(a, key).nil? && hash_property(b, key).nil? + a_p = item_property(a, property) + b_p = item_property(b, property) + + if !a_p.nil? && b_p.nil? - order - elsif hash_property(a, key).nil? && !hash_property(b, key).nil? + elsif a_p.nil? && !b_p.nil? + order else - hash_property(a, key) <=> hash_property(b, key) + a_p <=> b_p end } end @@ -250,16 +253,5 @@ module Jekyll item[property.to_s] end end - - def hash_property(hash, property) - return item_property(hash, property) - if hash.respond_to?('[]'.freeze) - hash[property] - elsif hash.respond_to?(property) - hash.send(property) - else - nil - end - end end end From 7f1b916f32f0f5a09ef4d1d8b327ca5431674c98 Mon Sep 17 00:00:00 2001 From: Anatol Broder Date: Thu, 8 May 2014 08:17:30 +0200 Subject: [PATCH 08/12] Fix output --- features/collections.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/collections.feature b/features/collections.feature index 8b69ab67..00c56c56 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.

\n\n

Whatever: foo.bar

\n

Jekyll.sanitized_path is used to make sure your path is in your source.

\n

Run your generators! default

\n

Create dat site.

\n

Run your generators! default

" in "_site/index.html" + And I should see "Collections:

Use Jekyll.configuration to build a full configuration for use w/Jekyll.

\n\n

Whatever: foo.bar

\n

Jekyll.sanitized_path is used to make sure your path is in your source.

\n

Run your generators! default

\n

Page without title.

\n

Run your generators! default

" in "_site/index.html" And the "_site/methods/configuration.html" file should not exist Scenario: Rendered collection From 6c48e9bbdf0e4ae9fa774814050c9ab17c589dc9 Mon Sep 17 00:00:00 2001 From: Anatol Broder Date: Thu, 8 May 2014 08:37:32 +0200 Subject: [PATCH 09/12] Simplify config --- features/collections.feature | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/features/collections.feature b/features/collections.feature index 00c56c56..87ae0b5e 100644 --- a/features/collections.feature +++ b/features/collections.feature @@ -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 From 5dcd84b71bd4a89805ec9a2063bb25ca2c89c53e Mon Sep 17 00:00:00 2001 From: Anatol Broder Date: Fri, 9 May 2014 08:56:04 +0200 Subject: [PATCH 10/12] Resolve conflict --- features/collections.feature | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/features/collections.feature b/features/collections.feature index 87ae0b5e..5c75677f 100644 --- a/features/collections.feature +++ b/features/collections.feature @@ -105,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" From ab3aaebe6d877185a01d9287faf2fe8d7063f00a Mon Sep 17 00:00:00 2001 From: Anatol Broder Date: Fri, 9 May 2014 08:59:46 +0200 Subject: [PATCH 11/12] Resolve second conflict --- test/source/_methods/site/initialize.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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. From fb523722b572c4aa7aaf9df4e6d1692479d6d980 Mon Sep 17 00:00:00 2001 From: Anatol Broder Date: Fri, 9 May 2014 09:21:24 +0200 Subject: [PATCH 12/12] Fruity variables --- lib/jekyll/filters.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index 67c8f264..5e96061f 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -212,16 +212,16 @@ module Jekyll exit(1) end - input.sort { |a, b| - a_p = item_property(a, property) - b_p = item_property(b, property) + input.sort { |apple, orange| + apple_property = item_property(apple, property) + orange_property = item_property(orange, property) - if !a_p.nil? && b_p.nil? + if !apple_property.nil? && orange_property.nil? - order - elsif a_p.nil? && !b_p.nil? + elsif apple_property.nil? && !orange_property.nil? + order else - a_p <=> b_p + apple_property <=> orange_property end } end