This application also makes use of HTMX to provide a more interactive experience. HTMX is a library that allows you to create web applications with less JavaScript. It uses HTML attributes to define the behavior of the application.
The Todo examples use project-specific domain types plus HTMX, HyperScript, SortableJS, Chi, and small application helpers.
Page Layouts
Each page will be wrapped with the following main layout:
Each page in the application makes use of the base template and will then include additional content which is rendered by the before mentioned =@children directive.
Taking a look at the partials.AddTodoForm template:
package partials
@haml AddTodoForm() {
%form.inline{
method: "POST",
action: "/todos",
hx-post: "/todos",
hx-target: "#no-todos",
hx-swap: "beforebegin",
}
%label.flex.items-center
%span.text-lg.font-bold Add Todo
%input.ml-2.grow{
type: "text",
name: "description",
_: "on keyup if the event's key is 'Enter' set my value to '' trigger keyup"
}
}
Being able to put the attributes across multiple lines makes it easier to read and understand the structure of the form. The HTMX attributes are also included without any additional effort. Likewise, we can also add the HyperScript code with _ as its name.
Handlers
A simple render() function is used to render the templates and catch any errors that may occur: