Skip to content

Commit

Permalink
Merge pull request #1772 from oSquat/master
Browse files Browse the repository at this point in the history
Add "tag" parameter to ItemList macro
  • Loading branch information
RogerHaase authored Oct 5, 2024
2 parents 180ef3a + 1199662 commit 722805a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/user/creolewiki.rst
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ The **ItemList** macro accepts multiple named parameters: item, startswith, rege
- <<ItemList(ordered='True')>> displays ordered list of subitems, default is unordered
- <<ItemList(startswith="Foo")>> lists subitems starting with Foo
- <<ItemList(regex="Foo$")>> lists subitems ending with Foo
- <<ItemList(tag="template")>> only include items with this tag
- <<ItemList(skiptag="template")>> ignore items with this tag
- <<ItemList(display="FullPath")>> default, displays full path to subitems
- <<ItemList(display="ChildPath")>> displays last component of the FullPath, including the '/'
Expand Down
1 change: 1 addition & 0 deletions docs/user/moinwiki.rst
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,7 @@ The **ItemList** macro accepts multiple named parameters: item, startswith, rege
- <<ItemList(ordered='True')>> displays ordered list of subitems, default is unordered
- <<ItemList(startswith="Foo")>> lists subitems starting with Foo
- <<ItemList(regex="Foo$")>> lists subitems ending with Foo
- <<ItemList(tag="template")>> only include items with this tag
- <<ItemList(skiptag="template")>> ignore items with this tag
- <<ItemList(display="FullPath")>> default, displays full path to subitems
- <<ItemList(display="ChildPath")>> displays last component of the FullPath, including the '/'
Expand Down
7 changes: 6 additions & 1 deletion src/moin/macros/ItemList.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
skiptag: a tag name, items with tag will be skipped
tag: only include items that have been tagged with this name
display: How should the link be displayed?
Options:
Expand Down Expand Up @@ -79,6 +81,7 @@ def macro(self, content, arguments, page_url, alternative):
ordered = False
display = "FullPath"
skiptag = ""
tag = ""

# process input
args = []
Expand Down Expand Up @@ -119,6 +122,8 @@ def macro(self, content, arguments, page_url, alternative):
display = val # let 'create_pagelink_list' throw an exception if needed
elif key == "skiptag":
skiptag = val
elif key == "tag":
tag = val
else:
err_msg = _('Unrecognized key "{key}".').format(key=key)
return fail_message(err_msg, alternative)
Expand All @@ -136,7 +141,7 @@ def macro(self, content, arguments, page_url, alternative):
return fail_message(err_msg, alternative)

# process subitems
children = get_item_names(item, startswith=startswith, skiptag=skiptag)
children = get_item_names(item, startswith=startswith, skiptag=skiptag, tag=tag)
if regex:
try:
regex_re = re.compile(regex, re.IGNORECASE)
Expand Down
10 changes: 9 additions & 1 deletion src/moin/macros/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from moin.constants.keys import TAGS


def get_item_names(name="", startswith="", kind="files", skiptag=""):
def get_item_names(name="", startswith="", kind="files", skiptag="", tag=""):
"""
For the specified item, return the fullname of matching descendents.
Expand All @@ -39,6 +39,8 @@ def get_item_names(name="", startswith="", kind="files", skiptag=""):
skiptag: skip items having this tag
tag: only include items having this tag
Output:
A List of descendent items using their "fullname" value
Expand All @@ -53,11 +55,17 @@ def get_item_names(name="", startswith="", kind="files", skiptag=""):
for item in files:
if skiptag and TAGS in item.meta and skiptag in item.meta[TAGS]:
continue
if tag:
if TAGS not in item.meta or tag not in item.meta[TAGS]:
continue
item_names.append(item.fullname)
if kind == "dirs" or kind == "both":
for item in dirs:
if skiptag and skiptag in item.meta[TAGS]:
continue
if tag:
if TAGS not in item.meta or tag not in item.meta[TAGS]:
continue
item_names.append(item.fullname)
if kind == "both":
item_names = list(set(item_names)) # remove duplicates
Expand Down

0 comments on commit 722805a

Please sign in to comment.