templates.scm 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. (define-module (templates)
  2. #:export (templatize
  3. debug-table-template))
  4. (use-modules (web request)
  5. (web response)
  6. (web uri))
  7. (define templatize
  8. (lambda (title body)
  9. "Wrap the usual stuff around the SXML of the body."
  10. `(html (head (title ,title)
  11. (link (@ (rel "stylesheet")
  12. (type "text/css")
  13. (href "/static/css/style.css"))))
  14. ;; Splice in the body. It could be multiple top
  15. ;; level expressions inside the body.
  16. (body ,@body))))
  17. (define debug-table-template
  18. (λ (request body)
  19. `((h1 "hello world!")
  20. (table
  21. (tr (th "header") (th "value"))
  22. ;; splice in all request headers
  23. ,@(map (lambda (pair)
  24. `(tr (td (tt ,(with-output-to-string
  25. (lambda () (display (car pair))))))
  26. (td (tt ,(with-output-to-string
  27. (lambda ()
  28. (write (cdr pair))))))))
  29. (request-headers request))))))