Runtime Engine generisch

This commit is contained in:
2026-05-29 21:39:21 +02:00
parent 9dff578c15
commit 04a29ae8cd
3 changed files with 13 additions and 89 deletions

View File

@@ -13,8 +13,11 @@
"{ toIntermediate: v => %s, fromIntermediate: v => %s }"
$toExpr $fromExpr }}
{{ else if eq .Params.engine "runtime" }}
{{ $config = dict "fromCurrency" .Params.from
"toCurrency" .Params.to | jsonify }}
{{ $fromCode := .Params.from }}
{{ $toCode := .Params.to }}
{{ $config = printf
"{ init: async function () { const pbUrl = document.querySelector('meta[name=\\'pocketbase-url\\']')?.content || 'https://www.alphabreed.com'; try { const response = await fetch(`${pbUrl}/api/collections/currencies/records`); if (!response.ok) { this.ratesError = 'Wechselkurse konnten nicht geladen werden.'; return; } const data = await response.json(); for (const item of data.items || []) { this.rates[item.id] = item.rate; } } catch (e) { this.ratesError = 'Wechselkurse konnten nicht geladen werden.'; } }, convert: function (value) { const fromRate = '%s' === 'eur' ? 1 : this.rates['%s']; const toRate = '%s' === 'eur' ? 1 : this.rates['%s']; if (!fromRate || !toRate) { return null; } return value.times(new Decimal(toRate)).dividedBy(new Decimal(fromRate)); } }"
$fromCode $fromCode $toCode $toCode }}
{{ end }}
{{ $availableUnits := partial "available-units.html"
(dict "category" .Params.category "units" $catData.units) }}