-
Notifications
You must be signed in to change notification settings - Fork 0
/
genhtml.lisp
131 lines (109 loc) · 3.36 KB
/
genhtml.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
(defmacro as (tag content)
`(format t "<~(~A~)>~A</~(~A~)>"
`,tag, content, `,tag))
(defmacro with (tag &rest body)
`(progn
(format t "~&<~(~A~)>%" `,tag)
,@body
(format t "~&</~(~A~)>~%" `,tag)))
(defun brs (&optional (n 1))
(fresh-line)
(dotimes (i n)
(princ "<br>"))
(terpri))
(defun html-file (base)
(format nil "~(~A~).html" base))
(defmacro page (name title &rest body)
(let ((ti (gensym)))
`(with-open-file (*standard-output*
(html-file ,name)
:direction :output
:if-exists :supersede)
(let ((,ti ,title))
(as title ,ti)
(with center
(as h2 (string-upcase, ti)))
(brs 3)
,@body))))
(defmacro with-link (dest &rest body)
`(progn
(format t "<a href=\"~A\">" (html-file, dest))
,@body
(princ "</a>")))
(defun link-item (dest text)
(princ "<li>")
(with-link dest
(princ text)))
(defun button (dest text)
(princ "[ ")
(with-link dest
(princ text))
(format t " ]~%"))
(defparameter *sections* nil)
(defstruct item
id title text)
(defstruct section
id title items)
(defmacro defitem (id title text)
`(setf ,id
(make-item :id `,id
:title ,title
:text ,text)))
(defmacro defsection (id title &rest items)
`(setf ,id
(make-section :id `,id
:title ,title
:items (list, @items))))
(defun defsite (&rest sections)
(setf *sections* sections))
(defconstant contents "contents")
(defconstant index "index")
(defun gen-contents (&optional (secitons *sections*))
(page contents contents
(with ol
(dolist (s sections)
(link-item (section-id s) (section-title s))
(brs 2))
(link-item index (string-capitalize index)))))
(defun gen-index (&optional (sections *sections*))
(page index index
(with ol
(dolist (i (all-items sections))
(link-item (item-id i) (item-title i))
(brs 2)))))
(defun all-items (sections)
(let ((is nil))
(dolist (s sections)
(dolist (i (section-items s))
(setf is (merge `list (list i) is #`title<))))
is))
(defun title< (x y)
(string-lessp (item-title x) (item-title y)))
(defun gen-site ()
(map3 #`gen-section *sections*)
(gen-contents)
(gen-index))
(defun gen-seciton (sect <sect sect>)
(page (section-id sect) (section-title sect)
(with ol
(map3 #`(lambda (item <item item>)
(link-item (item-id item)
(item-title item))
(brs 2)
(gen-item sect item <item item>))
(section-items sect)))
(brs 3)
(gen-move-buttons (if <sect (section-id <sect))
contnets
(if sect> (section-id sect>)))))
(defun gen-item (sect list <item item>)
(page (item-id item) (item-title item)
(princ (item-text item))
(brs 3)
(gen-move-buttons (if <item (item-id <item))
(section-id sect)
(if item> (item-id item>)))))
(defun gen-move-buttons (back up forward)
(if back (button back "Back"))
(if up (button up "Up"))
(if forward (button forward "Forward")))