r5294: *** empty log message ***
[lml2.git] / base.lisp
1 ;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          base.lisp
6 ;;;; Purpose:       Lisp Markup Language functions
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Aug 2002
9 ;;;;
10 ;;;; $Id: base.lisp,v 1.7 2003/07/12 17:54:05 kevin Exp $
11 ;;;;
12 ;;;; This file, part of LML2, is Copyright (c) 2000-2003 by Kevin Rosenberg.
13 ;;;; Rights of modification and redistribution are in the LICENSE file.
14 ;;;;
15 ;;;; *************************************************************************
16
17 (in-package #:lml2)
18
19
20 (defun lml-format (str &rest args)
21   (when (streamp *html-stream*)
22     (if args
23         (apply #'format *html-stream* str args)
24         (write-string str *html-stream*))))
25
26 (defun lml-princ (s)
27   (princ s *html-stream*))
28
29 (defun lml-print (s)
30   (format *html-stream* "~A~%" s))
31
32 (defun lml-write-char (char)
33   (write-char char *html-stream*))
34
35 (defun lml-write-string (str)
36   (write-string str *html-stream*))
37
38 (defun lml-print-date (date)
39   (lml-write-string (date-string date)))
40
41 (defun dtd-prologue (&optional (format :xhtml11))
42   (case format
43     ((:xhtml :xhtml11 :xhtml10-strict :xhtml10-transitional :xhtml10-frameset :xml)
44      (lml-write-string +xml-prologue-string+)
45      (lml-write-char #\newline)))
46   (case format
47     ((:xhtml11 :xhtml)
48      (lml-write-string +xhtml11-dtd-string+))
49     (:xhtml10-strict
50      (lml-write-string +xhtml10-strict-dtd-string+))
51     (:xhtml10-transitional
52      (lml-write-string +xhtml10-transitional-dtd-string+))
53     (:xhtml10-frameset
54      (lml-write-string +xhtml10-frameset-dtd-string+))
55     (:html
56      (lml-write-string +html4-dtd-string+)))
57   (lml-write-char #\newline))
58
59
60 (defmacro html-file-page ((out-file &key (format :xhtml11))
61                           &body body)
62   `(with-open-file (*html-stream*
63                     (lml-file-name ,out-file :output)
64                     :direction :output
65                     :if-exists :supersede)
66      (dtd-prologue ,format)
67      (html
68       ((:html :xmlns "http://www.w3.org/1999/xhtml")
69        ,@body))))
70                      
71
72 (defmacro alink (url desc)
73   `(html
74     ((:a :href ,url) ,desc)))
75
76 (defmacro alink-c (class url desc)
77   `(html
78     ((:a :class ,class :href ,url) ,desc)))