-
Notifications
You must be signed in to change notification settings - Fork 3
/
routes-map-printer.lisp
55 lines (44 loc) · 1.9 KB
/
routes-map-printer.lisp
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
(in-package #:easy-routes)
(defparameter *indention* 4)
(defparameter *current-indention* nil)
(defgeneric print-route (route stream))
(defmethod print-route (route stream)
(format stream "~a" route))
(defmethod print-route ((route route) stream)
(princ (route-symbol route) stream))
(defmethod print-route ((route routes::variable-template) stream)
(format stream "{~(~A~)}" (routes::template-data route)))
(defmethod print-route ((route routes::wildcard-template) stream)
(format stream "*~(~A~)" (routes::template-data route)))
(defmethod print-route ((route cons) stream)
(cond
((typep (car route) 'routes::route)
(princ (required-method (car route)) stream)
(write-char #\space stream)
(write-string (routes::route-name (car route)) stream))
((and (typep (cdr route) 'cons)
(typep (car (cdr route)) 'route))
(print-route (car route) stream)
(if (equal (car route) "")
nil
(write-char #\space stream))
(print-route (cdr route) stream))
(t (print-route (car route) stream)
(write-string "/" stream)
(print-route (cdr route) stream))))
(defmethod print-route ((route routes::or-template) stream)
(let ((*current-indention* (if (null *current-indention*)
0
(+ *current-indention* *indention*))))
(loop for item in (routes::template-data route)
do
(write-char #\newline stream)
(write-string (make-string *current-indention* :initial-element #\Space) stream)
(print-route item stream))))
(defmethod print-route ((route routes::concat-template) stream)
(loop for item in (routes::template-data route)
do (print-route item stream)))
(defmethod describe-object ((mapper routes:mapper) stream)
(call-next-method)
(format stream "~%Tree of routes~%--------------~%")
(print-route (slot-value mapper 'routes::template) stream))