4 ms·
Has there ever been a widely used open source project for writing HTML as functions inside of another language? (JSX and PHP don't count - you're still writing
by 65 2y ago
Has there ever been a widely used open source project for writing HTML as functions inside of another language? (JSX and PHP don't count - you're still writing the HTML markup).
- pmdr 2y agoPhlex (https://phlex.fun https://phlex.fun), but I don't know about the 'widely' part.
- librasteve 2y agoI have been working on a raku module (HTML::Functional) to do this, as with the OP the main motivation is for me to be able to declutter my own projects, so not widely used, but yes OSS. Here is an "Elm-like" example from https://elmprogramming.com/building-a-simple-page-in-elm.html https://elmprogramming.com/building-a-simple-page-in-elm.htm... coded in raku. HTMX is a great lever to put the code on the server - thus Go, Raku, whatever. use HTML::Functional; my $body = body [ div( :class<jumbotron>, [ h1("Welcome to Dunder Mifflin!"), p "Dunder Mifflin Inc. (stock symbol{strong 'DMI'})\n" ~ q:to/END/; is a micro-cap regional paper and office supply distributor with an emphasis on servicing small-business clients. END ]), p :hx-get<https://v2.jokeapi.dev/joke/Any?format=txt&safe-mode>, "Click Me", ]; From the module synopsis which means some of the capabilities of the Raku Quoting Slang are in play ... https://raku.land/zef:librasteve/HTML::Functional https://raku.land/zef:librasteve/HTML::Functional. Raku functions only need parens for disambiguation btw. Named attrs can use the :name<value> syntax which imo is the tidiest.
- eddyg 2y agoRaku is such a great language! It’s a shame it doesn’t get the attention it deserves. Thanks for sharing!
- gwd 2y agoI dunno how widely used it is, but I've found gomponents[1] a big improvement over golang templates with hand-crafted HTML. [1] https://www.gomponents.com/ https://www.gomponents.com/
- poorlyknit 2y agoElm comes to mind. Mentioned a bunch on HN but you probably wouldn't call it widely used...