|(require koyo)||package: koyo-lib|
koyo is a web application development toolkit that expands upon Racket’s built-in Web Applications in Racket with all the functionality that a web app typically needs in a complete package.
All of koyo’s components are decoupled so you get to pick and choose what you use.
|(require koyo/haml)||package: koyo-lib|
haml is a convenience macro for generating xexprs with less boilerplate. Its syntax is inspired by haml – whence its name – but if you’ve used Clojure’s hiccup or any similar templating language (like jade or pug), then haml will seem familiar to you.
element = (selector attributes element ...) | (selector element ...) | symbol | unless | when | splice | expr selector = :tag-name | .class-name | .class-name-1.class-name-2.class-name-n#id | :tag-name.class-name | :tag-name.class-name#id symbol = &name attributes = ((attribute-name maybe-expr) ...) attribute-name = :attribute-name unless = (unless cond-expr e0 e ...) when = (when cond-expr e0 e ...) splice = (@ e)
Literal numbers and strings are returned unmodified:
Identifiers that start with an & symbol are returned with said symbol stripped off:
> (haml &mdash)
Other identifiers are evaluated from the enclosing environment:
> (let ([a-symbol 'mdash]) (haml a-symbol))
Element tags start with a colon:
> (haml (:h1 "Hello World"))
'(h1 () "Hello World")
Id and class attributes can be attached to a tag via a shorthand syntax:
> (haml (:h1.title#main-title "Hello World"))
'(h1 ((id "main-title") (class "title")) "Hello World")
Tag names are optional if a class name is provided:
> (haml (.content (:h1.title "Hello World")))
'(div ((class "content")) (h1 ((class "title")) "Hello World"))
Lists of elements can be spliced in using the (@ e) syntax:
> (haml (.content (:ul.items (@ (for/list ([it (list "a" "b" "c")]) (haml (:li it)))))))
'(div ((class "content")) (ul ((class "items")) (li () "a") (li () "b") (li () "c")))
All expressions that don’t parse as an element are evaluated in place at runtime.