Author: hhubner Date: Thu Jan 31 07:32:06 2008 New Revision: 2432
Modified: branches/trunk-reorg/xhtmlgen/package.lisp branches/trunk-reorg/xhtmlgen/xhtmlgen.lisp Log: Fix xhtmlgen so that it properly flushes the output ystream when it is done.
Modified: branches/trunk-reorg/xhtmlgen/package.lisp ============================================================================== --- branches/trunk-reorg/xhtmlgen/package.lisp (original) +++ branches/trunk-reorg/xhtmlgen/package.lisp Thu Jan 31 07:32:06 2008 @@ -1,7 +1,7 @@ (in-package :cl-user)
(defpackage :xhtml-generator - (:use :common-lisp) + (:use :common-lisp :alexandria) (:export #:html #:html-stream #:*html-sink*
Modified: branches/trunk-reorg/xhtmlgen/xhtmlgen.lisp ============================================================================== --- branches/trunk-reorg/xhtmlgen/xhtmlgen.lisp (original) +++ branches/trunk-reorg/xhtmlgen/xhtmlgen.lisp Thu Jan 31 07:32:06 2008 @@ -24,7 +24,6 @@
(in-package :xhtml-generator)
-;; fixme (defvar *html-sink*)
;; html generation @@ -45,48 +44,21 @@ (make-hash-table :test #'equal) ; #'eq is accurate but want to avoid rehashes )
-;; support for strings encoded in latin-1 or utf-8 on non-unicode lisps - -#-rune-is-character -(defun make-sink-for-utf8-strings (stream) - (cxml:make-recoder (cxml:make-character-stream-sink/utf8 stream :canonical nil :indentation 3) - #'cxml::utf8-string-to-rod)) - -#-rune-is-character -(defun make-sink-for-latin1-strings (stream) - (cxml:make-recoder (cxml:make-character-stream-sink/utf8 stream :canonical nil :indentation 3) - #'cxml::string-rod)) - -#-rune-is-character -(defvar *make-sink-for-internal-strings-fn* #'make-sink-for-utf8-strings) - -#-rune-is-character -(defun make-sink-for-internal-strings (stream) - (funcall *make-sink-for-internal-strings-fn* stream)) - -#-rune-is-character -(defun set-string-encoding (encoding) - (ecase encoding - (:latin-1 (setf *make-sink-for-internal-strings-fn* #'make-sink-for-latin1-strings)) - (:utf-8 (setf *make-sink-for-internal-strings-fn* #'make-sink-for-utf8-strings)))) - (defmacro html (&rest forms &environment env) ;; just emit html to the current stream - `(let ((*html-sink* (if (boundp '*html-sink*) - *html-sink* - #+rune-is-character - (cxml:make-character-stream-sink *standard-output* :canonical nil :indentation 3) - #-rune-is-character - (make-sink-for-internal-strings *standard-output*)))) - ,(process-html-forms forms env))) + (with-gensyms (body) + `(labels ((,body () + ,(process-html-forms forms env))) + (if (boundp '*html-sink*) + (,body) + (let ((*html-sink* (cxml:make-character-stream-sink *standard-output* :canonical nil :indentation 3))) + (,body) + (sax:end-document *html-sink*))))))
(defmacro html-stream (stream &rest forms &environment env) - `(let ((*html-sink* - #+rune-is-character - (cxml:make-character-stream-sink ,stream :canonical nil :indentation 3) - #-rune-is-character - (make-sink-for-internal-strings ,stream))) - ,(process-html-forms forms env))) + `(let ((*html-sink* (cxml:make-character-stream-sink ,stream :canonical nil :indentation 3))) + ,(process-html-forms forms env) + (sax:end-document *html-sink*)))
(defun get-process (form) (let ((ent (gethash form *html-process-table*)))