summaryrefslogtreecommitdiff
path: root/API.md
blob: 625a7a5600aace2d58cfda7e36d36656c25e528b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# Table of contents
-  [`dompa.coordinates`](#dompa.coordinates) 
    -  [`->nodes`](#dompa.coordinates/->nodes) - Transform given <code>html</code> according to given <code>coordinates</code> into a tree of nodes, each representing one HTML node and its children.
    -  [`compose`](#dompa.coordinates/compose) - Composes a given <code>html</code> string into a vector of coordinates.
    -  [`unify`](#dompa.coordinates/unify) - Joins together given <code>coordinates</code> that represent one HTML node in <code>html</code>, using a stack-based approach to correctly handle nested and void tags.
-  [`dompa.html`](#dompa.html) 
    -  [`->coordinates`](#dompa.html/->coordinates) - Transform a <code>html</code> string into a vector of coordinates indicating where an HTML node ends and begins.
    -  [`->nodes`](#dompa.html/->nodes) - Transform a <code>html</code> string into a tree of nodes, each representing one HTML node and its children.
-  [`dompa.nodes`](#dompa.nodes) 
    -  [`$`](#dompa.nodes/$) - Creates a new node.
    -  [`->html`](#dompa.nodes/->html) - Transform a vector of <code>nodes</code> into an HTML string.
    -  [`defhtml`](#dompa.nodes/defhtml) - Creates a new function with <code>name</code> that outputs HTML.
    -  [`traverse`](#dompa.nodes/traverse) - Recursively traverses given tree of <code>nodes</code> with a <code>traverser-fn</code> that gets a single node passed to it and returns a new updated tree.
    -  [`zip`](#dompa.nodes/zip) - Creates a zipper for given a given <code>node</code>.

-----
# <a name="dompa.coordinates">dompa.coordinates</a>






## <a name="dompa.coordinates/->nodes">`->nodes`</a>
``` clojure

(->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`](#dompa.coordinates/compose) and [`unify`](#dompa.coordinates/unify) can be given to this
  function, allowing chaining such as:

  ```clojure
  (-> "some html ..."
      coordinates/compose
      coordinates/unify
      coordinates/->nodes)
  ```
<p><sub><a href="https://git.nmm.ee/asko/dompa/src/branch/main/src/dompa/coordinates.cljc#L327-L350">Source</a></sub></p>

## <a name="dompa.coordinates/compose">`compose`</a>
``` clojure

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

  ```html
  <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`](#dompa.coordinates/unify) function.
<p><sub><a href="https://git.nmm.ee/asko/dompa/src/branch/main/src/dompa/coordinates.cljc#L65-L85">Source</a></sub></p>

## <a name="dompa.coordinates/unify">`unify`</a>
``` clojure

(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.
<p><sub><a href="https://git.nmm.ee/asko/dompa/src/branch/main/src/dompa/coordinates.cljc#L159-L167">Source</a></sub></p>

-----
# <a name="dompa.html">dompa.html</a>






## <a name="dompa.html/->coordinates">`->coordinates`</a>
``` clojure

(->coordinates html)
```
Function.

Transform a `html` string into a vector of coordinates
  indicating where an HTML node ends and begins.
<p><sub><a href="https://git.nmm.ee/asko/dompa/src/branch/main/src/dompa/html.cljc#L5-L11">Source</a></sub></p>

## <a name="dompa.html/->nodes">`->nodes`</a>
``` clojure

(->nodes html)
```
Function.

Transform a `html` string into a tree of nodes,
  each representing one HTML node and its children.
<p><sub><a href="https://git.nmm.ee/asko/dompa/src/branch/main/src/dompa/html.cljc#L13-L19">Source</a></sub></p>

-----
# <a name="dompa.nodes">dompa.nodes</a>






## <a name="dompa.nodes/$">`$`</a>
``` clojure

($ & opts)
```
Function.

Creates a new node.
  
  Children can be passed directly - strings, numbers, and other values
  are automatically converted to text nodes. Nil values are filtered out.

  Usage:

  ```clojure
  ($ :div "hello world")
  ($ :div {:class "container"} "Hello, " name "!")
  ($ :<> "one" "two" "three")
  ```
<p><sub><a href="https://git.nmm.ee/asko/dompa/src/branch/main/src/dompa/nodes.cljc#L191-L207">Source</a></sub></p>

## <a name="dompa.nodes/->html">`->html`</a>
``` clojure

(->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`
  
<p><sub><a href="https://git.nmm.ee/asko/dompa/src/branch/main/src/dompa/nodes.cljc#L69-L93">Source</a></sub></p>

## <a name="dompa.nodes/defhtml">`defhtml`</a>
``` clojure

(defhtml name & args-and-elements)
```
Macro.

Creates a new function with `name` that outputs HTML.

  Optionally accepts a docstring between the name and the argument vector.
  
  Functions created with [`defhtml`](#dompa.nodes/defhtml) can be nested and composed with each other.

  Example usage:

  ```clojure
  (defhtml greeting [who]
    ($ :span who))

  (defhtml about-page
    "Renders the about page."
    [who]
    ($ :div
       "Hello, "
       (greeting who)))

  (about-page "world")
  ;;=> "<div>Hello, <span>world</span></div>"
  ```
  
<p><sub><a href="https://git.nmm.ee/asko/dompa/src/branch/main/src/dompa/nodes.cljc#L95-L125">Source</a></sub></p>

## <a name="dompa.nodes/traverse">`traverse`</a>
``` clojure

(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.
<p><sub><a href="https://git.nmm.ee/asko/dompa/src/branch/main/src/dompa/nodes.cljc#L43-L55">Source</a></sub></p>

## <a name="dompa.nodes/zip">`zip`</a>
``` clojure

(zip node)
```
Function.

Creates a zipper for given a given `node`.
<p><sub><a href="https://git.nmm.ee/asko/dompa/src/branch/main/src/dompa/nodes.cljc#L57-L67">Source</a></sub></p>