giuseppeg / xm

₪ extensible HTML
https://giuseppeg.github.io/xm
326 stars 9 forks source link

RFC: expressions #11

Closed giuseppeg closed 3 years ago

giuseppeg commented 4 years ago

xm is not a full blown templating system and will probably stay like this.

However I am thinking about implementing an extension (a separate PostHTML plugin) to add support for expressions and perhaps loops.

Please give this description a 👍 if you like this proposal or a 👎 if you'd rather use an existing PostHTML plugin like posthtml-expressions


sample syntax - see description

The syntax would be {xm:expression} where expression is a reference to a fill value or any other constant defined by the user via config file and is part of a serialized env object passed to the plugin as an option.

// configuration passed to the posthtml plugin
{
   env: { posts: collectPosts() }
}

Additionally expression can be an arrow function that takes one parameter - the fill value - and transforms that value:

{xm:domain => `www.${domain}`}

Finally I might add some built-in helpers to make things like url encoding easy:

{xm:permalink|encodeURIComponent}
giuseppeg commented 3 years ago

A simplified alternative could be:

<meta name="title" slot:content="{title}">
<fill name="title">hello</fill>

<a slot:href="https://{subdomain}.{domain}">acme</a>
<fill name="domain">acme.com</fill>
<fill name="subdomain">real</fill>