koyo - web app development toolkit
1 Introduction
2 Getting Started
3 HAML
3.1 Syntax
haml
Index
7.3

koyo - web app development toolkit

Bogdan Popa <bogdan@defn.io>

 (require koyo) package: koyo-lib

1 Introduction

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.

2 Getting Started

3 HAML

 (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.

3.1 Syntax

syntax

(haml element)

 
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)
Produces an x-expression.

Literal numbers and strings are returned unmodified:

> (haml 1)

1

> (haml "hello")

"hello"

Identifiers that start with an & symbol are returned with said symbol stripped off:

> (haml &mdash)

'mdash

Other identifiers are evaluated from the enclosing environment:

> (let ([a-symbol 'mdash])
    (haml a-symbol))

'mdash

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.

Index

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

 

Getting Started
HAML
haml
Introduction
koyo
koyo - web app development toolkit
koyo/haml
Syntax