@@ -7,7 +7,7 @@ import re | |||||
from hyde.model import Expando | from hyde.model import Expando | ||||
from hyde.plugin import Plugin | from hyde.plugin import Plugin | ||||
from hyde.site import Node, Resource | from hyde.site import Node, Resource | ||||
from hyde.util import add_method | |||||
from hyde.util import add_method, pairwalk | |||||
from collections import namedtuple | from collections import namedtuple | ||||
from functools import partial | from functools import partial | ||||
@@ -148,6 +148,18 @@ class GrouperPlugin(Plugin): | |||||
return | return | ||||
if not hasattr(self.site, 'grouper'): | if not hasattr(self.site, 'grouper'): | ||||
self.site.grouper = {} | self.site.grouper = {} | ||||
for name, grouping in self.site.config.grouper.__dict__.items(): | for name, grouping in self.site.config.grouper.__dict__.items(): | ||||
grouping.name = name | grouping.name = name | ||||
self.site.grouper[name] = Group(grouping) | |||||
prev_att = 'prev_in_%s' % name | |||||
next_att = 'next_in_%s' % name | |||||
setattr(Resource, prev_att, None) | |||||
setattr(Resource, next_att, None) | |||||
self.site.grouper[name] = Group(grouping) | |||||
walker = Group.walk_resources( | |||||
self.site.content, self.site.grouper[name]) | |||||
for prev, next in pairwalk(walker): | |||||
print ("%s => %s" % (prev.name, next.name)) | |||||
setattr(next, prev_att, prev) | |||||
setattr(prev, next_att, next) |
@@ -7,17 +7,12 @@ import re | |||||
from hyde.model import Expando | from hyde.model import Expando | ||||
from hyde.plugin import Plugin | from hyde.plugin import Plugin | ||||
from hyde.site import Node, Resource | from hyde.site import Node, Resource | ||||
from hyde.util import add_method | |||||
from hyde.util import add_method, pairwalk | |||||
from itertools import ifilter | |||||
from functools import partial | from functools import partial | ||||
from itertools import ifilter, izip, tee, product | |||||
from operator import attrgetter | from operator import attrgetter | ||||
def pairwalk(iterable): | |||||
a, b = tee(iterable) | |||||
next(b, None) | |||||
return izip(a, b) | |||||
def filter_method(item, settings=None): | def filter_method(item, settings=None): | ||||
""" | """ | ||||
Returns true if all the filters in the | Returns true if all the filters in the | ||||
@@ -129,6 +129,28 @@ class TestGrouperSingleLevel(object): | |||||
plugin_resources = [resource.name for resource in self.s.content.walk_resources_grouped_by_plugins()] | plugin_resources = [resource.name for resource in self.s.content.walk_resources_grouped_by_plugins()] | ||||
assert plugin_resources == self.plugins | assert plugin_resources == self.plugins | ||||
def test_prev_next(self): | |||||
resources = [] | |||||
for page in self.all: | |||||
resources.append(self.s.content.resource_from_relative_path('blog/' + page)) | |||||
index = 0 | |||||
for res in resources: | |||||
if index < 4: | |||||
assert res.next_in_section.name == self.all[index + 1] | |||||
else: | |||||
assert not res.next_in_section | |||||
index += 1 | |||||
index = 0 | |||||
for res in resources: | |||||
if index: | |||||
assert res.prev_in_section.name == self.all[index - 1] | |||||
else: | |||||
assert not res.prev_in_section | |||||
index += 1 | |||||
def test_nav_with_grouper(self): | def test_nav_with_grouper(self): | ||||
text =""" | text =""" | ||||
{% for group, resources in site.content.walk_section_groups() %} | {% for group, resources in site.content.walk_section_groups() %} | ||||
@@ -3,6 +3,7 @@ Module for python 2.6 compatibility. | |||||
""" | """ | ||||
import logging | import logging | ||||
import sys | import sys | ||||
from itertools import ifilter, izip, tee | |||||
try: | try: | ||||
from logging import NullHandler | from logging import NullHandler | ||||
@@ -94,4 +95,9 @@ def make_method(method_name, method_): | |||||
def add_method(obj, method_name, method_, *args, **kwargs): | def add_method(obj, method_name, method_, *args, **kwargs): | ||||
from functools import partial | from functools import partial | ||||
m = make_method(method_name, partial(method_, *args, **kwargs)) | m = make_method(method_name, partial(method_, *args, **kwargs)) | ||||
setattr(obj, method_name, m) | |||||
setattr(obj, method_name, m) | |||||
def pairwalk(iterable): | |||||
a, b = tee(iterable) | |||||
next(b, None) | |||||
return izip(a, b) |