-
Notifications
You must be signed in to change notification settings - Fork 2
/
template.scm
95 lines (82 loc) · 2.58 KB
/
template.scm
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
(use-modules (sxml simple))
(use-modules (srfi srfi-1))
(define insert-form
`(form (@ (action "insert"))
(p "Name:")
(input (@ (type "text") (name "name")))
(p "Number:")
(input (@ (type "text") (name "number")))
(br)
(input (@ (type "submit")
(value "Submit")))))
(define lookup-form
`(form (@ (action "lookup"))
(p "Name:")
(input (@ (type "text") (name "name")))
(br)
(input (@ (type "submit")
(value "Submit")))))
(define forms
`(div (@ (class "pure-g"))
(div (@ (class "pure-u-1 pure-u-md-1-2")) (h2 "Lookup") ,lookup-form)
(div (@ (class "pure-u-1 pure-u-md-1-2")) (h2 "Insert"),insert-form)))
(define (output str)
`(p ,str))
(define html-head
`(head (title "phone book")
(link (@ (rel "stylesheet")
(href "http://yui.yahooapis.com/pure/0.6.0/pure-min.css")))
(link (@ (rel "stylesheet")
(href "http://yui.yahooapis.com/pure/0.6.0/grids-responsive-min.css")))
(meta (@ (name "viewport")
(content "width=device-width, initial-scale=1")))))
(define (list->ul strings)
"Put stings from a list into an <ul> element."
(match strings
(()
;; output nothing if the string is empty
'())
(str
(cons 'ul (map (lambda (s) `(li ,s)) str)))))
(define footer
`(hr ,(output "Author: Sebastian Jordan")))
(define top
`((h2 "Navigation")
(div (@ (class "pure-menu pure-menu-horizontal"))
(ul (@ (class "pure-menu-list"))
(li (a (@ (href "/")
(class "pure-menu-link"))
"home"))
(li (a (@ (href "/lookup")
(class "pure-menu-link"))
"bla"))))))
;; Complete templates
(define (lookup-page-found name number)
"Generate an html page for the case the a queried number was found
in the database."
`(html ,html-head
(body
,(output (string-append name ": " number))
,forms
,footer)))
(define (lookup-page-not-found name)
"Generate a page for the case that a query for a name was not
successful."
`(html ,html-head
(body
,(output (string-append "there is no entry for " name " stored"))
,forms
,footer)))
(define insert-page
`(html ,html-head
(body
,top
,(output "OK")
,forms
,footer)))
(define (index-page xml)
`(html ,html-head
(body ,top
,xml
,forms
,footer)))