Update domain name to kpe.io
[lml.git] / api.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          api.lisp
6 ;;;; Purpose:       Macros for generating API documentation
7 ;;;; Programmer:    Kevin M. Rosenberg based on Matthew Danish's code
8 ;;;; Date Started:  Nov 2002
9 ;;;;
10 ;;;; $Id$
11 ;;;;
12 ;;;; This file, part of LML, is Copyright (c) 2002 by Kevin M. Rosenberg
13 ;;;; and Copyright (c) 2002 Matthew Danish
14 ;;;;
15 ;;;; LML users are granted the rights to distribute and use this software
16 ;;;; as governed by the terms of the GNU General Public License v2
17 ;;;; (http://www.gnu.org/licenses/gpl.html)
18 ;;;; *************************************************************************
19
20 (in-package #:lml)
21
22 ;;; Copyright (c) 2002 Matthew Danish.
23 ;;; All rights reserved.
24
25 ;;; Redistribution and use in source and binary forms, with or without
26 ;;; modification, are permitted provided that the following conditions
27 ;;; are met:
28 ;;; 1. Redistributions of source code must retain the above copyright
29 ;;;    notice, this list of conditions and the following disclaimer.
30 ;;; 2. Redistributions in binary form must reproduce the above copyright
31 ;;;    notice, this list of conditions and the following disclaimer in the
32 ;;;    documentation and/or other materials provided with the distribution.
33 ;;; 3. The name of the author may not be used to endorse or promote products
34 ;;;    derived from this software without specific prior written permission.
35 ;;;
36 ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
37 ;;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38 ;;; OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
39 ;;; IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
40 ;;; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 ;;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 ;;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 ;;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 ;;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
45 ;;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46
47 ;;; For an example, see Matthew Danish's cl-ftp documentation at
48 ;;; http://www.mapcar.org/~mrd/cl-sql/
49
50 (defmacro api-list (&body body)
51   `(ul ,@(loop for item in body collect `(li ,item))))
52
53 (defun stringify (x)
54   (let ((*print-case* :downcase))
55     (if (null x)
56         "()"
57         (format nil "~A" x))))
58
59 (defmacro with-class-info ((class-name superclasses &rest slot-docs) &body other-info)
60   `(p (i "Class ") (b ,(stringify class-name))
61     (i " derived from ") ,(stringify superclasses) " -- " (br)
62     (i "Initargs:") (br)
63     (ul
64      ,@(loop for (slot-name slot-desc slot-default) in slot-docs collect
65              `(li (tt ,(format nil ":~A" slot-name))
66                " -- " ,slot-desc " -- " (i "Default: ")
67                ,(if (eql slot-default :n/a)
68                     "Not specified"
69                     (format nil "~S" slot-default)))))
70     ,@other-info))
71
72 (defmacro with-macro-info ((macro-name &rest lambda-list) &body other-info)
73   `(p (i "Macro ") (b ,(stringify macro-name)) " "
74     (tt ,(stringify lambda-list)) (br)
75     ,@other-info))
76
77 (defmacro with-function-info ((function-name &rest lambda-list) &body other-info)
78   `(p (i "Function ") (b ,(stringify function-name)) " "
79     (tt ,(stringify lambda-list))
80     (br) ,@other-info))
81
82 (defmacro with-condition-info ((condition-name supers &rest slot-docs) &body other-info)
83   `(p (i "Condition ") (b ,(stringify condition-name))
84     (i " derived from ") ,(stringify supers) " -- " (br)
85     (i "Slots:") (br)
86     (ul
87      ,@(loop for (slot-name slot-desc slot-reader slot-initarg slot-default) in slot-docs collect
88              `(li (tt ,(stringify slot-name))
89                " -- " ,slot-desc " -- " (i " Default: ")
90                ,(if (eql slot-default :n/a)
91                     "Not specified"
92                     (format nil "~S" slot-default)))))
93     ,@other-info))
94
95 (defmacro with-functions (&rest slots)
96   `(progn ,@(loop for (fn description . args) in slots collect
97                   `(with-function-info (,fn ,@(if args args
98                                                   '(connection-variable)))
99                     ,description))))