Dynamic Web Development with Seaside

Buy PDF Buy Print

7.5Brush Structure

In the previous section you played with several brushes and painted a canvas with them. Now we will explain in detail how brushes work. A canvas provides a simple pattern for creating and using these brushes as shown in Figure 63.

  1. Tell the canvas what type of brush you are using.
  2. Configure the brush, specifying any special options that it may use.
  3. Render the contents of this brush. This is often done by passing an object such as a string or a block to with:.

It is not always necessary to send a brush the with: message. Do so only if you want to specify the contents of the body of the XHTML tag. Since this message causes the XHTML tag to be rendered, it should be sent last.

Select brush, configure it, and render it

Here is an example:

html heading level: 1; with: 'Hello world'.

produces the following XHTML

<h1>Hello world</h1>

In this example

  1. We first specify the brush (tag) we are using with html heading.
  2. We then send that brush the level: 1 message to indicate that this should be a level 1 heading.
  3. We tell the brush the contents of the heading and cause it to be rendered using with:.

Here are some examples that show that it is not necessary to use with: if you do not specify the attributes of the brush.

Just a brush

html paragraph

produces

 <p></p>

A brush with implicit content

html paragraph: 'foo'

produces

<p>foo</p>

Setting the content explicitly

html paragraph with: 'foo'

produces

<p>foo</p>

Setting attributes directly

html paragraph class: 'cool'; with: 'foo'

produces

<p class="cool">foo</p>

If no configuration of the brush is necessary, it is usually possible to specify it with a keyword parameter which becomes the contents of the tag. Thus the two following expressions are equivalent

html heading level: 1; with: 'Hello world'.
html heading: 'Hello World'.

since level 1 is the default level for a heading.

As you can see, there are two cases where you can write more compact code. These are summarized in Figure 64. There is a style checking tool called Slime that checks for such cases. Slime is explained in Chapter 14.

Brush Simplifications

The next section will show you what the other brushes are and how to find information about them within Seaside.

Copyright © 23 September 2017 Stéphane Ducasse, Lukas Renggli, C. David Shaffer, Rick Zaccone
This book is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 license.

This book is published using Seaside, Magritte and the Pier book publishing engine.