r7061: initial property settings
[wol.git] / genpage.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10; Package: wol -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          genpage.lisp
6 ;;;; Purpose:       HTML Pages creation functions
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Jun 2003
9 ;;;;
10 ;;;; $Id$
11 ;;;;
12 ;;;; This file, part of wol, is Copyright (c) 2003 by Kevin M. Rosenberg
13 ;;;; *************************************************************************
14
15 (in-package #:wol)
16
17 (defvar *header-table* (make-hash-table :size 100 :test 'eq)
18   "Table of header functions indexed by site")
19 (defvar *banner-table* (make-hash-table :size 100 :test 'eq)
20   "Table of banner functions indexed by site")
21 (defvar *contents-table* (make-hash-table :size 100 :test 'eq)
22   "Table of table of content functions indexed by site")
23 (defvar *page-table* (make-hash-table :size 100 :test 'equal)
24   "Table of page functions indexed by site-pagename")
25 (defvar *footer-table* (make-hash-table :size 100 :test 'eq)
26   "Table of footer functions indexed by site")
27
28 (defun maybe-gen-header (site plist command)
29   (awhen (gethash site *header-table*) (funcall it plist command)))
30
31 (defun maybe-gen-footer (site plist command)
32   (awhen (gethash site *footer-table*) (funcall it plist command)))
33
34 (defun maybe-gen-banner (site plist command)
35   (awhen (gethash site *banner-table*) (funcall it plist command)))
36
37 (defun maybe-gen-contents (site plist command)
38   (awhen (gethash site *contents-table*) (funcall it plist command)))
39
40 (defmacro def-stdsite-header (site &body body)
41   `(setf (gethash ',site *header-table*)
42          #'(lambda (plist command)
43              (declare (ignorable plist command))
44              ,@body)))
45
46 (defmacro def-stdsite-footer (site &body body)
47   `(setf (gethash ',site *footer-table*)
48          #'(lambda (plist command)
49              (declare (ignorable plist command))
50              ,@body)))
51
52 (defmacro def-stdsite-banner (site &body body)
53   `(setf (gethash ',site *banner-table*)
54          #'(lambda (plist command)
55              (declare (ignorable plist command))
56              ,@body)))
57
58 (defmacro def-stdsite-contents (site &body body)
59   `(setf (gethash ',site *contents-table*)
60          #'(lambda (plist command)
61              (declare (ignorable plist command))
62              ,@body)))
63
64
65 (defmacro gen-std-head (title site plist command &body body)
66   `(html
67     (:head 
68      (when ,title
69        (html (:title ,title)))
70      (maybe-gen-header ',site ,plist ,command)
71      ,@body)))
72
73 (defmacro gen-std-footer (site plist command)
74   `(html
75     ((:div class "disclaimsec")
76      (maybe-gen-footer ',site ,plist ,command))))
77
78
79 (defmacro gen-std-body (site plist command &body body)
80   `(progn
81     ;;(maybe-gen-banner ',site ,plist ,command)
82     (html
83      ((:div class "stdbodytable")
84       ((:div :style "width:160px;position:fixed;left:3;right:auto;top:0")
85        ((:img :src "/images/umlisp-logo.png" :alt "logo" 
86               :style "border:0;width:160;height:55"))
87        (maybe-gen-contents ',site ,plist ,command))
88       ((:div :style "position:absolute;left:170px;top:0")
89        ((:div :style
90               "font-size:20pt;color:#777;text-align:center;margin-bottom:4pt")
91         "High Performance Common Lisp Interface to the Unified Medical Langauge System")
92        ,@body
93         (gen-std-footer ,site ,plist ,command))))))
94
95
96 (defun ml-head (title-str &optional (css "http://b9.com/main.css") altcss)
97   (html
98    (:head
99     ((:link :rel "stylesheet" :href css :type "text/css"))
100     (when altcss
101       (html
102        ((:link :rel "stylesheet" :type "text/css"
103                :href (if (eq altcss t)
104                          "http://b9.com/umls.css" altcss)))))
105     (when title-str
106       (html (:title (lml-write-string title-str)))))))
107
108
109 (defun page-prologue (title format css altcss)
110   (ecase format
111     (:xml
112      (dtd-prologue format)
113      (lml-format "<?xml-stylesheet type=\"text/css\" href=\"~A\" ?>~%"
114                  (aif css it "http://b9.com/umlsxml.css"))
115      (lml-write-string "<pagedata xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:html=\"http://www.w3.org/TR/REC-html40\">")
116      (lml-write-char #\Newline)
117      (when title
118        (lml-format "<pagetitle>~A</pagetitle>" title))
119      (lml-write-char #\Newline))
120     (:html
121      (dtd-prologue format)
122      (lml-write-string "<html>")
123      (ml-head title (aif css it "http://b9.com/main.css") altcss)
124      (lml-write-string "<body>"))
125     ((:xhtml :xhtml11 :xhtml10-strict :xhtml10-transitional
126       :xhtml10-frameset)
127      (dtd-prologue format)
128      (lml-write-string
129       "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">")
130      (ml-head title (aif css it "http://b9.com/main.css") altcss)
131      (lml-write-string "<body>"))
132     (:text
133      ;; nothing to do
134      )))
135
136 (defun page-epilogue (format)
137   (ecase format
138     ((:html :xhtml :xhtml11 :xhtml10-strict :xhtml10-transitional
139       :xhtml10-frameset)
140      (lml-write-string "</body></html>"))
141     (:xml
142      (lml-print "</pagedata>"))
143     (:text
144      ;; nothing to do
145      )))
146
147
148
149 (defun page-keyword-format (format)
150   (ecase format
151     ((:html :xhtml :xhtml11 :xhtml10-strict :xhtml10-transitional
152             :xhtml10-frameset)
153      :html)
154     (:xml
155      :xml)
156     (:text
157      :text)))
158
159 (defmacro with-lml-page ((title &key (format :xhtml) css altcss (precompute t))
160                          &rest body)
161   (let ((fmt (gensym "FMT-")))
162     `(let ((,fmt ,format))
163       (with-ml-page (:format (page-keyword-format ,fmt) :precompute ,precompute)
164         (let ((*html-stream* *modlisp-socket*))
165           (prog1
166               (progn
167                 (page-prologue ,title ,format ,css ,altcss)
168                 ,@body)
169             (page-epilogue ,format)))))))
170
171
172 (defmacro gen-std-page ((site plist command title &key css altcss
173                               (precompute t) (format :xhtml))
174                         &body body)
175   `(let ((*print-circle* nil))
176     (with-lml-page (,title :css ,css :altcss ,altcss :format ,format
177                     :precompute ,precompute)
178       (gen-std-body ,site ,plist ,command ,@body))))
179
180
181
182
183 (defmacro with-ml-link ((href &key (format :html)) &rest body)
184   `(case ,format
185      (:xml
186       (lml-princ "<xmllink xlink:type=\"simple\" xlink:href=\"")
187       (lml-princ ,href)
188       (lml-princ "\">")
189       ,@body
190       (lml-princ "</xmllink>"))
191     (:ie-xml
192       (lml-princ "<html:a href=\"")
193       (lml-princ ,href)
194       (lml-princ "\">")
195      ,@body
196      (lml-princ "</html:a>"))
197     ((:html :xhtml :xhtml11 :xhtml10-strict :xhtml10-transitional
198             :xhtml10-frameset)
199       (lml-princ "<a href=\"")
200      (lml-princ ,href)
201      (lml-princ "\">")
202      ,@body
203      (lml-princ "</a>"))))
204
205 (defun ml-link (page name session-id &key (format :html))
206   (case format
207     ((:html :xhtml :xhtml11 :xhtml10-strict :xhtml10-transitional
208             :xhtml10-frameset)
209      (html
210       ((:div class "homelink")
211        "Return to "
212        (with-ml-link ((make-ml-url page :session-id session-id :html t))
213          (lml-write-string name))
214        " page.")))
215     ((:xml :ie-xml)
216      (lml-princ "<homelink>Return to ")
217      (with-ml-link ((make-ml-url page :session-id session-id :html t)
218                     :format format)
219        (lml-write-string name))
220      (lml-write-string " page.</homelink>"))))
221
222 (defun ml-home-link (session-id &key (format :html))
223   (ml-link "index" "home" session-id :format format))
224
225 (defun ml-search-link (session-id &key (format :html))
226   (ml-link "search" "search" session-id :format format))
227
228
229
230