r5306: add new attribute commands
authorKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 15 Jul 2003 04:28:56 +0000 (04:28 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 15 Jul 2003 04:28:56 +0000 (04:28 +0000)
2/htmlgen.lisp
2/utils.lisp

index dab8c16d975852736ab82c0100a0114dbbd1bd20..711fcc64597ca2ad9f8dfb4b29e7325bd240bba1 100644 (file)
@@ -1,6 +1,6 @@
 ;; -*- mode: common-lisp; package: lml2 -*-
 ;;
-;; $Id: htmlgen.lisp,v 1.12 2003/07/13 04:56:12 kevin Exp $
+;; $Id: htmlgen.lisp,v 1.13 2003/07/15 04:28:56 kevin Exp $
 ;;
 ;; copyright (c) 1986-2000 Franz Inc, Berkeley, CA 
 ;; copyright (c) 2003 Kevin Rosenberg
@@ -68,7 +68,7 @@
             ;; argsp is true if this isn't a singleton tag  (i.e. it has
             ;;     a body) .. (:tag ...) or ((:tag ...) ...)
             ;; body is the body if any of the form
-            ;; 
+            ;;
             (let (spec)
               (if* (setq spec (html-process-special ent))
                  then ; do something different
@@ -84,8 +84,9 @@
                               (push `(,(html-process-macro ent) :unset) res)
                               nil
                          else ; some args
-                              (push `(,(html-process-macro ent) ,args
-                                                                ,(process-html-forms body env))
+                              (push `(,(html-process-macro ent)
+                                      ,args
+                                      ,(process-html-forms body env))
                                     res)
                               nil)))))
                                 
                               (prin1-safe-http-string ,(cadddr xx)))
                             res)
                       (pop xx) (pop xx)
+                      elseif (eq :fformat (car xx))
+                      then
+                      ;; process :fformat
+                      (unless (and (listp (cadr xx))
+                                   (>= (length (cadr xx)) 2))
+                        (error ":fformat must be given a list"))
+                      (push
+                       `(write-string 
+                         ,(format nil " ~(~a~)=\"" (car (cadr xx)))
+                         *html-stream*)
+                       res)
+                      (push
+                       `(fformat *html-stream* ,(cadr (cadr xx))
+                         ,@(cddr (cadr xx)))
+                       res)
+                      (push '(write-char #\" *html-stream*) res)
+                      elseif (eq :optional (car xx))
+                      then 
+                      (push
+                       `(when ,(cadr (cadr xx))
+                         (write-string
+                          ,(format nil " ~(~a~)=\"" (car (cadr xx)))
+                          *html-stream*)
+                         (fformat *html-stream* "~A\""
+                          ,(cadr (cadr xx))))
+                       res)
                       else 
                       
                       (push `(write-string 
       (if (eq cmd :full)
          (write-char (cadr form) stream)
          (error ":write-char must be given an argument")))))
+
+;; fast formatter
+(def-special-html :fformat
+    (named-function html-write-char-function
+      (lambda (ent args argsp body)
+       (declare (ignore ent args argsp))
+       `(progn ,@(mapcar #'(lambda (bod)
+                             `(progn
+                               (format *html-stream* " ~(~A~)=\"" (car ,bod))
+                               (apply #'format *html-stream* (cdr ,bod))
+                               (write-char #\" *html-stream*)))
+                         body))))
+  
+  (named-function html-write-char-print-function
+    (lambda (ent cmd args form subst unknown stream)
+      (declare (ignore args ent unknown subst))
+      (assert (eql 2 (length form)))
+      (if (eq cmd :full)
+         (progn
+           (format stream " ~(~A~)=\"" (car form))
+           (apply #'format stream (cdr form))
+           (write-char #\" stream))
+         (error ":fformat must be given an argument")))))
+
index a90b32585b765c4a48c16d169fe141bdb55d0c86..2a6877fefa71ffec67082d44a23742f0911b21f3 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Author:        Kevin M. Rosenberg\r
 ;;;; Date Started:  June 2002\r
 ;;;;\r
-;;;; $Id: utils.lisp,v 1.3 2003/07/12 17:54:05 kevin Exp $\r
+;;;; $Id: utils.lisp,v 1.4 2003/07/15 04:28:56 kevin Exp $\r
 ;;;;\r
 ;;;; This file, part of LML2, is copyrighted and open-source software.\r
 ;;;; Rights of modification and redistribution are in the LICENSE file.\r
@@ -73,3 +73,7 @@
   #-(or allegro clisp cmu scl sbcl cormanlisp lispworks lucid mcl) (truename "."))\r
 \r
 \r
+\r
+(defun fformat (&rest args)\r
+  (declare (dynamic-extent args))\r
+  (apply #'format args))\r