From e9390dfa7e45b77d6040ccca540fe64bc79744ec Mon Sep 17 00:00:00 2001 From: SRHTNIN Date: Mon, 21 Sep 2026 23:15:12 +0200 Subject: [PATCH] Renamed Portals.py to VarFunctions.py, and fixed bug where you cannot use head or tail in a loop. --- Backend/Embeds.py | 2 +- Backend/Main.py | 2 +- Backend/{Portals.py => VarFunctions.py} | 20 ++++++++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) rename Backend/{Portals.py => VarFunctions.py} (95%) diff --git a/Backend/Embeds.py b/Backend/Embeds.py index 1848413..0f8932c 100644 --- a/Backend/Embeds.py +++ b/Backend/Embeds.py @@ -10,8 +10,8 @@ from Core import ResolvePath from Explorer import ClassifyFile, GetDirectoryNoteInfo from Groups import GuestGroupName from Locks import IsPathAccessible -from Portals import ResolvePortals from Preview import GetMimeType, ReadTextFile, TextFileTypes +from VarFunctions import ResolvePortals DescriptionExcerptLength = 200 diff --git a/Backend/Main.py b/Backend/Main.py index ca2b672..fbd28b9 100644 --- a/Backend/Main.py +++ b/Backend/Main.py @@ -51,7 +51,6 @@ from Locks import ( RequirePathAccessible, SetLock, ) -from Portals import ResolvePortals from Preview import GetMimeType, ReadTextFile, StreamBinaryFile, TextFileTypes from Settings import ( DefaultSettings, @@ -77,6 +76,7 @@ from Users import ( UserColourOptions, VerifyLogin, ) +from VarFunctions import ResolvePortals from pydantic import BaseModel diff --git a/Backend/Portals.py b/Backend/VarFunctions.py similarity index 95% rename from Backend/Portals.py rename to Backend/VarFunctions.py index 482a4de..cd15666 100644 --- a/Backend/Portals.py +++ b/Backend/VarFunctions.py @@ -24,6 +24,7 @@ LoopMarkerPattern = re.compile( r"\{(?Pchildren|siblings|parents)\s+%\s+(?P[A-Za-z_][A-Za-z0-9_]*)\}" r"|\{(?Pchildren|siblings|parents)\s+%\}" r"|\{(?:(?P[^\s{}']+)\s+)?\*\*\*(?P[^\s*{}]+)" + r"(?:\s+(?Phead|tail)\s+(?P\d+))?" r"\s+%\s+(?P[A-Za-z_][A-Za-z0-9_]*)\}" r"|\{\*\*\*(?P[^\s*{}]+)\s+%\}" ) @@ -192,7 +193,15 @@ def _ResolveLoops( PortalContent = _ResolveCrossFileReference( RootName, RefererDirectory, Match.group("LoopCrossPath"), Key, Username, UserGroups ) - Items = PortalContent.splitlines() if PortalContent is not None else [] + + if PortalContent is None: + Items = [] + elif Match.group("LoopCrossPipe"): + Items = _SlicePipeLines( + PortalContent, Match.group("LoopCrossPipe"), int(Match.group("LoopCrossPipeCount")) + ) + else: + Items = PortalContent.splitlines() CloseMatch = _FindLoopClose(Matches, Index + 1, IsFixed, Key) BodyEnd = CloseMatch.start() if CloseMatch is not None else len(Content) @@ -294,10 +303,13 @@ def _ResolveCrossFileReference( return _FindLocalDefinitions(Content).get(Name) -def _ApplyPipe(Text: str, Mode: str, Count: int) -> str: +def _SlicePipeLines(Text: str, Mode: str, Count: int) -> list[str]: Lines = Text.splitlines() - Selected = Lines[:Count] if Mode == "head" else Lines[-Count:] if Count > 0 else [] - return "\n".join(Selected) + return Lines[:Count] if Mode == "head" else (Lines[-Count:] if Count > 0 else []) + + +def _ApplyPipe(Text: str, Mode: str, Count: int) -> str: + return "\n".join(_SlicePipeLines(Text, Mode, Count)) def _ResolveWholeFilePipe(