Beispiel #1
0
    def begin_site(self):
        """
        Initialize plugin. Add a sort and match method
        for every configuration mentioned in site settings
        """

        config = self.site.config
        if not hasattr(config, 'sorter'):
            return

        for name, settings in config.sorter.__dict__.items():
            sort_method_name = 'walk_resources_sorted_by_%s' % name
            self.logger.debug("Adding sort methods for [%s]" % name)
            add_method(Node, sort_method_name, sort_method, settings=settings)
            match_method_name = 'is_%s' % name
            add_method(Resource, match_method_name, filter_method, settings)

            prev_att = 'prev_by_%s' % name
            next_att = 'next_by_%s' % name

            setattr(Resource, prev_att, None)
            setattr(Resource, next_att, None)

            walker = getattr(self.site.content,
                                sort_method_name,
                                self.site.content.walk_resources)
            for prev, next in pairwalk(walker()):
                setattr(prev, next_att, next)
                setattr(next, prev_att, prev)
Beispiel #2
0
    def walk_paged_resources(self, node, resource):
        """
        Group the resources and return the new page resources.
        """
        added_resources = []
        pages = list(self._walk_pages_in_node(node))
        resource.pages = pages
        if pages:
            deps = reduce(list.__add__, [page.posts for page in pages], [])

            Paginator._attach_page_to_resource(pages[0], resource)
            Paginator._add_dependencies_to_resource(deps, resource)
            for page in pages[1:]:
                # make new resource
                new_resource = self._new_resource(resource, node, page.number)
                Paginator._attach_page_to_resource(page, new_resource)
                new_resource.depends = resource.depends
                added_resources.append(new_resource)
                new_resource.pages = pages

            for prev, next in pairwalk(pages):
                next.previous = prev
                prev.next = next

        return added_resources
Beispiel #3
0
    def begin_site(self):
        """
        Initialize plugin. Add a sort and match method
        for every configuration mentioned in site settings
        """

        config = self.site.config
        if not hasattr(config, 'sorter'):
            return

        for name, settings in config.sorter.__dict__.items():
            sort_method_name = 'walk_resources_sorted_by_%s' % name
            self.logger.debug("Adding sort methods for [%s]" % name)
            add_method(Node, sort_method_name, sort_method, settings=settings)
            match_method_name = 'is_%s' % name
            add_method(Resource, match_method_name, filter_method, settings)

            prev_att = 'prev_by_%s' % name
            next_att = 'next_by_%s' % name

            setattr(Resource, prev_att, None)
            setattr(Resource, next_att, None)

            walker = getattr(self.site.content, sort_method_name,
                             self.site.content.walk_resources)
            for prev, next in pairwalk(walker()):
                setattr(prev, next_att, next)
                setattr(next, prev_att, prev)
Beispiel #4
0
    def walk_paged_resources(self, node, resource):
        """
        Group the resources and return the new page resources.
        """
        added_resources = []
        pages = list(self._walk_pages_in_node(node))
        resource.pages = pages
        if pages:
            deps = reduce(list.__add__, [page.posts for page in pages], [])

            Paginator._attach_page_to_resource(pages[0], resource)
            Paginator._add_dependencies_to_resource(deps, resource)
            for page in pages[1:]:
                # make new resource
                new_resource = self._new_resource(resource, node, page.number)
                Paginator._attach_page_to_resource(page, new_resource)
                new_resource.depends = resource.depends
                added_resources.append(new_resource)
                new_resource.pages = pages

            for prev, next in pairwalk(pages):
                next.previous = prev
                prev.next = next

        return added_resources
Beispiel #5
0
    def begin_site(self):
        """
        Initialize plugin. Add the specified groups to the
        site context variable.
        """
        config = self.site.config
        if not hasattr(config, 'grouper'):
            return
        if not hasattr(self.site, 'grouper'):
            self.site.grouper = {}

        self.site.groups_index = {}
        for name, grouping in self.site.config.grouper.__dict__.items():
            grouping.name = name
            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):
                setattr(next, prev_att, prev)
                setattr(prev, next_att, next)

            for group in self.site.grouper[name].walk_groups():
                self.site.groups_index[group.name] = group #NOT_HAPPY: I found no other way to directly access groups by names from jinja ;(
                self._create_group_archive(group.archives,group.name)
Beispiel #6
0
    def __init__(self, site):
        for name, settings in site.config.sorter.__dict__.items():
            method = partial(
                sort_method,
                settings=settings)

            setattr(self, name, method)

            prev_att = 'prev_by_%s' % name
            next_att = 'next_by_%s' % name

            setattr(Resource, prev_att, None)
            setattr(Resource, next_att, None)

            walker = method(site.content)
            for prev, next in pairwalk(walker):
                setattr(prev, next_att, next)
                setattr(next, prev_att, prev)
Beispiel #7
0
    def begin_site(self):
        """
        Initialize plugin. Add a sort and match method
        for every configuration mentioned in site settings
        """

        config = self.site.config
        if not hasattr(config, 'sorter'):
            return

        for name, settings in list(config.sorter.__dict__.items()):
            sort_method_name = 'walk_resources_sorted_by_%s' % name
            self.logger.debug("Adding sort methods for [%s]" % name)
            add_method(Node, sort_method_name, sort_method, settings=settings)
            match_method_name = 'is_%s' % name
            add_method(Resource, match_method_name, filter_method, settings)

            prev_att = 'prev_by_%s' % name
            next_att = 'next_by_%s' % name

            setattr(Resource, prev_att, None)
            setattr(Resource, next_att, None)

            walker = getattr(self.site.content,
                             sort_method_name,
                             self.site.content.walk_resources)
            first, last = None, None
            for prev, next in pairwalk(walker()):
                if not first:
                    first = prev
                last = next
                setattr(prev, next_att, next)
                setattr(next, prev_att, prev)

            try:
                circular = settings.circular
            except AttributeError:
                circular = False

            if circular and first:
                setattr(first, prev_att, last)
                setattr(last, next_att, first)
Beispiel #8
0
    def begin_site(self):
        """
        Initialize plugin. Add a sort and match method
        for every configuration mentioned in site settings
        """

        config = self.site.config
        if not hasattr(config, 'sorter'):
            return

        for name, settings in list(config.sorter.__dict__.items()):
            sort_method_name = 'walk_resources_sorted_by_%s' % name
            self.logger.debug("Adding sort methods for [%s]" % name)
            add_method(Node, sort_method_name, sort_method, settings=settings)
            match_method_name = 'is_%s' % name
            add_method(Resource, match_method_name, filter_method, settings)

            prev_att = 'prev_by_%s' % name
            next_att = 'next_by_%s' % name

            setattr(Resource, prev_att, None)
            setattr(Resource, next_att, None)

            walker = getattr(self.site.content, sort_method_name,
                             self.site.content.walk_resources)
            first, last = None, None
            for prev, next in pairwalk(walker()):
                if not first:
                    first = prev
                last = next
                setattr(prev, next_att, next)
                setattr(next, prev_att, prev)

            try:
                circular = settings.circular
            except AttributeError:
                circular = False

            if circular and first:
                setattr(first, prev_att, last)
                setattr(last, next_att, first)
Beispiel #9
0
    def begin_site(self):
        """
        Initialize plugin. Add the specified groups to the
        site context variable.
        """
        config = self.site.config
        if not hasattr(config, 'grouper'):
            return
        if not hasattr(self.site, 'grouper'):
            self.site.grouper = {}

        for name, grouping in self.site.config.grouper.__dict__.items():
            grouping.name = name
            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):
                setattr(next, prev_att, prev)
                setattr(prev, next_att, next)
Beispiel #10
0
    def begin_site(self):
        """
        Initialize plugin. Add the specified groups to the
        site context variable.
        """
        config = self.site.config
        if not hasattr(config, 'grouper'):
            return
        if not hasattr(self.site, 'grouper'):
            self.site.grouper = {}

        for name, grouping in self.site.config.grouper.__dict__.items():
            grouping.name = name
            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):
                setattr(next, prev_att, prev)
                setattr(prev, next_att, next)