[plt-scheme] Embedding scheme in web pages

From: Noel Welsh (noelwelsh at yahoo.com)
Date: Fri Jan 19 11:15:51 EST 2007

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


Posted on the users mailing list.