Show
Ignore:
Timestamp:
06/02/08 12:07:08 (7 months ago)
Author:
edi
Message:

Add hacks from flight

Now generates output compatible with Hans' clixdoc

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/thirdparty/documentation-template

    • Property svn:ignore set to
      *.ofasl
  • trunk/thirdparty/documentation-template/doc

    • Property svn:ignore set to
      *.ofasl
  • trunk/thirdparty/documentation-template/output.lisp

    r3242 r3244  
    11;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: DOCUMENTATION-TEMPLATE; Base: 10 -*- 
    2 ;;; $Header: /usr/local/cvsrep/documentation-template/output.lisp,v 1.14 2008/05/29 08:23:37 edi Exp $ 
     2;;; $Header: /usr/local/cvsrep/documentation-template/output.lisp,v 1.16 2008/06/01 21:26:20 edi Exp $ 
    33 
    44;;; Copyright (c) 2006-2008, Dr. Edmund Weitz.  All rights reserved. 
     
    3030(in-package :documentation-template) 
    3131 
    32 (defun write-entry-header (name type &key (write-name-p t)) 
    33   "Writes the header for a documentation entry of name NAME and 
    34 type TYPE.  The HTML anchor will only get a 'name' attribute if 
    35 WRITE-NAME-P is true and NAME is not a SETF name." 
    36   (format t "~%~%<!-- Entry for ~A -->~%~%<p><br>[~A]<br><a class=none~@[ name='~A'~]>"  
    37           name type (and write-name-p (atom name) (string-downcase name)))) 
    38  
    39 (defun write-entry-footer (name doc-string) 
    40   "Writes the footer for a documentation entry for the name NAME 
    41 including the documentation string DOC-STRING." 
    42   (format t "~%<blockquote><br>~%~%~@[~A~]~%~%</blockquote>~%~%<!-- End of entry for ~A -->~%" 
    43           (and doc-string (escape-string-iso-8859 doc-string)) name)) 
    44  
    4532(defun write-constant-entry (symbol doc-string) 
    4633  "Writes a full documentation entry for the constant SYMBOL." 
    47   (write-entry-header symbol "Constant"
    48   (format t "<b>~A</b></a>" (string-downcase symbol)
    49   (write-entry-footer symbol doc-string)) 
     34  (with-html-output (*doc-output* nil :indent 2
     35    (:|clix:constant| :name (string-downcase symbol
     36     (:|clix:description| (esc doc-string))))) 
    5037 
    5138(defun write-special-var-entry (symbol doc-string) 
    52   "Writes a full documentation entry for the special variable 
    53 SYMBOL." 
    54   (write-entry-header symbol "Special variable") 
    55   (format t "<b>~A</b></a>" (string-downcase symbol)) 
    56   (write-entry-footer symbol doc-string)) 
     39  "Writes a full documentation entry for the special variable SYMBOL." 
     40  (with-html-output (*doc-output* nil :indent 2) 
     41    (:|clix:special-variable| :name (string-downcase symbol) 
     42     (:|clix:description| (esc doc-string))))) 
    5743 
    5844(defun write-class-entry (symbol doc-string) 
    5945  "Writes a full documentation entry for the class SYMBOL." 
    60   (write-entry-header symbol (if (subtypep symbol 'condition) 
    61                                "Condition type" "Standard class")) 
    62                                 
    63   (format t "<b>~A</b></a>" (string-downcase symbol)) 
    64   (write-entry-footer symbol doc-string)) 
     46  (with-html-output (*doc-output* nil :indent 2) 
     47    (cond ((subtypep symbol 'condition) 
     48           (htm 
     49            (:|clix:condition| :name (string-downcase symbol) 
     50             (:|clix:description| (esc doc-string))))) 
     51          (t 
     52           (htm 
     53            (:|clix:class| :name (string-downcase symbol) 
     54             (:|clix:description| (esc doc-string)))))))) 
    6555 
    6656(defun write-lambda-list* (lambda-list &optional specializers) 
    6757  "The function which does all the work for WRITE-LAMBDA-LIST and 
    68 calls itself recursive if needed." 
     58calls itself recursively if needed." 
    6959  (let (body-seen after-required-args-p (firstp t)) 
    7060    (dolist (part lambda-list) 
     
    7363                 (setq part (first part))) 
    7464               (unless firstp 
    75                  (write-char #\Space)) 
     65                 (write-char #\Space *doc-output*)) 
    7666               (setq firstp nil) 
    7767               (cond ((consp part) 
    7868                      ;; a destructuring lambda list - recurse 
    79                       (write-char #\(
     69                      (write-char #\( *doc-output*
    8070                      (write-lambda-list* part) 
    81                       (write-char #\))) 
     71                      (write-char #\) *doc-output*)) 
    8272                     ((member part '(&key &optional &rest &allow-other-keys &aux &environment &whole)) 
    8373                      ;; marks these between <tt> and </tt> 
    8474                      (setq after-required-args-p t) 
    85                       (format t "<tt>~A</tt>" (escape-string (string-downcase part)))) 
     75                      (with-html-output (*doc-output* nil :indent 2) 
     76                        (:|clix:lkw| (esc (subseq (string-downcase part) 1))))) 
    8677                     ((eq part '&body) 
    8778                      ;; we don't really write '&BODY', we write it 
     
    8980                      (setq body-seen t 
    9081                            after-required-args-p t) 
    91                       (write-string "declaration* statement*")) 
     82                      (write-string "declaration* statement*" *doc-output*)) 
    9283                     (t 
    9384                      (let ((specializer (pop specializers))) 
    94                         (cond ((and specializer (not (eq specializer t))) 
    95                                ;; add specializers if there are any left 
    96                                (write-string (escape-string 
    97                                               (string-downcase 
    98                                                (format nil "(~A ~A)" part specializer))))) 
    99                               (t (write-string (escape-string (string-downcase part))))))))))))) 
    100  
    101 (defun write-lambda-list (lambda-list &key (resultp t) specializers) 
     85                        (write-string (escape-string 
     86                                       (string-downcase 
     87                                        (cond ((and specializer (not (eq specializer t))) 
     88                                               ;; add specializers if there are any left 
     89                                               (format nil "(~A ~A)" part specializer)) 
     90                                              (t part)))) 
     91                                      *doc-output*))))))))) 
     92 
     93(defun write-lambda-list (lambda-list &key specializers qualifiers (resultp t)) 
    10294  "Writes the lambda list LAMBDA-LIST, optionally with the 
    10395specializers SPECIALIZERS.  Adds something like `=> result' at 
    10496the end if RESULTP is true." 
    105   (write-string "<i>") 
    106   (write-lambda-list* lambda-list specializers) 
    107   (write-string "</i>") 
    108   (when resultp 
    109     (write-string " =&gt; <i>result</i></a>"))) 
     97  (with-html-output (*doc-output* nil :indent 2) 
     98    (:|clix:lambda-list| 
     99     (write-lambda-list* lambda-list specializers) 
     100     (dolist (qualifier qualifiers) 
     101       (htm 
     102        (:|clix:qualifier| (string-downcase qualifier))))) 
     103    (when resultp 
     104      (htm 
     105       (:|clix:returns| "result"))))) 
    110106 
    111107(defun write-macro-entry (symbol lambda-list doc-string) 
    112108  "Writes a full documentation entry for the macro SYMBOL." 
    113   (write-entry-header symbol "Macro"
    114   (format t "<b>~A</b> " (string-downcase symbol)
    115   (write-lambda-list lambda-list) 
    116   (write-entry-footer symbol doc-string)) 
     109  (with-html-output (*doc-output* nil :indent 2
     110    (:|clix:function| :macro "true" :name (string-downcase symbol
     111     (write-lambda-list lambda-list) 
     112     (:|clix:description| (esc doc-string))))) 
    117113 
    118114(defun write-function-entry (name lambda-list doc-string other-entries 
    119                                   &key genericp signature-only-p specializers qualifiers) 
     115                                  &key genericp specializers qualifiers) 
    120116  "Writes a full documentation entry for the function, generic 
    121117function, or method with name NAME.  NAME is a generic function 
    122118if GENERICP is true, SPECIALIZERS is a list of specializers, 
    123119i.e. in this case NAME is a method.  Likewise, QUALIFIERS is a 
    124 list of qualifiers.  SIGNATURE-ONLY-P means that we don't want a 
    125 full header." 
     120list of qualifiers." 
    126121  (let* ((setfp (consp name)) 
    127122         (symbol (if setfp (second name) name)) 
     
    140135         (resultp (and (not setfp) 
    141136                       (null (intersection '(:before :after) 
    142                                            qualifiers)))))     
    143     (cond (signature-only-p 
    144            (write-string "<a class=none>")) 
    145           (t 
    146            (write-entry-header name (if writer 
    147                                       (ecase type 
    148                                         (:method "Specialized accessor") 
    149                                         (:generic-function "Generic accessor") 
    150                                         (:function "Accessor")) 
    151                                       (ecase type 
    152                                         (:method "Method") 
    153                                         (:generic-function "Generic function") 
    154                                         (:function "Function"))) 
    155                                :write-name-p (null specializers)))) 
    156     (cond (setfp 
    157            (format t "<tt>(setf (</tt><b>~A</b> " (string-downcase symbol)) 
    158            (write-lambda-list (rest lambda-list) :resultp resultp :specializers (rest specializers)) 
    159            (write-string "<tt>)</tt> ") 
    160            ;; we should use the specializer here as well 
    161            (format t "<i>~A</i>" (string-downcase (first lambda-list))) 
    162            (write-string "<tt>)</tt></a>") 
    163            (format t "~(~{<tt> ~S</tt>~^~}~)" qualifiers)) 
    164           (t (format t "<b>~A</b> " (string-downcase symbol)) 
    165              (write-lambda-list lambda-list :specializers specializers :resultp resultp) 
    166              (format t "~(~{<tt> ~S</tt>~^~}~)" qualifiers))) 
    167     (when writer 
    168       ;; if this is an accessor, the add the writer immediately after 
    169       ;; the reader.. 
    170       (format t "~%<br>") 
    171       (destructuring-bind (name doc-type lambda-list doc-string &optional specializers qualifiers) 
    172           writer 
    173         (declare (ignore doc-type doc-string)) 
    174         (write-function-entry name lambda-list nil nil 
    175                               :signature-only-p t 
    176                               :specializers specializers 
    177                               :qualifiers qualifiers)) 
    178       ;; ...and remove it from the list of entries which haven't been 
    179       ;; written yet 
    180       (setq other-entries (remove writer other-entries)))) 
    181   (unless signature-only-p 
    182     (write-entry-footer name doc-string)) 
     137                                           qualifiers))))) 
     138    (cond       
     139     (writer 
     140      (with-html-output (*doc-output* nil :indent 2) 
     141        (:|clix:accessor| 
     142         :generic (and genericp "true") 
     143         :specialized specializers 
     144         :name (string-downcase symbol) 
     145         (write-lambda-list lambda-list 
     146                            :specializers specializers 
     147                            :qualifiers qualifiers 
     148                            :resultp resultp) 
     149         (:|clix:description| (esc doc-string)))) 
     150      (setq other-entries (remove writer other-entries))) 
     151     (t 
     152      (with-html-output (*doc-output* nil :indent 2) 
     153        (:|clix:accessor| 
     154         :generic (and genericp "true") 
     155         :specialized specializers 
     156         :name (string-downcase symbol) 
     157         (write-lambda-list lambda-list 
     158                            :specializers (if setfp (rest specializers) specializers) 
     159                            :qualifiers (if setfp (rest qualifiers) qualifiers) 
     160                            :resultp resultp) 
     161         (:|clix:description| (esc doc-string))))))) 
    183162  other-entries) 
    184163 
     
    189168  (destructuring-bind (name doc-type lambda-list doc-string &optional specializers qualifiers) 
    190169      entry 
    191     (unless (or (consp name) specializers) 
    192       ;; add NAME to index list unless it's a SETF name or the name of 
    193       ;; a method 
    194       (push name *symbols*)) 
    195170    (ecase doc-type 
    196171      (:constant (write-constant-entry name doc-string)) 
     
    209184  other-entries) 
    210185 
    211 (defun write-page-header (package-name subtitle symbols) 
    212   "Writes the header of the HTML page.  Assumes that the library 
    213 has the same name as the package.  Adds a list of all exported 
    214 symbols with links." 
    215   (format t "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"> 
    216 <html>  
    217  
    218 <head> 
    219   <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"> 
    220   <title>~A - ~A</title> 
    221   <style type=\"text/css\"> 
    222   pre { padding:5px; background-color:#e0e0e0 } 
    223   h3, h4 { text-decoration: underline; } 
    224   a { text-decoration: none; padding: 1px 2px 1px 2px; } 
    225   a:visited { text-decoration: none; padding: 1px 2px 1px 2px; } 
    226   a:hover { text-decoration: none; padding: 1px 1px 1px 1px; border: 1px solid #000000; }  
    227   a:focus { text-decoration: none; padding: 1px 2px 1px 2px; border: none; } 
    228   a.none { text-decoration: none; padding: 0; } 
    229   a.none:visited { text-decoration: none; padding: 0; }  
    230   a.none:hover { text-decoration: none; border: none; padding: 0; }  
    231   a.none:focus { text-decoration: none; border: none; padding: 0; }  
    232   a.noborder { text-decoration: none; padding: 0; }  
    233   a.noborder:visited { text-decoration: none; padding: 0; }  
    234   a.noborder:hover { text-decoration: none; border: none; padding: 0; }  
    235   a.noborder:focus { text-decoration: none; border: none; padding: 0; }   
    236   pre.none { padding:5px; background-color:#ffffff } 
    237   </style> 
    238 </head> 
    239  
    240 <body bgcolor=white> 
    241  
    242 <h2> ~2:*~A - ~A</h2> 
    243  
    244 <blockquote> 
    245 <br>&nbsp;<br><h3><a name=abstract class=none>Abstract</a></h3> 
    246  
    247 The code comes with 
    248 a <a 
    249 href=\"http://www.opensource.org/licenses/bsd-license.php\">BSD-style 
    250 license</a> so you can basically do with it whatever you want. 
    251  
    252 <p> 
    253 <font color=red>Download shortcut:</font> <a href=\"http://weitz.de/files/~A.tar.gz\">http://weitz.de/files/~:*~A.tar.gz</a>. 
    254 </blockquote> 
    255  
    256 <br>&nbsp;<br><h3><a class=none name=\"contents\">Contents</a></h3> 
    257 <ol> 
    258   <li><a href=\"#download\">Download</a> 
    259   <li><a href=\"#dictionary\">The ~A dictionary</a> 
    260     <ol> 
    261 ~{      <li><a href=\"#~A\"><code>~:*~A</code></a> 
    262 ~}    </ol> 
    263   <li><a href=\"#ack\">Acknowledgements</a> 
    264 </ol> 
    265  
    266 <br>&nbsp;<br><h3><a class=none name=\"download\">Download</a></h3> 
    267  
    268 ~2:*~A together with this documentation can be downloaded from <a 
    269 href=\"http://weitz.de/files/~2:*~A.tar.gz\">http://weitz.de/files/~:*~A.tar.gz</a>. The 
    270 current version is 0.1.0. 
    271  
    272 <br>&nbsp;<br><h3><a class=none name=\"dictionary\">The ~A dictionary</a></h3> 
    273  
    274 " 
    275           package-name subtitle (string-downcase package-name) 
    276           package-name symbols)) 
    277  
    278 (defun write-page-footer () 
    279   "Writes the footer of the HTML page." 
    280   (write-string " 
    281  
    282 <br>&nbsp;<br><h3><a class=none name=\"ack\">Acknowledgements</a></h3> 
    283  
    284 <p> 
    285 This documentation was prepared with <a href=\"http://weitz.de/documentation-template/\">DOCUMENTATION-TEMPLATE</a>. 
    286 </p> 
    287 <p> 
    288 $Header: /usr/local/cvsrep/documentation-template/output.lisp,v 1.14 2008/05/29 08:23:37 edi Exp $ 
    289 <p><a href=\"http://weitz.de/index.html\">BACK TO MY HOMEPAGE</a> 
    290  
    291 </body> 
    292 </html>")) 
    293  
    294186(defun create-template (package &key (target (or *target* 
    295187                                                 #-:lispworks (error "*TARGET* not specified.") 
     
    297189                                                 (capi:prompt-for-file "Select an output target:" 
    298190                                                                       :operation :save 
    299                                                                        :filters '("HTML Files" "*.HTML;*.HTM" 
     191                                                                       :filters '("XML Files" 
     192                                                                                  "*.XML" 
    300193                                                                                  "All Files" "*.*") 
    301                                                                        :filter "*.HTML;*.HTM"))) 
    302                                      (subtitle "a cool library") 
    303                                      ((:maybe-skip-methods-p *maybe-skip-methods-p*) 
    304                                       *maybe-skip-methods-p*) 
    305                                      (if-exists :supersede) 
    306                                      (if-does-not-exist :create)) 
    307   "Writes an HTML page with preliminary documentation entries and an 
    308 index for all exported symbols of the package PACKAGE to the file 
    309 TARGET.  If MAYBE-SKIP-METHODS-P is true, documentation entries for 
    310 inidividual methods are skipped if the corresponding generic function 
    311 has a documentation string." 
     194                                                                       :filter "*.XML"))) 
     195                                (subtitle "a cool library") 
     196                                ((:maybe-skip-methods-p *maybe-skip-methods-p*) 
     197                                 *maybe-skip-methods-p*) 
     198                                (if-exists :supersede) 
     199                                (if-does-not-exist :create)) 
     200  "Writes an XML file with documentation entries for all exported 
     201symbols of the package PACKAGE to the file TARGET.  If 
     202MAYBE-SKIP-METHODS-P is true, documentation entries for inidividual 
     203methods are skipped if the corresponding generic function has a 
     204documentation string." 
    312205  (when target 
    313206    (setq *target* target)) 
    314   (let (*symbols*) 
    315     (with-open-file (*standard-output* target 
    316                                        :direction :output 
    317                                        :if-exists if-exists 
    318                                        :if-does-not-exist if-does-not-exist) 
    319       (let ((body 
    320              (with-output-to-string (*standard-output*) 
    321                (let ((entries (collect-all-doc-entries package))) 
    322                  (loop 
    323                   (let ((entry (or (pop entries) (return)))) 
    324                     (setq entries (write-entry entry entries)))))))) 
    325         (write-page-header (package-name package) subtitle 
    326                            (mapcar #'string-downcase (reverse *symbols*))) 
    327         (write-string body) 
    328         (write-page-footer)))) 
     207  (with-open-file (*doc-output* target 
     208                                :direction :output 
     209                                :if-exists if-exists 
     210                                :if-does-not-exist if-does-not-exist) 
     211    (setf (html-mode) :xml) 
     212    (let ((*html-empty-tag-aware-p* nil) 
     213          (package-name (package-name package))) 
     214      (with-html-output (*doc-output* *doc-output* :prologue #.+clix-prologue+ :indent 2) 
     215        (:|clix:documentation| 
     216         :xmlns "http://www.w3.org/1999/xhtml" 
     217         :|xmlns:clix| "http://bknr.net/clixdoc" 
     218         (:|clix:title| 
     219          (esc package-name) 
     220          " - " 
     221          (esc subtitle)) 
     222         (:|clix:short-description| 
     223          (esc subtitle)) 
     224         (:h2 
     225          (esc package-name) 
     226          " - " 
     227          (esc subtitle)) 
     228         (:blockquote 
     229          (:|clix:chapter| :name "abstract" :title "Abstract") 
     230          (:p 
     231           "The code comes with a " 
     232           (:a :href "http://www.opensource.org/licenses/bsd-license.php" "BSD-style license") 
     233           " so you can basically do with it whatever you want.") 
     234          (:p 
     235           (:font :color "red" "Download shortcut:") 
     236           (:a :href (format nil "http://weitz.de/files/~(~A~).tar.gz" package-name)               
     237            (fmt "http://weitz.de/files/~(~A~).tar.gz" package-name)) 
     238           ".")) 
     239         (:|clix:chapter| :name "contents" :title "Contents") 
     240         (:|clix:contents|) 
     241         (:|clix:chapter| :name "dict" :title (format nil "The ~A dictionary" package-name) 
     242          (let ((entries (collect-all-doc-entries package))) 
     243            (loop 
     244             (let ((entry (or (pop entries) (return)))) 
     245               (setq entries (write-entry entry entries)))))) 
     246         (:|clix:chapter| :name "index" :title "Symbol index" 
     247          "Here are all exported symbols of the " 
     248          (:code (str package-name)) 
     249          " package in alphabetical order linked to their 
     250corresponding documentation entries:" 
     251          (:|clix:index|)) 
     252         (:|clix:chapter| :name "ack" :title "Ackknowledgements" 
     253          (:p 
     254           "This documentation was prepared with " 
     255           (:a :href "http://weitz.de/documentation-template/" "DOCUMENTATION-TEMPLATE"))) 
     256         (:p "$Header: /usr/local/cvsrep/documentation-template/output.lisp,v 1.16 2008/06/01 21:26:20 edi Exp $") 
     257         (:p (:a :href "http://weitz.de/index.html" "BACK TO MY HOMEPAGE")))))) 
    329258  (values)) 
  • trunk/thirdparty/documentation-template/specials.lisp

    r3242 r3244  
    11;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: DOCUMENTATION-TEMPLATE; Base: 10 -*- 
    2 ;;; $Header: /usr/local/cvsrep/documentation-template/specials.lisp,v 1.7 2008/05/29 08:23:37 edi Exp $ 
     2;;; $Header: /usr/local/cvsrep/documentation-template/specials.lisp,v 1.9 2008/06/01 21:26:20 edi Exp $ 
    33 
    44;;; Copyright (c) 2006-2008, Dr. Edmund Weitz.  All rights reserved. 
     
    3131 
    3232(defvar *target* nil 
    33   "Where to output the HTML page.  If this value is not NIL, it will 
    34 be the default target for CREATE-TEMPLATE.  CREATE-TEMPLATE will also 
    35 set this value.") 
     33  "Where to output the XML page.  If this value is not NIL, it will be 
     34the default target for CREATE-TEMPLATE.  CREATE-TEMPLATE will also set 
     35this value.") 
    3636 
    3737(defvar *maybe-skip-methods-p* nil 
     
    4040used internally.") 
    4141 
    42 (defvar *symbols* nil 
    43   "The list of symbols for which we will create an index with links.") 
     42(defvar *doc-output* nil 
     43  "A special variable to hold the stream CL-WHO will be using for 
     44output.") 
     45 
     46(defvar +clix-prologue+ 
     47  "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> 
     48<?xml-stylesheet type=\"text/xsl\" href=\"clixdoc.xsl\" ?>" 
     49  "The prologue for the generated XML.") 
    4450 
    4551;; stuff for Nikodemus Siivola's HYPERDOC