small fixes
- set child default object to field key - strip whitespace if split - ignore case for sort order - setup.py package instead of module
This commit is contained in:
@@ -42,8 +42,8 @@ class GroupByPlugin(Plugin):
|
|||||||
def _fn(args: GroupByCallbackArgs) -> Iterator[str]:
|
def _fn(args: GroupByCallbackArgs) -> Iterator[str]:
|
||||||
val = args.field
|
val = args.field
|
||||||
if isinstance(val, str):
|
if isinstance(val, str):
|
||||||
val = val.split(split) if split else [val] # make list
|
val = map(str.strip, val.split(split)) if split else [val]
|
||||||
if isinstance(val, list):
|
if isinstance(val, (list, map)):
|
||||||
yield from val
|
yield from val
|
||||||
|
|
||||||
def on_before_build_all(self, builder: Builder, **extra: object) -> None:
|
def on_before_build_all(self, builder: Builder, **extra: object) -> None:
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ class GroupBySource(VirtualSourceObject):
|
|||||||
|
|
||||||
def __lt__(self, other: 'GroupBySource') -> bool:
|
def __lt__(self, other: 'GroupBySource') -> bool:
|
||||||
# Used for |sort filter ("group" is the provided original string)
|
# Used for |sort filter ("group" is the provided original string)
|
||||||
return self.group < other.group
|
return self.group.lower() < other.group.lower()
|
||||||
|
|
||||||
def __eq__(self, other: object) -> bool:
|
def __eq__(self, other: object) -> bool:
|
||||||
# Used for |unique filter
|
# Used for |unique filter
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ class Watcher:
|
|||||||
while True:
|
while True:
|
||||||
if not isinstance(obj, (str, tuple)):
|
if not isinstance(obj, (str, tuple)):
|
||||||
raise TypeError(f'Unsupported groupby yield: {obj}')
|
raise TypeError(f'Unsupported groupby yield: {obj}')
|
||||||
slug = self._persist(record, obj)
|
slug = self._persist(record, key, obj)
|
||||||
# return slugified group key and continue iteration
|
# return slugified group key and continue iteration
|
||||||
if isinstance(_gen, Generator) and not _gen.gi_yieldfrom:
|
if isinstance(_gen, Generator) and not _gen.gi_yieldfrom:
|
||||||
obj = _gen.send(slug)
|
obj = _gen.send(slug)
|
||||||
@@ -159,7 +159,12 @@ class Watcher:
|
|||||||
except StopIteration:
|
except StopIteration:
|
||||||
del _gen
|
del _gen
|
||||||
|
|
||||||
def _persist(self, record: Record, obj: Union[str, tuple]) -> str:
|
def _persist(
|
||||||
|
self,
|
||||||
|
record: Record,
|
||||||
|
key: FieldKeyPath,
|
||||||
|
obj: Union[str, tuple]
|
||||||
|
) -> str:
|
||||||
group = obj if isinstance(obj, str) else obj[0]
|
group = obj if isinstance(obj, str) else obj[0]
|
||||||
slug = self.config.slugify(group)
|
slug = self.config.slugify(group)
|
||||||
# init group-key
|
# init group-key
|
||||||
@@ -174,6 +179,8 @@ class Watcher:
|
|||||||
# (optional) append extra
|
# (optional) append extra
|
||||||
if isinstance(obj, tuple):
|
if isinstance(obj, tuple):
|
||||||
self._state[slug][record].append(obj[1])
|
self._state[slug][record].append(obj[1])
|
||||||
|
else:
|
||||||
|
self._state[slug][record].append(key.flowKey or key.fieldKey)
|
||||||
return slug
|
return slug
|
||||||
|
|
||||||
def iter_sources(self, root: Record) -> Iterator[GroupBySource]:
|
def iter_sources(self, root: Record) -> Iterator[GroupBySource]:
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -5,7 +5,7 @@ with open('README.md') as fp:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='lektor-groupby',
|
name='lektor-groupby',
|
||||||
py_modules=['lektor_groupby'],
|
packages=['lektor_groupby'],
|
||||||
entry_points={
|
entry_points={
|
||||||
'lektor.plugins': [
|
'lektor.plugins': [
|
||||||
'groupby = lektor_groupby:GroupByPlugin',
|
'groupby = lektor_groupby:GroupByPlugin',
|
||||||
|
|||||||
Reference in New Issue
Block a user