12/08/2008

Still slow going!

Smalltalk syntax is pretty easy to grasp, but understanding the class library can take forever (or so it feels at the moment!). Take this example:

renderEntityTableOn: html
html table
summary: 'This table gives the character entity reference,
decimal character reference, and hexadecimal character
reference for 8-bit Latin-1 characters, as well as the
rendering of each in your browser.';
with: [
html tableCaption: 'HTML 4.0 entities'.
self renderEntityTableColumnGroupsOn: html.
self renderEntityTableHeadOn: html.
self renderEntityTableFootOn: html.
self renderEntityTableBodyOn: html]

It looks reasonably straight forward, but I had a couple of questions
  1. what was the summary: item?
  2. and why did we need the with: block?
So, off I went, digging around. Now, the first thing I did was to copy this method and save it as renderEntityTableOn2:. Being able to do this from within the browser is great. Then I started removing bits. A quick look at the generated code (toggle halos and then select 'S' for the html source) showed that summary: produced an attribute in the table tag. It turns out that this is part of the html spec - I just didn't know about it.


But what about the with: block? The reason I was pondering on this was that it seemed redundant. Why not send all the messages directly to html and self? And, this is where it all gets a bit messy - although in retrospect it is all very easy to understand. I used a method finder to locate the implementors of table, and started looking at it. My initial thought was that html table would return a WAHtmlCanvas tag (not sure why I thought that), but it turns out that although table is defined in that object, it actually returns a WATableTag. And... the tag has a 'closed' property. I think that determines whether the tag is rendered as

or not. Anyway, it turns out that by sending the with: block, the contents of the block gets rendered between the table tags, rather than as separate tags.


Another bit learned ;-)

No comments: