Templates

This commit is contained in:
Tony Garnock-Jones 2016-11-21 09:09:05 +13:00
parent 1f70e0e49f
commit ae8209410d
2 changed files with 32 additions and 0 deletions

22
racketmq/template.rkt Normal file
View File

@ -0,0 +1,22 @@
#lang racket/base
;; Templated response generation
(provide web-respond/page!
include-template
include-fragment)
(require web-server/templates)
(require syndicate/drivers/web)
(require (for-syntax racket/base))
(define-syntax (include-fragment stx)
(syntax-case stx ()
[(_ fragment-str)
;; It's important to preserve the lexical context of the *path*
;; because this is what's used to resolve any mentioned
;; identifiers in the template file!
(quasisyntax/loc stx
(include-template #,(datum->syntax stx (format "templates/~a" (syntax-e #'fragment-str)))))]))
(define (web-respond/page! id page-title page-body)
(web-respond/string! id (include-template "templates/_page.html")))

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>@|page-title|</title>
</head>
<body>
@|page-body|
</body>
</html>