This post originated from an RSS feed registered with Agile Buzz
by James Robertson.
Original Post: Smalltalk CSS generation
Feed Title: Michael Lucas-Smith
Feed URL: http://www.michaellucassmith.com/site.atom
Feed Description: Smalltalk and my misinterpretations of life
So Dave's making websites with Smalltalk in the simplest possible way available to him. I think this is a great idea. In fact, I've done similar stuff using XMLMaker before. But I thought it relevant to carry on from Dave's post to introduce a new API that we have in WithStyle.
You can now build CSS objects using normal Smalltalk syntax, and at the end, get out CSS in CSS form. Lets skip ahead to the actual details:
parser := CssParser on: ''.
We have to make a CssParser because its the only one who knows how to do a 'real' printout of CSS. We could do it ourselves at a Ruleset level, but there's no point. You may need to prefix these classes with WithStyle.CssParser depending on where you're executing the code.
A Ruleset is basically a bunch of criteria for matching and then a bunch of properties.
ruleset addCriteria: 'p' asCssTypeSelector.
There are a whole bunch of selector types in CSS. Child selectors (>), adjacent selectors (+), descendant selectors (space). All of these are messages you can send to add new criteria. You can also add pseudo selectors and class selectors.
Here we've added a float: left and a width of 10em's. There are many more types of things you can add and the best way to discover them is to look at the tests that come with the code, but lets wrap this up now: