[plt-scheme] Embedding scheme in web pages

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

Noel,

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.

Thanks,

-Brent


----- 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.

Cheers,
Noel


(module preprocess mzscheme

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

  (provide apply-template)
  
  ;; apply-template : (U string port) (alist-of symbol any)
-> string
  (define (apply-template template bindings)
    (let ((op (open-output-string)))
      (parameterize
        ((current-output-port op))
        (let ((ns (make-namespace 'initial)))
          (namespace-attach/require
           ns
           '(lib "mzpp.ss" "preprocessor"))
          (with-namespace
           ns
           (for-each
            (lambda (cell)
              (let ((key (car cell))
                    (val (cdr cell)))
                (eval `(define ,key ,val))))
            bindings)
           (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.
http://videogames.yahoo.com/platform?platform=120121
_________________________________________________
  For list-related administrative tasks:
  http://list.cs.brown.edu/mailman/listinfo/plt-scheme





Posted on the users mailing list.