|
Practical Common LispNot only do you never have to generate an s-expression representing the whole page, also much of the work that emit-html does at runtime to interpret the s-expression will be done once, when the macro is expanded, rather than every time the code is run. You can control where the output generated by both html and emit-html is sent with the macro with-html-output, which is part of the FOO library. Thus, you can use the with-html-output and html macros from FOO to rewrite random-number like this: (defun random-number (request entity) (with-http-response (request entity :content-type "text/html") (with-http-body (request entity) (with-html-output ((request-reply-stream request)) (html (:html (:head (:title "Random")) (:body (:p "Random number: " (:print (random 1000)))))))))) 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 ...» |
Код для вставки книги в блог HTML
phpBB
текст
|
|