File: base.lisp

package info (click to toggle)
cl-lml2 1.6.6-4.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 184 kB
  • sloc: lisp: 1,316; makefile: 39
file content (103 lines) | stat: -rw-r--r-- 3,155 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
;;;; *************************************************************************
;;;; FILE IDENTIFICATION
;;;;
;;;; Name:          base.lisp
;;;; Purpose:       Lisp Markup Language functions
;;;; Programmer:    Kevin M. Rosenberg
;;;; Date Started:  Aug 2002
;;;;
;;;; $Id$
;;;;
;;;; This file, part of LML2, is Copyright (c) 2000-2003 by Kevin Rosenberg.
;;;; Rights of modification and redistribution are in the LICENSE file.
;;;;
;;;; *************************************************************************

(in-package #:lml2)


(defun lml-format (str &rest args)
  (when (streamp *html-stream*)
    (if args
        (apply #'format *html-stream* str args)
        (write-string str *html-stream*))))

(defun lml-princ (s)
  (princ s *html-stream*))

(defun lml-print (s)
  (format *html-stream* "~A~%" s))

(defun lml-write-char (char)
  (write-char char *html-stream*))

(defun lml-write-string (str)
  (write-string str *html-stream*))

(defun lml-print-date (date)
  (lml-write-string (date-string date)))

(defun xml-header-stream (stream &key (version "1.0") (standalone :unspecified)
                   (encoding :unspecified))
  (format stream "<?xml version=\"~A\"~A~A ?>"
          version
          (if (eq standalone :unspecified)
              ""
              (format nil " standalone=\"~A\"" standalone))
          (if (eq encoding :unspecified)
              ""
              (format nil " encoding=\"~A\"" encoding))))

(defun dtd-prologue (&optional (format :xhtml11) (encoding :iso-8859-1) &key entities)
  (ecase format
    ((:xhtml :xhtml11 :xhtml10-strict :xhtml10-transitional :xhtml10-frameset :xml)
     (lml-write-string +xml-prologue-begin+)
     (ecase encoding
       (:iso-8859-1
        (lml-write-string "iso-8859-1"))
       (:utf-8
        (lml-write-string "UTF-8")))
     (lml-write-string +xml-prologue-end+)
     (lml-write-char #\newline)
     (case format
       ((:xhtml11 :xhtml)
        (lml-write-string +xhtml11-dtd-string+))
       (:xhtml10-strict
        (lml-write-string +xhtml10-strict-dtd-string+))
       (:xhtml10-transitional
        (lml-write-string +xhtml10-transitional-dtd-string+))
       (:xhtml10-frameset
        (lml-write-string +xhtml10-frameset-dtd-string+)))
     (when entities
       (lml-write-char #\space)
       (lml-write-char #\[)
       (lml-write-char #\Newline)
       (lml-write-string entities)
       (lml-write-char #\Newline)
       (lml-write-char #\]))
     (lml-write-char #\>))
    (:html
     (lml-write-string +html4-dtd-string+)))
  (lml-write-char #\newline))


(defmacro html-file-page ((out-file &key (format :xhtml11))
                          &body body)
  `(with-open-file (*html-stream*
                    (lml-file-name ',out-file :output)
                    :direction :output
                    :if-exists :supersede)
     (dtd-prologue ,format)
     (html
      ((:html :xmlns "http://www.w3.org/1999/xhtml")
       ,@body))))


(defmacro alink (url desc)
  `(html
    ((:a :href ,url) ,desc)))

(defmacro alink-c (class url desc)
  `(html
    ((:a :class ,class :href ,url) ,desc)))