[plt-scheme] Embedding scheme in web pages

From: Brent Fulgham (bfulg at pacbell.net)
Date: Fri Jan 19 16:15:38 EST 2007


What do you view as being the 'right' way to build such web sites?  Do you mean building programs that generate the appropriate HTML/Javascript on-the-fly, or some other templating system?

I'm quite interested in hearing your experiences.



----- Original Message ----
From: Noel Welsh <noelwelsh at yahoo.com>
To: Maarten Koopmans <maarten at vrijheid.net>; plt-scheme at list.cs.brown.edu
Sent: Friday, January 19, 2007 8:15:51 AM
Subject: Re: [plt-scheme] Embedding scheme in web pages

I don't advocate it as a good way to build web sites (I
fact, I think the opposite) but if you want to embed Scheme
in HTML you can use the preprocessor library.  Delimit your
Scheme with << >> and use the command line mzpp or
apply-template given below.

Let me know if you have any quesitons on the code.


(module preprocess mzscheme

  (require (lib "mzpp.ss" "preprocessor")
           (planet "namespace.ss" ("schematics"

  (provide apply-template)
  ;; apply-template : (U string port) (alist-of symbol any)
-> string
  (define (apply-template template bindings)
    (let ((op (open-output-string)))
        ((current-output-port op))
        (let ((ns (make-namespace 'initial)))
           '(lib "mzpp.ss" "preprocessor"))
            (lambda (cell)
              (let ((key (car cell))
                    (val (cdr cell)))
                (eval `(define ,key ,val))))
           (eval `(preprocess ,template)))))
      (get-output-string op)))

--- Maarten Koopmans <maarten at vrijheid.net> wrote:

> Hi,
> > Search for "xexpr" in the HelpDesk.
> Thanks.
> > Returning
> > 
> >   `(html (head (title "A title"))
> >          (body ,(+ 1 2)))
> > 
> > as the result of a servlet will generate the
> > wanted output.
> Yes, but say I build a website with a lot of
> Javascript/CSS and a 
> separate web designer, this is'nt what you want. Is there
> a wy to add an 
> input/output filter to the PLT webserver for some file
> extensions/mime 
> types?
> --Maarten
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Email: noelwelsh <at> yahoo <dot> com   noel <at> untyped <dot> com
AIM: noelhwelsh
Blogs: http://monospaced.blogspot.com/  http://www.untyped.com/untyping/

Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.
  For list-related administrative tasks:

Posted on the users mailing list.