expand binary paths
[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$
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 xml-header-stream (stream &key (version "1.0") (standalone :unspecified)
42                    (encoding :unspecified))
43   (format stream "<?xml version=\"~A\"~A~A ?>"
44           version
45           (if (eq standalone :unspecified)
46               ""
47               (format nil " standalone=\"~A\"" standalone))
48           (if (eq encoding :unspecified)
49               ""
50               (format nil " encoding=\"~A\"" encoding))))
51
52 (defun dtd-prologue (&optional (format :xhtml11) (encoding :iso-8859-1) &key entities)
53   (ecase format
54     ((:xhtml :xhtml11 :xhtml10-strict :xhtml10-transitional :xhtml10-frameset :xml)
55      (lml-write-string +xml-prologue-begin+)
56      (ecase encoding
57        (:iso-8859-1
58         (lml-write-string "iso-8859-1"))
59        (:utf-8
60         (lml-write-string "UTF-8")))
61      (lml-write-string +xml-prologue-end+)
62      (lml-write-char #\newline)
63      (case format
64        ((:xhtml11 :xhtml)
65         (lml-write-string +xhtml11-dtd-string+))
66        (:xhtml10-strict
67         (lml-write-string +xhtml10-strict-dtd-string+))
68        (:xhtml10-transitional
69         (lml-write-string +xhtml10-transitional-dtd-string+))
70        (:xhtml10-frameset
71         (lml-write-string +xhtml10-frameset-dtd-string+)))
72      (when entities
73        (lml-write-char #\space)
74        (lml-write-char #\[)
75        (lml-write-char #\Newline)
76        (lml-write-string entities)
77        (lml-write-char #\Newline)
78        (lml-write-char #\]))
79      (lml-write-char #\>))
80     (:html
81      (lml-write-string +html4-dtd-string+)))
82   (lml-write-char #\newline))
83
84
85 (defmacro html-file-page ((out-file &key (format :xhtml11))
86                           &body body)
87   `(with-open-file (*html-stream*
88                     (lml-file-name ',out-file :output)
89                     :direction :output
90                     :if-exists :supersede)
91      (dtd-prologue ,format)
92      (html
93       ((:html :xmlns "http://www.w3.org/1999/xhtml")
94        ,@body))))
95
96
97 (defmacro alink (url desc)
98   `(html
99     ((:a :href ,url) ,desc)))
100
101 (defmacro alink-c (class url desc)
102   `(html
103     ((:a :class ,class :href ,url) ,desc)))