Magritte is a meta-engine that can be instantiated for any Pharo object. One of its applications is that of generating forms out of the meta-descriptions to enable the user to manipulate the values of an object. These forms can be rendered in multiple ways, such as a web form. Given that the engine also offers a backend for rendering morphs directly in the Pharo image, this can be leveraged to be integrated as well in the GTInspector.
Let’s take a look at an example.
In the latest Moose 5.1 distribution, the
GLMMagrittePersonExample class provides an simple example for describing a person with a name and an address, and if you inspect an instance of this class, you get a form with which you can manipulate those fields:
How does this work? Both the name and the address are described as Magritte properties like this:
GLMMagrittePersonExample>>descriptionName <magritteDescription> ^ MAStringDescription new accessor: #name; label: 'Name'; yourself
Glamour, the engine behind the GTInspector, can embed Magritte forms directly. As our annotated object already provides a description, the extension to offer the presentation in the inspector is as simple as:
GLMMagrittePersonExample>>gtInspectorMagritteIn: composite <gtInspectorPresentationOrder: 40> composite magritte title: 'Form'; display: [ self ]
That’s it. Once you have Magritte annotations, you can directly use them to provide form manipulation directly in the inspector, or for that matter, in any other Glamour browser.