[ANN] Kelpie.jl: An HTML templating engine in pure Julia

Kelpie wraps EzXML.jl nodes with functions taken from the names of HTML5 elements (e.g. a, img, nav, etc.). Each function takes the content of the element as a positional argument, and translates all keyword arguments into attributes. For example

<a href="https://julialang.org" class="card-link">Julia</a>

is represented in Kelpie as

a("Julia"; href="https://julialang.org", class="card-link")

This package happened almost entirely by accident: I was writing a script to display a combination of biological sequences in a webpage using BioJulia and EzXML.jl and got tired of having to manually link all my nodes together. So I started writing wrapper functions, then I got tired of writing those, so I converted to a generated function, and Kelpie was born. Once I started chaining function calls, I noticed that the syntax looked a lot like Pug, so I named it after a different dog breed.

I’m still learning the full capabilities of my new creation, but it should be really easy to insert into Genie projects (I haven’t tried yet). It is way more capable than its flat-nosed counterpart, as Julia function calls from any package can be inserted right into a webpage directly. Documentation and testing will be more fleshed out in the coming weeks as I play around with it more.

Enjoy! :smile:

13 Likes

Cool :slight_smile:
Did you know of Hyperscript.jl, which does seem to do something similar?

1 Like

I hadn’t seen Hyperscript.jl. It’s a cool approach, too.

1 Like

Hi I haven’t tried it, although I think it’s a great idea.
How does it cope with some problematic HTML I know about:

  • invalid julia names of tags
  • attributes as values
  • invalid kw argument names
<!DOCTYPE html>

<input type="checkbox" checked>

<p data-56="some data">

<option selected>

<!-- what about comments -->


  1. Invalid names of tags are edge cases with special wrapper functions (i.e. <div>html_div())
  2. Attributes as values are invalid XHTML afaik, and won’t be supported
  3. Kelpie translates underscores in kwargs names to dashes: this is undocumented right now, and will probably change to something more robust later
  4. My goal with Kelpie is to make machine-readable HTML out of human-readable Julia, so I don’t plan to add support for comments

Oh. Your headlines says HTML Templating, not XHTML

well, all the best

1 Like