Sample code using MACssRenderer, MADivsRenderer or Magritte-ComponentDecoration?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Sample code using MACssRenderer, MADivsRenderer or Magritte-ComponentDecoration?

Rick Flower
Hi all..

I'm trying to wrap my brain around the above classes and what they  
offer over the default rendering that Magritte offers  
(MATableRenderer)... To that end, I've seen a few little snippets  
using a little of the above but still can't seem to figure out the  
typical usage scenario.. I've got existing css that I would like to  
use to dress up various pieces of one or more objects -- similar to  
what Keith has submitted in photo form here on this mailing list  
earlier this year (enclosing various fields in boxes,etc).. Anyway, if  
someone can post a little code that can do something akin to that,  
that would get me past my current hurdle.. MANY thanks in advance!

-- Rick


_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Sample code using MACssRenderer, MADivsRenderer or Magritte-ComponentDecoration?

Lukas Renggli-2
> I'm trying to wrap my brain around the above classes and what they
> offer over the default rendering that Magritte offers
> (MATableRenderer)... To that end, I've seen a few little snippets
> using a little of the above but still can't seem to figure out the
> typical usage scenario.. I've got existing css that I would like to
> use to dress up various pieces of one or more objects -- similar to
> what Keith has submitted in photo form here on this mailing list
> earlier this year (enclosing various fields in boxes,etc).. Anyway, if
> someone can post a little code that can do something akin to that,
> that would get me past my current hurdle.. MANY thanks in advance!

MATableRenderer (default) and MACssRenderer are complementary. These  
classes define how the different input fields are laid out in the  
XHTML. You can choose a different renderer by overriding the container  
description:

        descriptionContainer
                ^ super descriptionContainer componentRenderer: MACssRenderer

* MATableRenderer creates something along:

<table>
        <tr class="group">
                <th colspan="2">[Group]</th>
        </tr>
        <tr>
                <th>[Label]</th>
                <td>[Component]</th>
        </tr>
        ...
</table>

This is what traditional web applications mostly had. It looks ok even  
without applying any style-sheets.

* MACssRenderer creates something along:

<dl>
        <dt class="group">[Group]</dt>
        <dt>[Label]</dt>
        <dd>[Component]</dd>
        ...
</dl>

This is is a more modern approach (semantically meaningful) and  
requires some CSS tweaking.

In both cases you don't have many possibilities to tweak the XHTML  
generation. You might set a CSS class to the descriptions though, that  
gets added to <th>, <td> and <dt>, <dd> respectively:

        descriptionFirstName
                ^ MAStringDescription new
                        accesssor: #firstName;
                        cssClass: 'firstname';
                        yourself

In your case you probably need to provide your own implementation of a  
renderer.

* The components (subclasses of MADescriptionComponent) provide the  
view of the description. Every description has a default component,  
but some have addition views. You can choose the different view like  
this:

        descriptionVegetarian
                ^ MABooleanDescription new
                        accessor: #vegetarian;
                        componentClass: MACheckboxComponent;
  "or MASelectListComponent or MARadioGroupComponent" ;
                        yourself

* The decorations (subclasses of MAComponentDecoration) are solely  
used to attach the form around the components, to display the error  
messages and to add form buttons.

Hope this helps? I might turn this answer into a blog post someday ;-)

Cheers,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch


_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Sample code using MACssRenderer, MADivsRenderer or Magritte-ComponentDecoration?

Rick Flower
On Aug 10, 2008, at 11:46 PM, Lukas Renggli wrote:

[ ... snippet content ... ]

> In your case you probably need to provide your own implementation of a
> renderer.
>
> * The components (subclasses of MADescriptionComponent) provide the
> view of the description. Every description has a default component,
> but some have addition views. You can choose the different view like
> this:
>
> descriptionVegetarian
> ^ MABooleanDescription new
> accessor: #vegetarian;
> componentClass: MACheckboxComponent;
>   "or MASelectListComponent or MARadioGroupComponent" ;
> yourself
>
> * The decorations (subclasses of MAComponentDecoration) are solely
> used to attach the form around the components, to display the error
> messages and to add form buttons.
>
> Hope this helps? I might turn this answer into a blog post someday ;-)

Lukas -- Thanks for the great write-up!  That is what I was looking  
for and something I think that ought
to be captured in an FAQ at least.. Anyway -- if I want to write my  
own renderer, I'm assuming the
renderer will get a copy of the object to be rendered or does it work  
differently?  If you want to point me
to an example, that would be good too!  Thanks again!

-- Rick





_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Sample code using MACssRenderer, MADivsRenderer or Magritte-ComponentDecoration?

Randal L. Schwartz
>>>>> "Richard" == Richard E Flower <[hidden email]> writes:

Richard> Anyway -- if I want to write my own renderer, I'm assuming the
Richard> renderer will get a copy of the object to be rendered or does it work
Richard> differently?  If you want to point me to an example, that would be
Richard> good too!  Thanks again!

The best examples, as always, are the source code for the existing renderers.
I learned a lot from studying the source code, although the whole visitor
pattern thing turns everything sideways and requires having a quite a bit
of screen real estate to have all the particpating classes on the screen
at once. :)

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki