diff --git a/hyde/ext/plugins/sorter.py b/hyde/ext/plugins/sorter.py index 229e565..c923283 100644 --- a/hyde/ext/plugins/sorter.py +++ b/hyde/ext/plugins/sorter.py @@ -44,8 +44,7 @@ def sort_method(node, settings=None): if settings and hasattr(settings, 'attr') and settings.attr: attr = settings.attr filter_ = partial(filter_method, settings=settings) - resources = sorted(ifilter(filter_, node.walk_resources()), - key=lambda f: f.name) + resources = ifilter(filter_, node.walk_resources()) reverse = False if settings and hasattr(settings, 'reverse'): reverse = settings.reverse diff --git a/hyde/tests/ext/test_sorter.py b/hyde/tests/ext/test_sorter.py index 29aff42..3a3c25c 100644 --- a/hyde/tests/ext/test_sorter.py +++ b/hyde/tests/ext/test_sorter.py @@ -31,7 +31,7 @@ class TestSorter(object): s = Site(TEST_SITE) s.load() s.config.plugins = ['hyde.ext.sorter.SorterPlugin'] - s.config.sorter = Expando(dict(kind=dict(attr='source_file.kind'))) + s.config.sorter = Expando(dict(kind=dict(attr=['source_file.kind', 'name']))) SorterPlugin(s).begin_site() @@ -49,13 +49,13 @@ class TestSorter(object): pages = [page.name for page in s.content.walk_resources_sorted_by_kind()] - assert pages == sorted(sorted(expected), key=lambda f: File(f).kind) + assert pages == sorted(expected, key=lambda f: (File(f).kind, f)) def test_walk_resources_sorted_reverse(self): s = Site(TEST_SITE) s.load() s.config.plugins = ['hyde.ext.sorter.SorterPlugin'] - s.config.sorter = Expando(dict(kind=dict(attr='source_file.kind', reverse=True))) + s.config.sorter = Expando(dict(kind=dict(attr=['source_file.kind', 'name'], reverse=True))) SorterPlugin(s).begin_site() @@ -74,7 +74,7 @@ class TestSorter(object): s.content.walk_resources_sorted_by_kind()] - assert pages == sorted(sorted(expected), key=lambda f: File(f).kind, reverse=True) + assert pages == sorted(expected, key=lambda f: (File(f).kind, f), reverse=True) def test_walk_resources_sorted_with_filters(self): s = Site(TEST_SITE) @@ -110,6 +110,7 @@ class TestSorter(object): attr: - source_file.kind - node.name + - name """ s.config = Config(TEST_SITE, config_dict=yaml.load(cfg)) @@ -131,10 +132,10 @@ class TestSorter(object): expected_sorted = [File(page).name for page in - sorted(sorted(expected), + sorted(expected, key=lambda p: tuple( [File(p).kind, - File(p).parent.name]))] + File(p).parent.name, p]))] assert pages == expected_sorted def test_walk_resources_sorted_no_default_is_processable(self): @@ -146,6 +147,8 @@ class TestSorter(object): kind2: filters: source_file.kind: html + attr: + - name """ s.config = Config(TEST_SITE, config_dict=yaml.load(cfg)) s.load() @@ -169,6 +172,8 @@ class TestSorter(object): kind2: filters: source_file.kind: html + attr: + - name """ s.config = Config(TEST_SITE, config_dict=yaml.load(cfg)) s.load() @@ -201,7 +206,8 @@ class TestSorter(object): - hyde.ext.sorter.SorterPlugin sorter: folder_name: - attr: node.name + attr: + - node.name reverse: True filters: source_file.kind: html diff --git a/hyde/tests/templates/jinja2/index.html b/hyde/tests/templates/jinja2/index.html index 0379820..b006d05 100644 --- a/hyde/tests/templates/jinja2/index.html +++ b/hyde/tests/templates/jinja2/index.html @@ -6,7 +6,7 @@