#lang scheme/base
(require (planet "dispatch.ss" ("untyped" "dispatch.plt" 1 5))
(planet "web.scm" ("soegaard" "web.plt" 2 1))
"util.scm"
"web-support.scm"
"session.scm"
"settings.scm")
(provide define-page
define-session-page
page
design
**
page-url
redirect-to-page
atom-wrapper
js-inc
css-inc
versioned-file-reference)
(define-syntax define-page
(syntax-rules ()
((_ (page-name args ...)
keywords-and-body ...)
(define-controller (page-name args ...)
(page keywords-and-body ...)))))
(define-syntax define-session-page
(syntax-rules ()
((_ (page-name req-iden sesh-iden args ...)
keywords-and-body ...)
(define-controller (page-name req-iden args ...)
(sessioned-response req-iden (sesh-iden)
(page keywords-and-body ...))))))
(define (page #:doc-type (doc-type #f)
#:raw-header (raw-header '())
#:css (css '())
#:js (js '())
#:title (title "a LeftParen web app")
#:body-attrs (body-attrs '())
#:body-wrap (body-wrap (lambda (body) body))
#:blank (blank #f)
#:plain-text (plain-text #f)
#:design (a-design #f)
. body)
(let ((returned-body (last body)))
(cond ((response/full? returned-body) returned-body)
(plain-text (basic-response (list returned-body)
#:type #"text/plain; charset=us-ascii"))
(blank returned-body) (a-design (a-design returned-body))
(else (let ((main `(html (head ,@(map css-inc css)
,@(map js-inc js)
,@(map raw-str raw-header)
(title ,title))
(body ,body-attrs ,(body-wrap returned-body)))))
(if doc-type
`(group ,(raw-str doc-type) ,main)
main))))))
(define (design #:raw-header (raw-header '())
#:css (css '())
#:js (js '())
#:title (title "a LeftParen web app")
#:doc-type (doc-type #f) #:body-attrs (body-attrs '())
#:body-wrap (body-wrap (lambda (body) body)))
(lambda (body) (page #:doc-type doc-type
#:raw-header raw-header
#:css css
#:js js
#:title title
#:body-attrs body-attrs
#:body-wrap body-wrap
body)))
(define (** . bodies)
`(group ,@bodies))
(define (js-inc script-filename)
`(script ((src ,script-filename) (type "text/javascript")) ""))
(define (css-inc css-filename)
`(link ((rel "stylesheet") (type "text/css") (href ,css-filename))))
(define (atom-wrapper body)
(list-response #:type #"text/xml"
(list (raw-str "<?xml version=\"1.0\" encoding=\"utf-8\"?>")
`(feed ((xmlns "http://www.w3.org/2005/Atom"))
,body))))
(define (versioned-file-reference filename)
(string-append filename "#" (number->string (setting *APP_VERSION*))))
(define (redirect-to-page page-name . args)
(redirect-to (apply controller-url page-name args)))
(define page-url controller-url)