r5182: *** 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.4 2003/06/23 23:58:29 kevin Exp $
11 ;;;;
12 ;;;; This file, part of LML, is Copyright (c) 2002 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; LML users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the GNU General Public License v2
16 ;;;; (http://www.gnu.org/licenses/gpl.html)
17 ;;;; *************************************************************************
18
19 (in-package #:lml2)
20
21
22 (defun reset-indent ()
23   (setq *indent* 0))
24
25 (defun lml-format (str &rest args)
26   (when (streamp *html-stream*)
27     (when *print-spaces* (indent-spaces *indent* *html-stream*))
28     (if args
29         (apply #'format *html-stream* str args)
30       (write-string str *html-stream*))
31     (when *print-spaces* (write-char #\newline *html-stream*))))
32
33 (defun lml-princ (s)
34   (princ s *html-stream*))
35
36 (defun lml-print (s)
37   (format *html-stream* "~A~%" s))
38
39 (defun lml-write-char (char)
40   (write-char char *html-stream*))
41
42 (defun lml-write-string (str)
43   (write-string str *html-stream*))
44
45 (defun lml-print-date (date)
46   (lml-write-string (date-string date)))
47
48 (defun dtd-prologue (&optional (format :xhtml11))
49   (case format
50     ((:xhtml :xhtml11 :xhtml10-strict :xhtml10-transitional :xhtml10-frameset :xml)
51      (lml-write-string +xml-prologue-string+)
52      (lml-write-char #\newline)))
53   (case format
54     ((:xhtml11 :xhtml)
55      (lml-write-string +xhtml11-dtd-string+))
56     (:xhtml10-strict
57      (lml-write-string +xhtml10-strict-dtd-string+))
58     (:xhtml10-transitional
59      (lml-write-string +xhtml10-transitional-dtd-string+))
60     (:xhtml10-frameset
61      (lml-write-string +xhtml10-frameset-dtd-string+))
62     (:html
63      (lml-write-string +html4-dtd-string+)))
64   (lml-write-char #\newline))
65
66
67 (defmacro page ((out-file &key (format :xhtml11))
68                 &body body)
69   `(with-open-file (*html-stream*
70                     (lml-file-name ,out-file :output)
71                     :direction :output
72                     :if-exists :supersede)
73      (html-prologue ,format)
74      (html
75       ((:html :xmlns "http://www.w3.org/1999/xhtml")
76        ,@body))))
77
78                      
79
80 (defmacro alink (url desc)
81   `(html
82     ((:a :href ,url) ,desc)))
83
84 (defmacro alink-c (class url desc)
85   `(html
86     ((:a :class ,class :href ,url) ,desc)))