From c144d66ca1249e3b81d85d9ae45f0a4d60ab1216 Mon Sep 17 00:00:00 2001 From: Tatu Tarvainen Date: Sat, 13 Jan 2024 23:25:03 +0200 Subject: [PATCH] Add a treenode example --- src/LiveWeb-Examples/LWTreeNode.class.st | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/LiveWeb-Examples/LWTreeNode.class.st b/src/LiveWeb-Examples/LWTreeNode.class.st index 57ebc56..a6df466 100644 --- a/src/LiveWeb-Examples/LWTreeNode.class.st +++ b/src/LiveWeb-Examples/LWTreeNode.class.st @@ -10,6 +10,16 @@ Class { #category : #'LiveWeb-Examples' } +{ #category : #'as yet unclassified' } +LWTreeNode class >> exampleSimpleTree [ + + ^ self new beBranch + label: 'root'; + child: 'My Documents' do: [ :d | d beBranch; child: 'Music'; child: 'Pictures' ]; + child: 'Secret stuff (don''t look)' do: [ :d | d beBranch; child: 'Passwords & codes' do: [ :p | p beBranch; child: 'Nuclear launch codes' ] ]; + yourself +] + { #category : #'as yet unclassified' } LWTreeNode >> beBranch [ leaf := false @@ -38,6 +48,12 @@ LWTreeNode >> child: childLabel [ ] ] +{ #category : #'as yet unclassified' } +LWTreeNode >> child: aLabel do: block [ + block value: (self child: aLabel). + ^ self +] + { #category : #accessing } LWTreeNode >> children [ ^ReadStream on: children