Convert social and federation profile from Jinja to SX rendering
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 14m34s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 14m34s
Add primitives (replace, strip-tags, slice, csrf-token), convert all social blueprint routes and federation profile to SX content builders, delete 12 unused Jinja templates and social_lite layout. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -257,6 +257,24 @@ def prim_split(s: str, sep: str = " ") -> list[str]:
|
||||
def prim_join(sep: str, coll: list) -> str:
|
||||
return sep.join(str(x) for x in coll)
|
||||
|
||||
@register_primitive("replace")
|
||||
def prim_replace(s: str, old: str, new: str) -> str:
|
||||
return s.replace(old, new)
|
||||
|
||||
@register_primitive("strip-tags")
|
||||
def prim_strip_tags(s: str) -> str:
|
||||
"""Strip HTML tags from a string."""
|
||||
import re
|
||||
return re.sub(r"<[^>]+>", "", s)
|
||||
|
||||
@register_primitive("slice")
|
||||
def prim_slice(coll: Any, start: int, end: Any = None) -> Any:
|
||||
"""Slice a string or list: (slice coll start end?)."""
|
||||
start = int(start)
|
||||
if end is None or end is NIL:
|
||||
return coll[start:]
|
||||
return coll[start:int(end)]
|
||||
|
||||
@register_primitive("starts-with?")
|
||||
def prim_starts_with(s, prefix: str) -> bool:
|
||||
if not isinstance(s, str):
|
||||
|
||||
@@ -41,6 +41,7 @@ IO_PRIMITIVES: frozenset[str] = frozenset({
|
||||
"nav-tree",
|
||||
"get-children",
|
||||
"g",
|
||||
"csrf-token",
|
||||
})
|
||||
|
||||
|
||||
@@ -314,6 +315,17 @@ async def _io_g(
|
||||
return getattr(g, key, None)
|
||||
|
||||
|
||||
async def _io_csrf_token(
|
||||
args: list[Any], kwargs: dict[str, Any], ctx: RequestContext
|
||||
) -> str:
|
||||
"""``(csrf-token)`` → current CSRF token string."""
|
||||
from quart import current_app
|
||||
csrf = current_app.jinja_env.globals.get("csrf_token")
|
||||
if callable(csrf):
|
||||
return csrf()
|
||||
return ""
|
||||
|
||||
|
||||
_IO_HANDLERS: dict[str, Any] = {
|
||||
"frag": _io_frag,
|
||||
"query": _io_query,
|
||||
@@ -326,4 +338,5 @@ _IO_HANDLERS: dict[str, Any] = {
|
||||
"nav-tree": _io_nav_tree,
|
||||
"get-children": _io_get_children,
|
||||
"g": _io_g,
|
||||
"csrf-token": _io_csrf_token,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user