diff options
author | Hans Hübner <hans.huebner@gmail.com> | 2012-04-10 02:02:39 -0700 |
---|---|---|
committer | Hans Hübner <hans.huebner@gmail.com> | 2012-04-10 02:02:39 -0700 |
commit | 30806f2df2f834542a1abd32babc47152da2bcd7 (patch) | |
tree | 6ec145ce1640648212c5ea2ece4874f7738f49bc | |
parent | da66bc56812dd3faf62672939ed0c54adacb9a2a (diff) | |
parent | 4618609f71498a6909b39d2c87ea5d26ea68cfb0 (diff) | |
download | tl-who-30806f2df2f834542a1abd32babc47152da2bcd7.tar.gz tl-who-30806f2df2f834542a1abd32babc47152da2bcd7.tar.bz2 tl-who-30806f2df2f834542a1abd32babc47152da2bcd7.zip |
Merge pull request #4 from nikodemus/master
Test portability fixes / indentation suppression from Nikodemus
-rw-r--r-- | packages.lisp | 2 | ||||
-rwxr-xr-x | specials.lisp | 4 | ||||
-rw-r--r-- | test/simple | 51 | ||||
-rw-r--r-- | who.lisp | 15 |
4 files changed, 55 insertions, 17 deletions
diff --git a/packages.lisp b/packages.lisp index 89d56de..5ea0159 100644 --- a/packages.lisp +++ b/packages.lisp @@ -33,10 +33,12 @@ (:use :cl) (:nicknames :who) #+:sbcl (:shadow :defconstant) + #+:sb-package-locks (:lock t) (:export :*attribute-quote-char* :*escape-char-p* :*prologue* :*downcase-tokens-p* + :*html-no-indent-tags* :*html-empty-tags* :*html-empty-tag-aware-p* :conc diff --git a/specials.lisp b/specials.lisp index 349c7fc..c731a78 100755 --- a/specials.lisp +++ b/specials.lisp @@ -64,6 +64,10 @@ needs to output case sensitive XML.") (defvar *empty-tag-end* " />" "End of an empty tag. Default is XML style.") +(defvar *html-no-indent-tags* + '(:pre) + "List of HTML tags that disable indentation inside them. Default list containts only :PRE.") + (defvar *html-empty-tags* '(:area :atop diff --git a/test/simple b/test/simple index 6fa48e5..c952fa0 100644 --- a/test/simple +++ b/test/simple @@ -105,8 +105,8 @@ ;;; 11 (string= (let ((*prologue* "<!DOCTYPE math SYSTEM \"http://www.w3.org/Math/DTD/mathml1/mathml.dtd\">")) - (with-html-output-to-string (out nil :prologue t) - (:apply (:factorial) (:cn "3")))) + (eval `(with-html-output-to-string (out nil :prologue t) + (:apply (:factorial) (:cn "3"))))) "<!DOCTYPE math SYSTEM \"http://www.w3.org/Math/DTD/mathml1/mathml.dtd\"> <apply><factorial></factorial><cn>3</cn></apply>") @@ -231,16 +231,16 @@ "<p></p>") ;;; 19 -(string= (let ((*html-empty-tag-aware-p* nil)) - (with-html-output-to-string (out) - (:p))) +(string= (let ((cl-who:*html-empty-tag-aware-p* nil)) + (eval `(with-html-output-to-string (out) + (:p)))) "<p />") ;;; 20 (string= (let ((*html-empty-tag-aware-p* t) (*html-empty-tags* '(:p))) - (with-html-output-to-string (out) - (:p))) + (eval `(with-html-output-to-string (out) + (:p)))) "<p />") ;;; 21 @@ -250,8 +250,8 @@ ;;; 22 (string= (let ((*downcase-tokens-p* nil)) - (with-html-output-to-string (out) - (:|Foo| :bar 42))) + (eval `(with-html-output-to-string (out) + (:|Foo| :bar 42)))) "<Foo BAR='42'></Foo>") ;;; 23 @@ -260,4 +260,35 @@ (with-html-output (var (pop list)) (progn (htm (:br)))) (get-output-stream-string stream)) - "<br />")
\ No newline at end of file + "<br />") + +;;; 24 +(string= (with-html-output-to-string (out) + (:div (:pre "Foo"))) + "<div><pre>Foo</pre></div>") + +;;; 25 +(string= (with-html-output-to-string (out nil :indent t) + (:div (:pre "Foo"))) + " +<div> + <pre>Foo</pre> +</div>") + +;;; 26 +(string= (with-html-output-to-string (out nil :indent t) + (:div (:p "Bar"))) + " +<div> + <p>Bar + </p> +</div>") + +;;; 27 +(string= (let ((*html-no-indent-tags* (cons :p *html-no-indent-tags*))) + (eval `(with-html-output-to-string (out nil :indent t) + (:div (:p "Bar"))))) + " +<div> + <p>Bar</p> +</div>") @@ -144,7 +144,11 @@ a list of strings or Lisp forms.")) "The standard method which is not specialized. The idea is that you can use EQL specializers on the first argument." (declare (optimize speed space)) - (let ((tag (if *downcase-tokens-p* (string-downcase tag) (string tag)))) + (let ((tag (if *downcase-tokens-p* (string-downcase tag) (string tag))) + (body-indent + ;; increase *INDENT* by 2 for body -- or disable it + (when (and *indent* (not (member tag *html-no-indent-tags* :test #'string-equal))) + (+ 2 *indent*)))) (nconc (if *indent* ;; indent by *INDENT* spaces @@ -157,13 +161,10 @@ can use EQL specializers on the first argument." (if body (append (list ">") - ;; now hand over the tag's body to TREE-TO-TEMPLATE, increase - ;; *INDENT* by 2 if necessary - (if *indent* - (let ((*indent* (+ 2 *indent*))) - (funcall body-fn body)) + ;; now hand over the tag's body to TREE-TO-TEMPLATE + (let ((*indent* body-indent)) (funcall body-fn body)) - (if *indent* + (when body-indent ;; indentation (list +newline+ (n-spaces *indent*))) ;; closing tag |