mirror of
https://github.com/MillironX/Kelpie.jl.git
synced 2024-11-14 13:43:08 +00:00
🐕 I accidentally built an HTML templating engine in Julia
Thomas A. Christensen II
ba57b38d5b
Signed-off-by: Thomas A. Christensen II <25492070+MillironX@users.noreply.github.com> |
||
---|---|---|
.github | ||
.vscode | ||
docs | ||
src | ||
test | ||
.gitignore | ||
.JuliaFormatter.toml | ||
.markdownlint.yml | ||
CHANGELOG.md | ||
CITATION.bib | ||
CODE_OF_CONDUCT.md | ||
CONTRIBUTING.md | ||
cspell.json | ||
LICENSE | ||
Project.toml | ||
README.md |
Kelpie
🐕 I accidentally built an HTML templating engine in Julia. It looked a lot like Pug, but I like working dogs better, so I named it Kelpie.
Installation
You can install straight from the Julia REPL. Press ]
to enter pkg mode,
then:
add Kelpie
Usage
Most HTML elements1 now have functions of the same name: simply pass the contents as a positional argument, and attributes as keyword arguments, and everything will be returned as an EzXML Document or Node.
import EzXML: prettyprint
doc = html(
head(
title("Kelpie.jl is awesome!"),
),
body(
header(
h1("Dogs are cool"),
h2("Julia is cool"),
),
main(
img(;
src="/kelpie-on-sheep-back.jpg",
alt="A Kelpie herding sheep"
),
[
p("Kelpies make great herding dogs for $animal.")
for animal in ["cows", "sheep", "chickens"]
]...,
),
),
)
prettyprint(doc)
Turns into
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE html SYSTEM "about:legacy-compat">
<html>
<head>
<title>Kelpie.jl is awesome!</title>
</head>
<body>
<header>
<h1>Dogs are cool</h1>
<h2>Julia is cool</h2>
</header>
<main>
<img src="/kelpie-on-sheep-back.jpg" alt="A Kelpie herding sheep" />
<p>Kelpies make great herding dogs for cows.</p>
<p>Kelpies make great herding dogs for sheep.</p>
<p>Kelpies make great herding dogs for chickens.</p>
</main>
</body>
</html>
Everything is pure Julia, so your imagination is the limit!
-
Exception:
div
is the division function, and I wanted to leave it that way. To make<div>
s, you need to usehtml_div
. ↩︎