[plt-scheme] Embedding scheme in web pages
Noel Welsh wrote:
> 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
Why not? Generating html from x-expressions feels design-wise sub-optimal.
> in HTML you can use the preprocessor library. Delimit your
> Scheme with << >> and use the command line mzpp or
> apply-template given below.
Thanks.
> Let me know if you have any quesitons on the code.
I am pretty new to serious usage of Scheme, but I used REBOL a lot which
is somewhat similar (I wrote the RSP code and a full-blown rpc broker,
Rugby). But for the time being I'll have to read this code carefully,
line by line.
What I'd really like is something like LAMP, with the P(HP) part
replaced by Scheme. Perhaps I'll try something myself; nothing like
writing some infrastructural code to get "into" a language.
Thanks!
--Maarten
> 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)))
>
> )
>