I am making a web store. The store will have domain
classes like
"Item", and these will need a different "display" or "view"
depending
on where they are shown. For example, one view will be to customers
so it will show things like pictures and descriptions. Another view
will be for administration so it will be for editing this information,
or creating new items.
What is the best way to do this with Magritte? I know you have like
the "description" method that makes the whole component view, and I
seem to recall that you can change the name of that method, so I was
wondering if I could have several such methods and use the one I want
depending on where I am displaying the object?
There are different ways to do this and people have posted different
solutions to this very problem to the list (check out the archive).
The approach I am using most of the time (you can see it for example
in Pier) is the following one:
- Sending #description to an object returns all the available
descriptions of this object. This is what Magritte does by default.
- To create separate sub-sets of descriptions I tag them using the
property framework. So for example I define my descriptions like:
SomeDescription new
...
propertyAt: #reported put: true;
propertyAt: #visitor put: false;
propertyAt: #administrator put: true;
...
To make the code look nicer, you would create helper method for each
tag as a class extension to MADescription.
- Now to create a view with the elements for a 'visitor' I would
write code like this:
description := aModel description select: [ :each |
each propertyAt: #visitor ifAbsent: [ false ] ].
component := description asComponentOn: aModel.
Again with the help of some dedicated helper methods you can make
your code look much simpler. This is just the full implementation to
communicate the general idea.
HTH,
Lukas
--
Lukas Renggli
http://www.lukas-renggli.ch