> Stephen Pair wrote:
>
> > We've also started using SSP to generate dynamic
> > pages in a lot of places where we were using text formatters
> (with mutiple
> > levels of formatting applied). In some cases, moving to SSP
> reduced request
> > processing time from 200ms to 20ms (on a less powerful
> development machine).
>
> Eh! you started it! (-:
>
> I'm trying to learn how to use SSP (not dedicating it too
> much time...), we
> already coded
> some Comanche modules from zero, and they worked perfectly, but I
> don't fully
> understand
> how to use SSP in a Comanche module... is this possible?
Yes.
> Can you (or anybody else), write a ComancheModuleSubClass >>
> #process: (and
> friends)
> that uses SSP ?
SSP is a very simple thing...it just gives you a handy way of expressing
text that is to be written out to a stream. Squeak code snippets can be
embedded in that stream using <% and %> delimiters. An SSP method is simply
added as any other method...it's just an alternate syntax.
So, anywhere you find yourself creating a large amount of HTML text, and
possibly using text formatters (or search and replace) to place dynamic
content is a candidate for using SSP. I would still use text formatters for
Swiki templates however.
See http://ssp-squeak.swiki.net for the code. Also, we've made a few more
enhancements that we using internally that I haven't had a chance to post
yet.
So, the following two methods show a simple example how to use SSP to create
some HTML for an object:
---------
Object>>prettyHtmlOn: strm
<ssp on: strm>
Hi, my class is <b><%= self class name %></b>.
---------
Object>>prettyHtml
tmp _ WriteStream on: ''.
self prettyHtmlOn: tmp.
^tmp contents
---------
The first method actually compiles to the equivalent of:
---------
Object>>prettyHtmlOn: strm
strm nextPutAll: 'Hi, my class is <b>'.
(self class name) sspStreamOn: strm.
strm nextPutAll: '</b>.'.
---------
So, SSP just makes it a little nicer in dealing with large literal strings
(such as HTML code), with embedded Squeak code. They also have the
advantage of being pre-compiled (not requiring dynamic compiler
invocation...as my first stab at SSP did).
- Stephen
P.S. I think these examples are not fully accurate with respect to the
current version at http://ssp-squeak.swiki.net, I hope to get our latest
version up there soon.