Externalize sexp component templates and delete redundant HTML fragments
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m13s

Move 24 defcomp definitions from Python string constants in components.py
to 7 grouped .sexp files under shared/sexp/templates/. Add load_sexp_dir()
to jinja_bridge.py for file-based loading. Migrate events and market
link-card fragment handlers from render_template to sexp. Delete 9
superseded Jinja HTML fragment templates.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-28 08:55:54 +00:00
parent 9c6170ed31
commit 53c4a0a1e0
20 changed files with 506 additions and 1029 deletions

View File

@@ -6,7 +6,7 @@ by other coop apps via the fragment client.
from __future__ import annotations
from quart import Blueprint, Response, g, render_template, request
from quart import Blueprint, Response, g, request
from shared.infrastructure.fragments import FRAGMENT_HEADER
from shared.services.registry import services
@@ -65,6 +65,7 @@ def register():
from sqlalchemy import select
from shared.models.market import Product
from shared.infrastructure.urls import market_url
from shared.sexp.jinja_bridge import sexp as render_sexp
slug = request.args.get("slug", "")
keys_raw = request.args.get("keys", "")
@@ -79,14 +80,16 @@ def register():
await g.s.execute(select(Product).where(Product.slug == s))
).scalar_one_or_none()
if product:
parts.append(await render_template(
"fragments/link_card.html",
title=product.title,
image=product.image,
description_short=product.description_short,
brand=product.brand,
regular_price=product.regular_price,
special_price=product.special_price,
subtitle = product.brand or ""
detail = ""
if product.special_price:
detail = f"<s>{product.regular_price}</s> {product.special_price}"
elif product.regular_price:
detail = str(product.regular_price)
parts.append(render_sexp(
'(~link-card :title title :image image :subtitle subtitle :detail detail :link link)',
title=product.title, image=product.image,
subtitle=subtitle, detail=detail,
link=market_url(f"/product/{product.slug}/"),
))
return "\n".join(parts)
@@ -99,14 +102,16 @@ def register():
).scalar_one_or_none()
if not product:
return ""
return await render_template(
"fragments/link_card.html",
title=product.title,
image=product.image,
description_short=product.description_short,
brand=product.brand,
regular_price=product.regular_price,
special_price=product.special_price,
subtitle = product.brand or ""
detail = ""
if product.special_price:
detail = f"<s>{product.regular_price}</s> {product.special_price}"
elif product.regular_price:
detail = str(product.regular_price)
return render_sexp(
'(~link-card :title title :image image :subtitle subtitle :detail detail :link link)',
title=product.title, image=product.image,
subtitle=subtitle, detail=detail,
link=market_url(f"/product/{product.slug}/"),
)

View File

@@ -1,9 +0,0 @@
{# Market links nav — served as fragment from market app #}
{% for m in markets %}
<a
href="{{ market_url('/' + post_slug + '/' + m.slug + '/') }}"
class="{{styles.nav_button_less_pad}}">
<i class="fa fa-shopping-bag" aria-hidden="true"></i>
<div>{{m.name}}</div>
</a>
{% endfor %}

View File

@@ -1,28 +0,0 @@
<a href="{{ link }}" class="block rounded border border-stone-200 bg-white hover:bg-stone-50 transition-colors no-underline" data-fragment="link-card" data-app="market" data-hx-disable>
<div class="flex flex-row items-start gap-3 p-3">
{% if image %}
<img src="{{ image }}" alt="" class="flex-shrink-0 w-16 h-16 rounded object-cover">
{% else %}
<div class="flex-shrink-0 w-16 h-16 rounded bg-stone-100 flex items-center justify-center text-stone-400">
<i class="fas fa-shopping-bag text-lg"></i>
</div>
{% endif %}
<div class="flex-1 min-w-0">
<div class="font-medium text-stone-900 text-sm clamp-2">{{ title }}</div>
{% if brand %}
<div class="text-xs text-stone-500 mt-0.5">{{ brand }}</div>
{% endif %}
{% if description_short %}
<div class="text-xs text-stone-500 mt-1 clamp-2">{{ description_short }}</div>
{% endif %}
<div class="text-xs mt-1">
{% if special_price %}
<span class="text-red-600 font-medium">&pound;{{ "%.2f"|format(special_price) }}</span>
<span class="text-stone-400 line-through ml-1">&pound;{{ "%.2f"|format(regular_price) }}</span>
{% elif regular_price %}
<span class="text-stone-700 font-medium">&pound;{{ "%.2f"|format(regular_price) }}</span>
{% endif %}
</div>
</div>
</div>
</a>