Skip to content

Latest commit

 

History

History
193 lines (136 loc) · 5.64 KB

File metadata and controls

193 lines (136 loc) · 5.64 KB

Table of contents

  • dompa.coordinates
    • ->nodes - Transform given html according to given coordinates into a tree of nodes, each representing one HTML node and its children.
    • compose - Composes a given html string into a vector of coordinates.
    • unify - Joins together given coordinates that represent one HTML node in html, using a stack-based approach to correctly handle nested and void tags.
  • dompa.html
    • ->coordinates - Transform a html string into a vector of coordinates indicating where an HTML node ends and begins.
    • ->nodes - Transform a html string into a tree of nodes, each representing one HTML node and its children.
  • dompa.nodes
    • $ - Creates a new node Usage: clojure ($ :div ($ "hello world" )) .
    • ->html - Transform a vector of nodes into an HTML string.
    • defhtml - Creates a new function with name that outputs HTML.
    • traverse - Recursively traverses given tree of nodes with a traverser-fn that gets a single node passed to it and returns a new updated tree.

(->nodes {:keys [html coordinates]})

Function.

Transform given html according to given coordinates into a tree of nodes, each representing one HTML node and its children.

Direct output of both compose and unify can be given to this function, allowing chaining such as:

(-> "some html ..."
    coordinates/compose
    coordinates/unify
    coordinates/->nodes)

Source

(compose html)

Function.

Composes a given html string into a vector of coordinates. These are single-pass coordinates without awareness of context, thus HTML such as:

<div>hello</div>

will return 3 coordinates (div, text, div) instead of 2 (div, text). To unify the coordinates in a context-aware way, you pass the result of this function to the unify function.

Source

(unify {:keys [html coordinates]})

Function.

Joins together given coordinates that represent one HTML node in html, using a stack-based approach to correctly handle nested and void tags.

Source


(->coordinates html)

Function.

Transform a html string into a vector of coordinates indicating where an HTML node ends and begins.

Source

(->nodes html)

Function.

Transform a html string into a tree of nodes, each representing one HTML node and its children.

Source


($ name & opts)

Function.

Creates a new node

Usage:

($ :div
  ($ "hello world" ))

Source

(->html nodes)
(->html nodes {:keys [void-nodes]})

Function.

Transform a vector of nodes into an HTML string.

Options:

  • void-nodes - A set of node names that are self-closing, defaults to:
    • :!doctype
    • :area
    • :base
    • :br
    • :col
    • :embed
    • :hr
    • :img
    • :input
    • :link
    • :meta
    • :source
    • :track
    • :wbr

Source

(defhtml name & args-and-elements)

Macro.

Creates a new function with name that outputs HTML.

Example usage:

(defhtml about-page [who]
  ($ :div
    ($ "hello " who)))

(about-page "world")

Source

(traverse nodes traverser-fn)

Function.

Recursively traverses given tree of nodes with a traverser-fn that gets a single node passed to it and returns a new updated tree. If the traverses function returns nil, the node will be removed. In any other case the node will be replaced. If you wish to keep a node unchanged, just return it as-is.

Source