On Apr 1, 4:23 pm, B Smith-Mannschott <bsmith.o...@gmail.com> wrote:
> Thanks very much for the link. I'm enjoying the paper. When I've
> addressed my immediate needs (with stringtemplate), I hope to return
> to it again in more depth. I have this notion, that an alternate
> reader for Clojure in the style of Scribble combined with core
> concepts of stringtemplate could make a convenient and yet lispy
> templating system for producing non-lisp code and other textual
> output.

At the time I worked on this, I've looked at a number of systems, and
none were close to being complete in what they were doing.  IIRC, I
got the general impression that they were all dealing with HTML
output, and things started to go downhill when people tried to
generalize that.  I definitely remember Cheetah being one of these,
where there were some really odd corners around indentation -- an
issue that came up when people tried to use it as a code generator.

OTOH, I made the scribble thing flexible enough that I could even
tackle the odd rules of indenting CPP #-lines.  You can see an example
of that in our ffi code:

  http://git.racket-lang.org/plt/blob/HEAD:/src/foreign/foreign.c

and the source file that generates that:

  http://git.racket-lang.org/plt/blob/HEAD:/src/foreign/foreign.rktc

Look for "(ffi-lib filename no-error?)" in both files, and see how the
output gets indented.  See also some of that documented in the text
languague description at:

  http://docs.racket-lang.org/scribble/preprocessor.html

(but in retrospect I dislike the overloading of lists as markers for
an indentation group, and will change that in the very near future to
`block'.)

I think that I didn't look at StringTemplate at the time -- maybe it
wasn't too known then.  In any case, looking at some examples (eg,
http://www.antlr.org/wiki/display/ST/Five+minute+Introduction), I
don't see anything radically different from the other tools in the
same category...  (The main difference is a little too much
buzzword-itis...)  So it looks like it's very similar to do these
things with plain scribble.  For example, if I translate the
"homepage.st" example from that page to Racket, I'd do this (the first
line specifies using the @-reader, and the `require' line gives me the
`output' function which, roughly speaking, displays its argument(s)):

  #lang at-exp racket
  (require scribble/text)
  (define (hello-world title name friends)
    @list{
      <html>
          <head>
             <title>@|title|</title>
          </head>
          <body>
             <p>Hello again, @name !</p>
             <p>Greetings to your friends @(add-between friends ", ")</
p>
         </body>
      </html>
    })
  (output (hello-world "Welcome To NotStringTemplate"
                       "World"
                       '("Ter" "Kunle" "Micheal" "Marq")))

Note that the @|...| thing is needed when the racket expression
(`title' in the above) needs to be separated from the text around it.
The thing that makes this attractive to me is that there is no need to
talk about "attributes", "properties", etc -- it's *just* code.  If
you have some objects then things work fine too, of course, but you
can mix things in way you want.  For example, I can easily change the
above with dropping the `title' argument and instead define a single
global value for it -- so the choice of using an argument or a fixed
global is something that is up to the code.

But there is an important point that they're talking about there --
the model-view separation -- which (I think) is coming from the
HTML-generating heritage of these systems, where you want some people
to do the HTML design, and other people to do the hacking.  (Seems
that "logic" is the canonical term for "programming" in these
contexts...)  Racket has an `include' thing that can basically read
some source code file into any context, and the `scribble/text' module
uses that and provides an `include/text' which is the same thing, only
using the @-reader to read the file.  Think about `include' as a kind
of a macro that `read's some random file to produce its output, and
`include/text' does the same with the extended readtable.  So to get
this separation, take the textual contents of the `hello-world'
function and dump it in a "homepage.st" file (unindented, of course),
then change the above code to be:

  #lang at-exp racket
  (require scribble/text)
  (define (hello-world title name friends)
    (include/text "homepage.st"))
  (output ...same as above...)

You can see a number of similar examples in the templates chapter of
our web-server manual, which uses the same thing.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to