builtin filter collision rename groupby -> vgroups

This commit is contained in:
relikd
2022-04-06 13:29:19 +02:00
parent 637524a615
commit df4be7c60a
3 changed files with 7 additions and 7 deletions

View File

@@ -20,7 +20,7 @@ main { margin: 3em; }
<footer> <footer>
{%- for k, v in [('testA','Config'),('testB','Simple'),('testC','Advanced')] %} {%- for k, v in [('testA','Config'),('testB','Simple'),('testC','Advanced')] %}
<div>{{v}} Tags: <div>{{v}} Tags:
{%- for x in this|groupby(k, recursive=True)|list|unique|sort %} {%- for x in this|vgroups(k, recursive=True)|unique|sort %}
<a href="{{ x|url }}">({{x.key}})</a> <a href="{{ x|url }}">({{x.key}})</a>
{%- endfor %} {%- endfor %}
</div> </div>

View File

@@ -16,7 +16,7 @@ class GroupByPlugin(Plugin):
def on_setup_env(self, **extra: object) -> None: def on_setup_env(self, **extra: object) -> None:
self.creator = GroupBy() self.creator = GroupBy()
self.env.add_build_program(GroupBySource, GroupByBuildProgram) self.env.add_build_program(GroupBySource, GroupByBuildProgram)
self.env.jinja_env.filters.update(groupby=GroupBySource.of_record) self.env.jinja_env.filters.update(vgroups=GroupBySource.of_record)
# resolve /tag/rss/ -> /tag/rss/index.html (local server only) # resolve /tag/rss/ -> /tag/rss/index.html (local server only)
@self.env.urlresolver @self.env.urlresolver

View File

@@ -147,9 +147,9 @@ class GroupBySource(VirtualSourceObject):
def _reverse_reference_records(self) -> None: def _reverse_reference_records(self) -> None:
''' Attach self to page records. ''' ''' Attach self to page records. '''
for child in self._children: for child in self._children:
if not hasattr(child, '_groupby'): if not hasattr(child, '_vgroups'):
child._groupby = WeakSet() # type: ignore[attr-defined] child._vgroups = WeakSet() # type: ignore[attr-defined]
child._groupby.add(self) # type: ignore[attr-defined] child._vgroups.add(self) # type: ignore[attr-defined]
@staticmethod @staticmethod
def of_record( def of_record(
@@ -169,9 +169,9 @@ class GroupBySource(VirtualSourceObject):
page = proc_list.pop(0) page = proc_list.pop(0)
if recursive and hasattr(page, 'children'): if recursive and hasattr(page, 'children'):
proc_list.extend(page.children) # type: ignore[attr-defined] proc_list.extend(page.children) # type: ignore[attr-defined]
if not hasattr(page, '_groupby'): if not hasattr(page, '_vgroups'):
continue continue
for vobj in page._groupby: # type: ignore[attr-defined] for vobj in page._vgroups: # type: ignore[attr-defined]
if not keys or vobj.config.key in keys: if not keys or vobj.config.key in keys:
yield vobj yield vobj