Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 107 lines (86 sloc) 3.34 kb
09bce2b @archimag update
authored
1 ;;; example.lisp
2
3 (asdf:operate 'asdf:load-op :restas)
81da31b @archimag update examples
authored
4 (asdf:operate 'asdf:load-op :xfactory)
09bce2b @archimag update
authored
5
6 (restas:define-plugin :restas.example-2
7 (:use :cl))
8
9 (in-package :restas.example-2)
10
81da31b @archimag update examples
authored
11 (defparameter *frame* "<?xml version=\"1.0\" encoding=\"utf-8\"?>
12 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
13
14 <html xmlns=\"http://www.w3.org/1999/xhtml\">
15 <head >
16 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />
17 </head>
18
19 <body>
20 <div id=\"content\" />
21 </body>
22 </html> ")
23
24 (defun in-pool (obj)
25 (gp:object-register obj *request-pool*))
26
27 (defun apply-format-aux (format args)
28 (if args
29 (apply #'format nil (cons format args))
30 format))
31
32 (defun eid (format &rest args)
33 "Make id attribute"
34 (xfactory:attributes :id
35 (apply-format-aux format args)))
36
37 (defun ehref (format &rest args)
38 "Make href attribute"
39 (xfactory:attributes :href
40 (apply-format-aux format args)))
41
42 (defun etitle (format &rest args)
43 (xfactory:with-element-factory ((E))
44 (E :head
45 (E :title
46 (xfactory:text (apply-format-aux format args))))))
47
48
49 (defun index-page ()
50 (in-pool
51 (xfactory:with-document-factory ((html))
52 (html :overlay
53 (etitle "Example 2: Index")
54 (html :div
55 (xfactory:attributes :id "content")
56 (eid "content")
57 (html :h1 "Index")
58 (html :ul
59 (loop for x from 1 to 10
60 do (html :li
61 (html :a
62 (ehref "chapter-~A.html" x)
63 (xfactory:text "Chapter ~A" x))))))))))
64
65 (define-simple-route root ("" :overlay-master *frame*)
66 (index-page))
67
68 (define-simple-route index.html ("index.html" :overlay-master *frame*)
69 (index-page))
70
71 (define-simple-route chapter-?.html ("chapter-:(id).html")
72 (xfactory:with-document-factory ((html))
73 (html :overlay
74 (etitle "Example 2: Chapter ~A" id)
75 (html :div
76 (eid "content")
77 (html :h1
78 (xfactory:text "Chapter ~A" id))
79 (html :ul
80 (loop for x from 1 to 10
81 do (html :li
82 (html :a
83 (ehref "chapter-~A-~A.html" id x)
84 (xfactory:text "Chapter ~A-~A" id x)))))
85 (html :a
86 (ehref "index.html")
87 "Back to Index")))))
88
89 (define-simple-route chapter-?-?.html ("chapter-:(id1)-:(id2).html" :overlay-master *frame*)
90 (xfactory:with-document-factory ((html))
91 (html :overlay
92 (etitle "Example 2: Chapter ~A-~A" id1 id2)
93 (html :div
94 (eid "content")
95 (html :h1
96 (xfactory:text "Chapter ~A-~A" id1 id2))
97 (html :p
98 (xfactory:text "This is a chapter ~A-~A" id1 id2))
99 (html :a
100 (ehref "chapter-~A.html" id1)
101 (xfactory:text "Back to Chapter ~A" id1))))))
102
103
104
09bce2b @archimag update
authored
105 (restas:reconnect-all-plugins)
106 (restas:start-web-server 8080)
Something went wrong with that request. Please try again.