1 ;;; --------------------------------------------------------------------------
2 ;;; CLFSWM - FullScreen Window Manager
4 ;;; --------------------------------------------------------------------------
5 ;;; Documentation: Html generator helper
6 ;;; --------------------------------------------------------------------------
8 ;;; (C) 2010 Philippe Brochard <hocwp@free.fr>
10 ;;; This program is free software; you can redistribute it and/or modify
11 ;;; it under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or
13 ;;; (at your option) any later version.
15 ;;; This program is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with this program; if not, write to the Free Software
22 ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 ;;; --------------------------------------------------------------------------
28 (in-package :common-lisp-user
)
31 (:use
:common-lisp
:tools
)
32 (:export
:insert-html-doctype
35 :produce-html-string
))
40 (defun insert-html-doctype ()
41 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
42 \"http://www.w3.org/TR/html4/transitional.dtd\">")
46 (defun produce-html (tree &optional
(level 0) (stream *standard-output
*))
48 (print-space level stream
)
49 (format stream
"~(<~A>~)~%" (first tree
))
50 (dolist (subtree (rest tree
))
51 (produce-html subtree
(+ 2 level
) stream
))
52 (print-space level stream
)
53 (format stream
"~(</~A>~)~%"
54 (if (stringp (first tree
))
55 (subseq (first tree
) 0 (position #\Space
(first tree
)))
58 (print-space level stream
)
59 (format stream
(if (stringp tree
) "~A~%" "~(~A~)~%") tree
))))
62 (defmacro with-html
((&optional
(stream t
)) &rest rest
)
63 `(produce-html ',@rest
0 ,stream
))
66 (defun produce-html-string (tree &optional
(level 0))
67 (with-output-to-string (str)
68 (produce-html tree level str
)))
81 ,(format nil
"Plip=~A" (+ 3 5))
82 ("a href=\"index.html\"" index
)
93 "<img src=\"toto.png\">"
103 (produce-html-string `(html
110 ,(format nil
"Plip=~A" (+ 3 5))
112 ("a href=\"index.html\"" Index
)