How to Add a Pier Structure

How to add a new structure to Pier:

  1. Subclass of PRStructure (or a subclass of it)

    PRStructure subclass: #PRWorkoutLog
    	instanceVariableNames: 'date exercies'
    	classVariableNames: ''
    	package: 'Pier-Workout'

  2. Add class>>isAbstract to return false (otherwise it won't be an option, and tests using the the class will fail to create an instance of it)
  3. Add class>>label to return the name you want to display (an informal name for your class). Add accessors and initializing.
  4. Add the method:

    viewComponentClass
    	^ PRWorkoutLogView

    Define it as:

    PRViewComponent subclass: #PRWorkoutLogView
    	instanceVariableNames: ''
    	classVariableNames: ''
    	package: 'Pier-Workout'

  5. Add

    PRWorkoutLogView>>renderContentOn: html
    	html
    		text: 'Test'

  6. Create a workout log and add it through code - add methods for adding workouts and create the model:

    (PRPathLookup start: (PRKernel instanceNamed: 'Pier') root path: '/John Borden/Todo/Workout') addChild:
    	((PRWorkoutLog new) addWorkout: (
    			PRWorkout new addExerciseEntry: (
    				PRExerciseEntry newOf: (
    					PRExercise name: 'Bench Press' weightUnits: 'lb'
    					details: 'Flat bench with bar') weight: 200.5 times: 12)
    			);
    		name: 'test';
    		title: 'Test';
    		yourself).

  7. When the new view should only be displayed in certain circumstances, add the class method isValidIn:. If this is not present, it will be listed under Views:
  8. See what can be displayed in the browser.
Following these steps allows one to create the structure instance with the name and title. Subclassing PRCase will include the document contents (which is what was done for Pier Task List).

There are common pitfalls related to Seaside and Pier, and several specific to new structures:

  • Error: MessageNotUnderstood: receiver of "detect:ifNone:" is nil - This can be caused by not calling super initialize from the new classes initialize method.

Posted by John Borden at 23 August 2017, 11:59 pm link