Templates
This commit is contained in:
parent
1f70e0e49f
commit
ae8209410d
|
@ -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")))
|
|
@ -0,0 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>@|page-title|</title>
|
||||
</head>
|
||||
<body>
|
||||
@|page-body|
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue