23 lines
737 B
Racket
23 lines
737 B
Racket
|
#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")))
|