Книга: Practical Common Lisp
HTML Macros
HTML Macros
Another feature of FOO is that it allows you to define HTML "macros" that can translate arbitrary forms into HTML s-expressions that the html
macro understands. For instance, suppose you frequently find yourself writing pages of this form:
(:html
(:head (:title "Some title"))
(:body
(:h1 "Some title")
... stuff ...))
You could define an HTML macro to capture that pattern like this:
(define-html-macro :standard-page ((&key title) &body body)
`(:html
(:head (:title ,title))
(:body
(:h1 ,title)
,@body)))
Now you can use the "tag" :standard-page
in your s-expression HTML, and it'll be expanded before being interpreted or compiled. For instance, the following:
(html (:standard-page (:title "Hello") (:p "Hello, world.")))
generates the following HTML:
<html>
<head>
<title>Hello</title>
</head>
<body>
<h1>Hello</h1>
<p>Hello, world.</p>
</body>
</html>
- Handling HTML Forms
- 31. Practical: An HTML Generation Library, the Compiler
- Generating HTML
- Boilerplate HTML
- FOO Macros
- 6.8 Building More Complicated Macros
- Применение PHP-технологий в программе HtmlPad
- Модульный HTML
- 2.1. Информация о версии HTML
- 19.2.4. Чтение и запись значений элементов HTML-форм
- HTML5 для веб-дизайнеров
- 19.2.1. Чтение и запись значений HTML-атрибутов