-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1602 from UlrichB22/titleindex
Add macro TitleIndex
- Loading branch information
Showing
4 changed files
with
152 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Copyright: 2000 Juergen Hermann <[email protected]> | ||
# Copyright: 2008-2011 MoinMoin:ThomasWaldmann | ||
# Copyright: 2024 MoinMoin:UlrichB | ||
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details. | ||
|
||
""" | ||
|
@@ -13,7 +14,7 @@ | |
from moin.utils.iri import Iri | ||
from moin.utils.tree import moin_page, xlink | ||
from moin.items import Item | ||
from moin.macros._base import MacroPageLinkListBase | ||
from moin.macros._base import MacroPageLinkListBase, get_item_names | ||
from moin.storage.middleware.protecting import AccessDenied | ||
|
||
random.seed() | ||
|
@@ -26,7 +27,7 @@ def macro(self, content, arguments, page_url, alternative): | |
else: | ||
item_count = 1 | ||
|
||
all_item_names = self.get_item_names() | ||
all_item_names = get_item_names() | ||
|
||
# Now select random item from the full list, and if it exists and | ||
# we can read it, save. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright: 2024 MoinMoin:UlrichB | ||
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details. | ||
|
||
""" | ||
TitleIndex - generates a list of links for the namespace of the current item, grouped by initials | ||
Parameters: | ||
None | ||
Usage: | ||
<<TitleIndex>> | ||
""" | ||
|
||
from moin.macros._base import MacroMultiLinkListBase, get_item_names | ||
from moin.i18n import _ | ||
from moin.utils.tree import moin_page | ||
from moin.utils.interwiki import split_fqname | ||
|
||
|
||
class Macro(MacroMultiLinkListBase): | ||
def macro(self, content, arguments, page_url, alternative): | ||
# get namespace of current item | ||
namespace = split_fqname(str(page_url.path)).namespace | ||
|
||
if arguments: | ||
raise ValueError(_("TitleList macro does not have any arguments.")) | ||
|
||
children = get_item_names(namespace) | ||
if not children: | ||
empty_list = moin_page.list(attrib={moin_page.item_label_generate: 'unordered'}) | ||
item_body = moin_page.list_item_body(children=[_("<TitleList macro: No matching items were found.>")]) | ||
empty_list.append(moin_page.list_item(children=[item_body])) | ||
return empty_list | ||
|
||
return self.create_multi_pagelink_list(children, namespace) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters