Repository navigation
Replies: 1 comment 2 replies
|
This seems a bit high level to me to support directly as a Goose language feature, but then again I don't have a lot of experience with templating systems.. opinions? |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I'd like to start a discussion about a possible new feature: tagged string literals,
in the style of JavaScript's tagged templates, adapted to Goose.
A tag is an ordinary Goose function. The compiler splits the literal into text parts
and
${ }holes and passes them to it. Thehtmltag in the standard library escapeseach hole for where it lands: text, attribute, URL (
javascript:is blocked), eventhandler,
<script>or<style>.It fits Goose's constraints:
u8[>..]buffer, and nested templates write into the same buffer.an
ifthat isn't taken costs nothing.if,matchandforwork inside holes, and the escape ischosen by overloading on the hole's type.
Why now
Plod already gives Goose a solid HTTP framework, and
goose-postgres a database client, but Plod
answers with JSON or plain text. With
html"...", the same server can return HTMLpages, safely escaped, and Goose has everything a complete web application needs.
The idea extends to other tags later, such as a
sql"..."that turns holes intoquery parameters.
An exploratory implementation
I have an exploratory implementation working locally: lexer and parser support,
format/print/strconsuming templates, andhtmlas a stdlib module, with tests.It's deliberately minimal: the parser desugars templates into ordinary calls, so the
rest of the compiler doesn't know about them.
I'm happy to send it as a draft PR, along with the full design write-up, if there's
interest. I'd especially welcome views on:
ident"..."with${ }holes is the right syntax for Goose;such as compile-time execution;
htmlshould live in the stdlib or in a separate package.All reactions