Hacker News new | ask | show | jobs
by 65 635 days 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).
4 comments

I 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.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. Raku functions only need parens for disambiguation btw. Named attrs can use the :name<value> syntax which imo is the tidiest.
Raku is such a great language! It’s a shame it doesn’t get the attention it deserves. Thanks for sharing!
I 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/

Phlex (https://phlex.fun), but I don't know about the 'widely' part.
Elm comes to mind. Mentioned a bunch on HN but you probably wouldn't call it widely used...