Liking cljdoc? Tell your friends :D

hiccup-templating.core

EDN-driven Hiccup template engine Templates are filled at runtime with a Clojure data map.

Tagged-literal grammar

Tag Meaning


:data/foo.bar Look up [:foo :bar] in data. Resolves to the value, or to the ::missing sentinel when absent / nil.

#data/foo.bar <form> Back-compat shorthand for #when :data/foo.bar <form> - used by the original template; kept so old templates still parse.

#when <test> <body> Splice <body> if <test> resolves; drop otherwise. <body> can be a single form or a vector of forms.

#when-not <test> <body> Inverse of #when.

#when-and [<tests>] <body> Splice <body> if EVERY test in the <tests> vector resolves. Cheap way to gate a row on multiple data paths.

#when-or [<tests>] <body> Splice <body> if AT LEAST ONE test in <tests> resolves.

#or [<expr> <fallback>] Evaluate <expr>; if it resolves to ::missing, evaluate <fallback>. Two special fallbacks are recognised: :remove/element drop the element that holds this #or. :remove/parent drop the parent of that element. Any other fallback is spliced as a plain value.

How element removal works

:remove/element and :remove/parent are not values - they are sentinels that propagate up the walk:

  • a vector / list whose child returned ::drop-element drops itself (returns ::missing so it disappears from its own parent);
  • a vector / list whose child returned ::drop-parent returns ::drop-element, so the level above drops itself instead.

That two-hop hand-off means :remove/parent deletes exactly the element one level above the #or form - typically a :tr row whose inner :td referenced a missing value.

Public API

template-from-edn-string / template-from-edn-stream Read an EDN template and wrap user-defined tags as tagged-literals.

template-to-hiccup Walk a template + data map, returning a Hiccup vector tree with missing branches pruned.

hiccup-xhtml-string / hiccup-xhtml-stream Render a Hiccup tree to XHTML (with <!DOCTYPE>) for the flying-saucer PDF pipeline.

EDN-driven Hiccup template engine
Templates are filled at runtime with a Clojure data map.

## Tagged-literal grammar
Tag                              Meaning
-------------------------------- ----------------------------------------
`:data/foo.bar`                  Look up `[:foo :bar]` in `data`.
                                 Resolves to the value, or to the
                                 `::missing` sentinel when absent / nil.

`#data/foo.bar <form>`           Back-compat shorthand for
                                 `#when :data/foo.bar <form>` - used by
                                 the original template; kept so old
                                 templates still parse.

`#when <test> <body>`            Splice `<body>` if `<test>` resolves;
                                 drop otherwise. `<body>` can be a
                                 single form or a vector of forms.

`#when-not <test> <body>`        Inverse of `#when`.

`#when-and [<tests>] <body>`     Splice `<body>` if EVERY test in the
                                 `<tests>` vector resolves. Cheap way
                                 to gate a row on multiple data
                                 paths.

`#when-or  [<tests>] <body>`     Splice `<body>` if AT LEAST ONE
                                 test in `<tests>` resolves.

`#or [<expr> <fallback>]`        Evaluate `<expr>`; if it resolves to
                                 `::missing`, evaluate `<fallback>`.
                                 Two special fallbacks are recognised:
                                   `:remove/element`  drop the element
                                                      that holds this
                                                      `#or`.
                                   `:remove/parent`   drop the parent
                                                      of that element.
                                 Any other fallback is spliced as a
                                 plain value.

## How element removal works

`:remove/element` and `:remove/parent` are not values - they are
sentinels that propagate up the walk:

  * a vector / list whose child returned `::drop-element` drops itself
    (returns `::missing` so it disappears from its own parent);
  * a vector / list whose child returned `::drop-parent` returns
    `::drop-element`, so the level above drops itself instead.

That two-hop hand-off means `:remove/parent` deletes exactly the
element one level above the `#or` form - typically a `:tr` row whose
inner `:td` referenced a missing value.

## Public API

`template-from-edn-string` / `template-from-edn-stream`
  Read an EDN template and wrap user-defined tags as `tagged-literal`s.

`template-to-hiccup`
  Walk a template + data map, returning a Hiccup vector tree with
  missing branches pruned.

`hiccup-xhtml-string` / `hiccup-xhtml-stream`
  Render a Hiccup tree to XHTML (with `<!DOCTYPE>`) for the
  flying-saucer PDF pipeline.
raw docstring

as-xhtml-streamclj

(as-xhtml-stream hiccup-ds)

Parses provided hiccup datastructure into xhtml with unescaped strings and returns it as stream

Parses provided hiccup datastructure into xhtml with unescaped strings and returns it as stream
sourceraw docstring

as-xhtml-stringclj

(as-xhtml-string hiccup-ds)

Parses provided hiccup datastructure into xhtml with unescaped strings and returns it as string

Parses provided hiccup datastructure into xhtml with unescaped strings and returns it as string
sourceraw docstring

from-fileclj

(from-file path filename)

Reads an EDN html template as java.io.File from provided path + filename

Reads an EDN html template as `java.io.File` from provided path + filename
sourceraw docstring

from-streamclj

(from-stream ednstream)

Reads an EDN html template from provided stream

Reads an EDN html template from provided stream
sourceraw docstring

from-stringclj

(from-string ednstring)

Reads an EDN html template from provided string

Reads an EDN html template from provided string
sourceraw docstring

template-to-hiccupclj

(template-to-hiccup template
                    data
                    &
                    {:keys [template-key] :or {template-key :template}})

Parses and fills provided template under :template-key with provided data

Parses and fills provided template under :template-key with provided data
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close