-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplates.carp
51 lines (45 loc) · 1.44 KB
/
templates.carp
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
(load "https://github.com/TimDeve/[email protected]")
(load "https://github.com/TimDeve/[email protected]")
(defmodule TodoDomain
(defmodule Template
(defn add-todo-form-html []
(with Elements
(form
{@"action" @"/"
@"method" @"POST"
@"class" @"add-todo-form"}
[(input {@"name" @"description"
@"placeholder" @"What to do?"})])))
(defn delete-todo-form-html [id]
(with Elements
(form
{@"action" @"/delete"
@"method" @"POST"}
[(input {@"name" @"id"
@"value" (str id)
@"type" @"hidden"})
(button {} [@"×"])])))
(defn todo-html [id description]
(with Elements
(li {@"class" @"todo"}
[(delete-todo-form-html id)
description])))
(defn todos-html [todos]
(with Elements
(ul {@"class" @"todos"}
(Array.copy-map
&(fn [pair]
(Pair.spread [id description @pair]
(todo-html id description)))
&(Array.enumerated todos)))))
(defn todos-page-html [todos]
(with Elements
(html {}
[(head {}
[(meta {@"charset" @"UTF-8"})
(link {@"href" @"/static/index.css" @"rel" @"stylesheet"})])
(body {}
[(div {@"class" @"container"}
[(h1 {} [@"Todo"])
(add-todo-form-html)
(todos-html todos)])])])))))