HapticX / happyx

Macro-oriented asynchronous web-framework written in Nim with ♥
https://hapticx.github.io/happyx/
MIT License
522 stars 17 forks source link

Own template engine 🤔 #6

Open Ethosa opened 1 year ago

Ethosa commented 1 year ago

Example syntax:

quimt commented 1 year ago

I'm partial to systems that emphasize functions of text and allow for nesting. I have some familiarity with Pollen, as an example:

â—Švariable-name
◊tag{Text inside the tag.}
◊tag[#:attr "value"]{Text inside the tag}
◊get-customer-id["Brennan Huff"]
◊tag{His ID is ◊get-customer-id["Brennan Huff"].}

The goal of the syntax is to allow procs that return strings to extend html tags, and to modify paragraph text at any level of nesting. This helps the coded text to more closely resemble the output text. Like a lot of things that have become standards on the front end, mustache-style syntax spreads easily, and is easy to implement on JS, but ultimately it's not as powerful a tool as it could be, and is not even that easy to implement in languages where whitespace is part of the syntax.

I'd rather have this kind of function injection on parts of template strings than all the nimja-style constructs. These are nice, but their functionality is easy to get if you can easily inline procs of parts of the text.