Commits

Phil Hargett  committed d492beb

Added basic unit testing (many more tests needed), and fixed interesting bug where the 'context' for loading templates wasn't set up--if we're going to load a template, gotta have meaningful values for variables like *tag-library-provider-registry* and *template-provider-registry* or the load could fail

  • Participants
  • Parent commits aab55d4

Comments (0)

Files changed (8)

File taglibraries/html.lisp

-;; Copyright (c) 2010 Phil Hargett
+;; Copyright (c) 2010 Haphazard House LLC
 
 ;; Permission is hereby granted, free of charge, to any person obtaining a copy
 ;; of this software and associated documentation files (the "Software"), to deal

File taglibraries/script.lisp

-;; Copyright (c) 2010 Phil Hargett
+;; Copyright (c) 2010 Haphazard House LLC
 
 ;; Permission is hereby granted, free of charge, to any person obtaining a copy
 ;; of this software and associated documentation files (the "Software"), to deal

File taglibraries/wt-tags-tests1.lisp

+;; Copyright (c) 2010 Haphazard House LLC
+
+;; Permission is hereby granted, free of charge, to any person obtaining a copy
+;; of this software and associated documentation files (the "Software"), to deal
+;; in the Software without restriction, including without limitation the rights
+;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+;; copies of the Software, and to permit persons to whom the Software is
+;; furnished to do so, subject to the following conditions:
+
+;; The above copyright notice and this permission notice shall be included in
+;; all copies or substantial portions of the Software.
+
+;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+;; THE SOFTWARE.
+
+(in-tag-library :wt-tags-tests)
+
+(+tag-library :html)
+(+tag-library :script)

File templates.lisp

 				      :args template-args 
 				      :kwargs template-keyword-args
 				      )) 
-	   (*package (template-package *template*))
+	   (*package* (template-package *template*))
 	   (definition (eval `(lambda (,@template-args ,@(if template-keyword-args `(&key ,@template-keyword-args)) )
 				,@(or (load-template-definition *template* template-path)
 				      `( (error 'template-not-found-error :path ,template-path) ))))) )
     (when (probe-file full-path)
       (setf (template-provider *template*) provider)
       (setf (modified-time-of *template*) 
-	    (template-file-modified-time template-path provider)
-	    )
+	    (template-file-modified-time template-path provider))
       (read-template-definition (open full-path :direction :input) (template-package *template*)
 				(template-args *template*)
 				(template-keyword-args *template*)
 
      ;; pre-load -- note that this will likely create definitions in error, because a template cannot be found
      ;; doing this so that a "reload" later can find all the templates to reload
-     (load-template ,path (quote ,template-args) (quote ,template-keyword-args) ) 
+     (handler-case 
+	 (load-template ,path (quote ,template-args) (quote ,template-keyword-args))
+       ;; we want to catch this error and continue, in case the template will be
+       ;; available later
+       (template-not-found-error (c) (format *standard-output* "Delaying load of ~s: ~s~%" ',name c))) 
 
      ;; create a macro to invoke the template
      (defmacro ,name (,@template-args ,@(if template-keyword-args `(&key ,@template-keyword-args)) )
 	     (template-args (quote ,template-args) )
 	     (template-arg-values (list ,@template-args) )
 	     (template-keyword-args (quote ,template-keyword-args)))
-	 `(let ((tmpl (or (find-cached-template ,path) 
+	 `(let* ((*tag-library-provider-registry* (or *tag-library-provider-registry* ,(local-template-provider-registry-symbol)))
+		 (*template-provider-registry* (or *template-provider-registry* ,(local-template-provider-registry-symbol)))
+		 (tmpl (or (find-cached-template ,path) 
 			  (load-template ,path (quote ,template-args) (quote ,template-keyword-args)))))
 	    (when tmpl
 	      (let ((*template* tmpl)

File templates/wt_empty_page.lisp

+;; Copyright (c) 2010 Haphazard House LLC
+
+;; Permission is hereby granted, free of charge, to any person obtaining a copy
+;; of this software and associated documentation files (the "Software"), to deal
+;; in the Software without restriction, including without limitation the rights
+;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+;; copies of the Software, and to permit persons to whom the Software is
+;; furnished to do so, subject to the following conditions:
+
+;; The above copyright notice and this permission notice shall be included in
+;; all copies or substantial portions of the Software.
+
+;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+;; THE SOFTWARE.
+
+(+tag-library :html)
+(+tag-library :script)

File templates/wt_tags_tests1.lisp

+;; Copyright (c) 2010 Haphazard House LLC
+
+;; Permission is hereby granted, free of charge, to any person obtaining a copy
+;; of this software and associated documentation files (the "Software"), to deal
+;; in the Software without restriction, including without limitation the rights
+;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+;; copies of the Software, and to permit persons to whom the Software is
+;; furnished to do so, subject to the following conditions:
+
+;; The above copyright notice and this permission notice shall be included in
+;; all copies or substantial portions of the Software.
+
+;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+;; THE SOFTWARE.
+
+(+tag-library :html)
+(+tag-library :script)
+
+(page "hello")

File templates/wt_tags_tests2.lisp

+;; Copyright (c) 2010 Haphazard House LLC
+
+;; Permission is hereby granted, free of charge, to any person obtaining a copy
+;; of this software and associated documentation files (the "Software"), to deal
+;; in the Software without restriction, including without limitation the rights
+;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+;; copies of the Software, and to permit persons to whom the Software is
+;; furnished to do so, subject to the following conditions:
+
+;; The above copyright notice and this permission notice shall be included in
+;; all copies or substantial portions of the Software.
+
+;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+;; THE SOFTWARE.
+
+(+tag-library :html)
+(+tag-library :script)
+
+(html  (p "hello"))
+;; Copyright (c) 2010 Haphazard House LLC
+
+;; Permission is hereby granted, free of charge, to any person obtaining a copy
+;; of this software and associated documentation files (the "Software"), to deal
+;; in the Software without restriction, including without limitation the rights
+;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+;; copies of the Software, and to permit persons to whom the Software is
+;; furnished to do so, subject to the following conditions:
+
+;; The above copyright notice and this permission notice shall be included in
+;; all copies or substantial portions of the Software.
+
+;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+;; THE SOFTWARE.
+
+
+(defpackage :hh-web-tags-tests
+  (:use :cl :asdf :lisp-unit :hh-web-tags))
+
+(in-package :hh-web-tags-tests)
+
+;; start fresh--remove any tests that no longer exist
+(remove-all-tests)
+
+;;----------------------------------------
+;; Templates
+
+;; Note that we're using really ugly template file names because
+;; we don't ever want them to be used in a real application--they
+;; are just for test
+
+(deftemplates :tag-library-packages ( "hh-web-tags" )
+  :template-packages ( "hh-web-tags")
+  :templates (
+	      (test-page "wt_tags_tests1.lisp")
+	      (test-html "wt_tags_tests2.lisp")
+	      ))
+
+;;----------------------------------------
+;; Tests
+
+(define-test template-tests
+  (assert-true (string= (test-page) "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\">
+<html xmlns=\"http://www.w3.org/1999/xhtml\">
+<head>
+</head>
+<body>
+hello
+</body>
+</html>
+")))
+
+(define-test html-tests
+  (assert-true (string= (test-html) "<p>
+hello</p>
+")))
+
+;;----------------------------------------
+;; Run
+(run-tests)