forked from gigamonkey/monkeylib-foo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml-macros.lisp
63 lines (48 loc) · 1.76 KB
/
html-macros.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
;;
;; Copyright (c) 2005, Gigamonkeys Consulting All rights reserved.
;;
(in-package :foo.xml)
(defvar *css* (make-instance 'foo.css::css))
(define-html-macro :comment (&body body)
`(:progn
(:noescape "<!-- ")
(:newline)
,@body
(:newline)
(:noescape " -->")))
(define-html-macro :character (name)
`(:noescape (:format ,(if (numberp name) "&#~d;" "&~(~a~);") ,name)))
(define-html-macro :pi (name &rest attrs)
`(:progn
(:noescape (:format "<?~a ~@{~(~a~)=\"~a\"~^ ~}?>" ,name ,@attrs))
(:newline)))
(define-html-macro :doctype (name type id url)
`(:progn
(:noescape (:format "<!DOCTYPE ~a ~a \"~a\" \"~a\">" ,name ,type ,id ,url))
(:newline)))
(define-html-macro :xhtml (&body body)
`(:progn
(:pi "xml" :version 1.0 :encoding "UTF-8")
(:doctype "html" "PUBLIC" "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd")
((:html :xmlns "http://www.w3.org/1999/xhtml" :xml\:lang "en" :lang "en")
,@body)))
(define-html-macro :css-stylesheet (href)
`(:link :rel "stylesheet" :type "text/css" :href ,href))
;(define-html-macro :css (&rest values)
; `(:attribute (:format "~@{~(~a~): ~a;~^ ~}" ,@values)))
(define-html-macro :css (&body body)
`((:style :type "text/css")
(:comment
(:with-language (*css*)
,@body))))
;; This macro doesn't really work so well since Lispscript is
;; case-sensitive and, at the moment, FOO/HTML is not. Not to mention
;; packaging issues. Bah.
(define-html-macro :lispscript (&body body)
`((:script :type "text/javascript")
(:comment
(:with-language (foo.lispscript::*lispscript*)
,@body))))
(defparameter *interpolated-foo* '((:title . "My TITLE")))
(define-html-macro :interpolate (name)
(cdr (assoc name *interpolated-foo*)))