r5163: *** 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.1 2003/06/20 04:12: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 (defmacro xhtml-prologue ()
49   `(progn
50      (lml-write-string (xml-prologue-string))
51      (lml-write-char #\newline)
52      (lml-write-string (xhtml-prologue-string))
53      (lml-write-char #\newline)))
54
55 (defmacro print-page (title &body body)
56   `(html
57     (:head
58      (:title (:princ ,title)))
59     (:body ,@body)))
60
61 (defmacro page (out-file &body body)
62   `(with-open-file (*html-stream*
63                     (lml-file-name ,out-file :output)
64                     :direction :output
65                     :if-exists :supersede)
66      (xhtml-prologue)
67      (html
68       ((:html :xmlns "http://www.w3.org/1999/xhtml")
69        ,@body))))
70
71