Advent 2019 part 18, Exploring Bootleg
Dive into yet another GraalVM based Clojure CLI tool
This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.
With the advent of Graal it's now relatively straightforward to compile Clojure code to a compact and fast native binary, which has led to an explosion of new tools. In previous episodes I talked about Babashka, jet, and rep. Today I'll explore what looks like another interesting tool: Bootleg.
This post uses Nextjournal, a computational notebook environment with a focus on reproducibility. Go ahead and remix this notebook to run the code cells yourself.
First things first, let's install Bootleg, I'll simply follow the instructions in the README.
curl -sLO https://github.com/retrogradeorbit/bootleg/releases/download/v0.1.6-1/bootleg-0.1.6-1-linux-amd64.tgz
tar xvf bootleg-0.1.6-1-linux-amd64.tgz && rm bootleg-0.1.6-1-linux-amd64.tgz
mv bootleg /usr/bin
bootleg --help
Bootleg's main job is being a template processing tool for building static websites. Let's try that out by adding a Hiccup template.
[:html
[:body
[:h1 "A simple webpage"]
[:p "Made with bootleg for maximum powers!"]]]
And running it through bootleg
:
bootleg a_simple_template.clj
So it expands Hiccup, basically acting as a Hiccup -> HTML converter. It can also take hiccup forms directly at the command line.
bootleg -e '[:p "pretty sweet!"]'
And these forms are evaluated, you have the full power of Clojure at your disposal thanks to Sci, the Small Clojure Interpreter that also powers Babashka.
bootleg -e '[:li (for [t ["Green" "Black" "Wulong"]] [:ul t])]'
So in a way Bootleg is just a Clojure interpreter, similar to bb
, but with two main differences: it renders the result of the expression to HTML, and it includes a whole slew of utility functions for dealing with various templating and markdown formats (markdown, mustache, ...), as well as doing file system manipulation like creating directories or symlinks, and for reading data from yaml, json, or edn.
bootleg -e '(str (+ 13 29))'
bootleg -e '(markdown "https://raw.githubusercontent.com/retrogradeorbit/bootleg/master/README.md")'
So say you have this simple "layout" template, and you want to render some markdown into that
[:html
[:head
[:title]]
[:body]]
My first page
**cool stuff**
bootleg -e '(-> (hiccup "layout.clj")
(enlive/at [:title]
(enlive/content "My first page"))
(enlive/at [:body]
(enlive/content (markdown "my_first_page.md"))))'
What I like about the approach bootleg has taken is that it gives you all the raw tools to set up your static site building, without dictating any of the specifics. It gives you all the building blocks, what you do with them is up to you!
Hi, my name is Arne (aka @plexus) and I consult companies and teams about application architecture, development process, tooling and testing. I collaborate with other talented people under the banner Gaiwan. If you like to have a chat about how we could help you with your project then please get in touch!