Friday, December 25, 2009

Eli on My Scribble-For-HTML Solution

Eli was kind enough to write up some comments on the Scribble hack I put together for generating HTML. Because of Blogger's limited comment form, he sent them to me via e-mail. I think they more than deserve their own post, so they are posted below.

Thanks Eli!


Eli says:

That's all very nice, but you could easily take this *much* further... One thing that I noticed is that you're using just plain scheme code that "expands" into some string but is not using any body argument. You could use it, for example, to make a self-link thing:

   (define (url . body)
     @list{<a href="@body">@|body|</a>})

And now you can do:

   Want to visit @url[project-url].

Note that I'm using square brackets to use a Scheme expression as an argument, it could also be done with

   Want to visit @url{@project-url}.

This is semi-cute, but it's even better if you use this instead of spans, which would be even nicer with your class->style thing:

   (define (span style . body)
     @list{<span @|style|>@|body|</span>})

and now:

   We @span[loud]{rock}!

(This will require a minor change -- looks like you made your `define-style' thing use strings, and the above is easier to use if you make it just a plain definition. My guess is that this change will simplify things.)

Obviously, this can be taken further...:

   (define (p . body) @list{<p>@|body|</p>})

   ... @p{Some text here} ...

and this can end up doing the whole thing with Scheme code. And there's yet more: you can go further than just a Scheme function for each HTML tag -- you can have functions that generate the complete template. For example:

   (define (letter name . body)
     @list{<html><body><p>Hello @|name|,</p>@|body|</body></html>})

   @letter["John Doe"]{
     @p{Blah blah blah}
     ...}

This kind of a smooth transition from a pure text to a simple template to something that looks like a DSL for HTML generation is something that I talked about in the scribble syntax paper (from the Scheme workshop in the summer). Going the whole way might not be appropriate -- for example, if your clients are using this, they might feel more comfortable with sticking with writing the HTML code.

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails