/
node.clj
31 lines (25 loc) · 882 Bytes
/
node.clj
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
(ns selmer.node
" Node protocol for the objects that get accum'd in the post-parse vector.
Same vector that will be processed by the runtime context-aware renderer.
Currently only TextNodes and FunctionNodes. Anything that requires action
upon context map data at runtime is handled by a generated anonymous function. "
(:gen-class))
;; Generic INode protocol
(defprotocol INode
(render-node [this context-map] "Renders the context"))
;; Implements fn handler for the context map. fn handlers can
;; access any data in the context map.
(deftype FunctionNode [handler]
INode
(render-node [this context-map]
(handler context-map))
clojure.lang.IMeta
(meta [this]
(meta handler)))
;; Implements dumb text content injection at runtime.
(deftype TextNode [text]
INode
(render-node [this context-map]
(str text))
(toString [_]
(str text)))