pay/web/template/template.qtpl

143 lines
4.9 KiB
Plaintext

{% package template %}
{% import (
"golang.org/x/text/language"
"golang.org/x/text/message"
) %}
{% interface Page {
body()
dir()
lang()
t(format message.Reference, v ...any)
title()
head()
} %}
{% code
type Context struct {
language language.Tag
printer *message.Printer
amount float64
}
func NewContext(lang language.Tag, amount uint64) *Context {
return &Context{
language: lang,
printer: message.NewPrinter(lang),
amount: float64(amount),
}
}
%}
{% stripspace %}
{% func (ctx Context) head() %}
<link rel="icon" href="/favicon.ico" sizes="32x32">
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<link rel="manifest" href="/manifest.webmanifest">
<link rel="preload stylesheet"{% space %}
as="style"{% space %}
href="/styles.css"{% space %}
type="text/css"{% space %}
fetchpriority="high"{% space %}
referrerpolicy="no-referrer"{% space %}
crossorigin="anonymous">
{% endfunc %}
{% func (ctx Context) body() %}
<h1>{%= ctx.title() %}</h1>
<ul class="[ cluster ][ list-style-type:none padding-inline-start:unset ]">
<li>
<a class="button"{% space %}
rel="noopener noreferrer payment"{% space %}
href="https://liberapay.com/toby3d/donate{% if ctx.amount > 0 %}?amount={%f.2 ctx.amount/100 %}&currency=USD&period=monthly{% endif %}">
{%= icon("liberapay") %}
Liberapay
</a>
</li>
<li>
<a class="button"{% space %}
rel="noopener noreferrer payment"{% space %}
href="https://www.paypal.me/toby3dKZ{% if ctx.amount > 0 %}/{%f.2 ctx.amount/100 %}USD{% endif %}">
{%= icon("paypal") %}
PayPal
</a>
</span>
</li>
</ul>
{% endfunc %}
{% func (ctx Context) dir() %}
{% switch ctx.language %}
{% default %}
ltr
{% case language.Arabic, language.Persian, language.Hebrew, language.Urdu %}
rtl
{% endswitch %}
{% endfunc %}
{% func (ctx Context) lang() %}
{% code base, _ := ctx.language.Base() %}
{%s base.String() %}
{% endfunc %}
{% func (ctx Context) t(format message.Reference, v ...any) %}
{%s ctx.printer.Sprintf(format, v...) %}
{% endfunc %}
{% func (ctx Context) title() %}
{%= ctx.t(`Donate $%.2f to %s`, ctx.amount/100, "toby3d") %}
{% endfunc %}
{% func Template(p Page) %}
<!DOCTYPE html>
<html lang="{%= p.lang() %}" dir="{%= p.dir() %}">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{%= p.title() %}</title>
{%= p.head() %}
</head>
<body>
{%= p.body() %}
</body>
</html>
{% endfunc %}
{% func icon(id string) %}
{% switch id %}
{% case "liberapay" %}
<svg class="icon"{% space %}
width="32"{% space %}
height="32"{% space %}
viewBox="0 0 80 80"{% space %}
aria-hidden="true"{% space %}
focusable="false"{% space %}
xmlns="http://www.w3.org/2000/svg">
<path fill="#1a171b" d="M25.91 63.04c-3.57 0-6.37-.47-8.41-1.4a9.03 9.03 0 0 1-4.38-3.8 11.15 11.15 0 0 1-1.28-5.55c.03-2.08.32-4.31.87-6.67L22.3 5.57l11.69-1.81L23.5 47.2c-.2.9-.32 1.73-.34 2.49-.03.75.11 1.42.41 2 .3.57.82 1.04 1.55 1.39a8.7 8.7 0 0 0 3.05.68l-2.26 9.28m42.24-24.96c0 3.67-.6 7.03-1.81 10.07a23.94 23.94 0 0 1-5.01 7.88 22.43 22.43 0 0 1-7.7 5.17 25.4 25.4 0 0 1-9.76 1.85c-1.71 0-3.42-.16-5.13-.46l-3.4 13.65H24.19L36.7 24.05a67.6 67.6 0 0 1 6.9-1.62c2.6-.48 5.4-.71 8.42-.71 2.81 0 5.24.42 7.27 1.28a13.6 13.6 0 0 1 5.02 3.5 14.32 14.32 0 0 1 2.9 5.21c.63 1.99.95 4.11.95 6.37M40.78 53.54c.85.2 1.91.3 3.17.3 1.96 0 3.74-.36 5.35-1.09a11.8 11.8 0 0 0 4.11-3.05 14.1 14.1 0 0 0 2.64-4.72c.63-1.83.95-3.86.95-6.07 0-2.16-.48-4-1.44-5.5-.95-1.51-2.61-2.27-4.97-2.27-1.61 0-3.12.15-4.53.46l-5.28 21.94" />
</svg>
{% case "paypal" %}
<svg class="icon"{% space %}
width="32"{% space %}
height="32"{% space %}
viewBox="0 0 154.7 190.5"{% space %}
aria-hidden="true"{% space %}
focusable="false"{% space %}
xmlns="http://www.w3.org/2000/svg">
{% comment %}Left blue{% endcomment %}
<path fill="#003087" d="M28 0a5.5 5.5 0 0 0-5.5 4.6L.1 147.2a4.5 4.5 0 0 0 4.4 5.2h33.3l8.3-52.5 9-57.2a5.5 5.5 0 0 1 5.4-4.6h47.8c8.7 0 16.6 2 23.4 5.6C132 19.7 112.4 0 85.3 0z" />
{% comment %}Middle blue{% endcomment %}
<path fill="#001c64" d="M60.5 38.1a5.5 5.5 0 0 0-5.4 4.6l-9 57.2-8.3 52.5 8.3-52.5a5.5 5.5 0 0 1 5.4-4.6H78a54 54 0 0 0 53.8-51.6 50 50 0 0 0-23.4-5.6z" />
{% comment %}Right blue{% endcomment %}
<path fill="#0070e0" d="M131.7 43.7a54 54 0 0 1-53.8 51.6H51.5c-2.7 0-5 2-5.4 4.6l-8.3 52.5-5.2 33a4.5 4.5 0 0 0 4.4 5.1h28.7a5.5 5.5 0 0 0 5.4-4.6l7.6-48a5.5 5.5 0 0 1 5.4-4.5H101a54 54 0 0 0 53.2-45.7c3-18.7-6.5-35.6-22.5-44z" />
</svg>
{% endswitch %}
{% endfunc %}
{% endstripspace %}