mirror of
https://git.srhtnin.garden/sarah/SaraView.git
synced 2026-10-13 18:28:14 +02:00
Renamed Portals.py to VarFunctions.py, and fixed bug where you cannot
use head or tail in a loop.
This commit is contained in:
1 parent
9bd57505bb
commit
e9390dfa7e
3 files changed
+18
-6
No files matched your search
+1
-1
@@ -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
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ LoopMarkerPattern = re.compile(
|
||||
r"\{(?P<LoopSource>children|siblings|parents)\s+%\s+(?P<LoopVar>[A-Za-z_][A-Za-z0-9_]*)\}"
|
||||
r"|\{(?P<CloseSource>children|siblings|parents)\s+%\}"
|
||||
r"|\{(?:(?P<LoopCrossPath>[^\s{}']+)\s+)?\*\*\*(?P<LoopCrossName>[^\s*{}]+)"
|
||||
r"(?:\s+(?P<LoopCrossPipe>head|tail)\s+(?P<LoopCrossPipeCount>\d+))?"
|
||||
r"\s+%\s+(?P<LoopCrossVar>[A-Za-z_][A-Za-z0-9_]*)\}"
|
||||
r"|\{\*\*\*(?P<CloseCrossName>[^\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(
|
||||
Reference in new issue
Block a user