Author Topic: [ANN] Ginger: Jinja2 template engine for FPC/Lazarus (without leaks and Python)  (Read 246 times)

tnt4brain

  • Newbie
  • Posts: 5
Hi all,

I've just published Ginger, a from-scratch Free Pascal implementation of Jinja2's template syntax - the {{ }} / {% if %} / {% for %} / filters / macros / template-inheritance language that Flask and Django developers use every day.

Why this exists: if you're writing an FPC web app (Brook, fpWeb, mORMot, whatever) and want your frontend/designers to write templates in a syntax that's widely documented, has editor support everywhere, and that a Python-background teammate already knows - instead of inventing yet another bespoke templating mini-language - Ginger renders that exact syntax natively, no Python runtime involved.

Code: Pascal  [Select][+][-]
  1. uses GingerEnvironment, GingerValue;
  2. var
  3.     Env: TGingerEnvironment;
  4.     Ctx: TGingerDict;
  5. begin
  6.     Env := TGingerEnvironment.Create;
  7.     Ctx := GingerEmptyDict;
  8.     GingerDictSet(Ctx, 'name', GingerStr('World'));
  9.     WriteLn(Env.RenderString('Hello, {{ name }}!', Ctx));
  10. end;

What's in: expressions, if/for/set/with, extends/block/include/import, macros (with varargs/kwargs, *args/**kwargs unpacking), tuple-target set/for, {% raw %}, {% filter  %}, the full default filter/test library, range/dict/cycler/namespace/lipsum, whitespace control, custom filters/tests (process-wide and per-Environment, matching real env.filters/env.tests scoping), Unicode-aware casing (Turkish/Azeri/Lithuanian/Dutch locale rules included).

How correctness is handled: every piece of behavior is checked against a real installed jinja2==3.1.6, not against memory or the docs — if Ginger's behavior and real Jinja2's output disagree on something not explicitly called out as a deliberate divergence, that's a bug. 650+ automated tests, 0 unfreed memory blocks on every run. Full design history (54 ADRs) is in the repo if you want to see why something works the way it does, including every known gap versus upstream.

Pre-1.0, BSD-3-Clause, no external users yet - which is exactly why I'm posting here first. Issues, feedback, and PRs welcome.

GitHub Repository: https://github.com/tnt4brain/ginger

tnt4brain

  • Newbie
  • Posts: 5
While building this, I made sure Ginger follows upstream Jinja2 behavior to the letter by default. However, I've added a few opt-in parameters for developers running in specific international environments (gated behind Ctx.Locale). For example, setting Ctx.Locale := 'tr' triggers correct Turkish dotless/dotted I/ı resolution, and we also support Lithuanian and Dutch (IJ) digraph rules.

Furthermore, Ginger's title filter includes an option for true Unicode titlecasing for South-Slavic Latin digraphs (dž, lj, nj), converting them to their single precomposed titlecase codepoints instead of brute-forcing uppercase on the first letter.

Have any of you running headless FPC daemons on Linux or Windows ran into specific uppercase/lowercase bugs when rendering localized text via the standard RTL tools? I would love to hear your architectural feedback or real-world layout edge cases!

 

TinyPortal © 2005-2018