[plt-scheme] Parameters and servlets
On 2/16/06, Jens Axel Søgaard <jensaxel at soegaard.net> wrote:
>
> Thanks for the explanation. Your web-cells might do the trick.
>
> I am trying to make a small library that uses site-wide defaults.
> E.g in "view.scm" I'd like to write
>
> (require "html.scm")
>
> ;;;
> ;;; SITE WIDE DEFAULTS
> ;;;
>
> (current-page-title "Foo 2.0")
> (current-page-header '(h1 ((class "page_header")) "Foo 2.0!"))
> (current-page-style-sheet "http://localhost/stylesheet.css")
>
> (define (html-a-page)
> (html-page #:body "Foo bar baz"))
>
> where html-page is defined "html.scm".
For a given site, I typically wrap the 'start' procedure in the site-wide
defaults:
(define (start ir)
(parameterize ([current-page-title "Foo 2.0"])
(html-a-page)))
Parameters will work in the web-server provided you are only using
'parameterize', but not if you are using the parameter-procedure set method.
I think this approach is most what you want, as cells do something
different, and your `persistent parameters' seem very kludgy
Jay
At the same time, I want the ability to override the defaults
> for a single request in "control.scm" with, say,
>
> (parameterize ([current-page-title "Foo 3.0"])
> (html-a-page))
>
> Apart from the losing the settings when a new thread is started,
> it works nicely.
>
>
> Here is html.scm:
>
> (module html mzscheme
> (provide (all-defined))
>
> (require (lib "kw.ss"))
>
> (define current-page-title (make-parameter "A title"))
> (define current-page-header (make-parameter '(h1 "A Header")))
> (define current-page-body (make-parameter "A body"))
> (define current-page-content-type
> (make-parameter "text/html;charset=UTF-8"))
> (define current-page-style-sheet (make-parameter ""))
>
> ; html-page
> ; Puts all the pieces together to make a complete html page.
> ; Defaults are taken from site-wide parameters
> (define/kw
> (html-page #:key
> (title (current-page-title))
> (title-atts #f)
> (header (current-page-header))
> (head-atts #f)
> (body (current-page-body))
> (body-atts #f)
> (style-sheet (current-page-style-sheet))
> (content-type (current-page-content-type)))
> (let ([title-atts (if title-atts (list title-atts) '())]
> [head-atts (if head-atts (list head-atts) '())]
> [body-atts (if body-atts (list body-atts) '())])
> `(html (head (title , at title-atts ,title)
> ; external stylesheet
> (link ((rel "stylesheet")
> (type "text/css")
> (href ,style-sheet)))
> (meta ((http-equiv "Content-Type")
> (content ,content-type)))
> , at head-atts)
> (body , at body-atts
> ,header
> ,body))))
>
--
Jay McCarthy <jay at cs.brown.edu>
http://jay.makeoutcity.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20060217/773bb65a/attachment.html>