StMenuComponent
Last updated at 8:23 pm UTC on 13 September 2017
StMenuComponent is an example of a reusable menu component for Seaside.
Description is in chapter 4 "components" of http://www.swa.hpi.uni-potsdam.de/seaside/tutorial.
1. Instance variable 'entries'
Have an instance variable 'entries' and accessors for it.
StMenuComponent>>#initialize
initialize
super initialize.
entries := OrderedCollection new.
2. General method to add menu entries
StMenuComponent>>#addEntry:withAction:
addEntry: aString withAction: aBlock
^ self entries add: aString -> aBlock
3. Rendering of menu entries
StMenuComponent>>#renderContentOn:
renderContentOn: html
self entries
do: [:entry | html anchor callback: entry value;
with: entry key]
separatedBy: [html space]
This is all what is needed for the menu to work. CSS might be added later.
How to use the menu component.
1. Have another component with an instance variable 'menuComponent'.
2. In the #initialize method initialize the menu as follows (example).
initializeMenuComponent
self menuComponent: (StMenuComponent new
addEntry: 'All' withAction: [];
addEntry: 'Completed' withAction: [];
addEntry: 'Pending' withAction: [];
addEntry: 'Missed' withAction: [];
yourself).