[squeak-dev] CustomHelpToOrg dev question.

gettimothy gettimothy at zoho.com
Sat Sep 4 18:25:13 UTC 2021

Update fy on progress...

I now iterate down the Class tree for a CustomHelp class and write their contents to a stream as well.

The iteration step looks like this (code improvements most welcome):

I create an OrderedDictionary of the classes to traverse and then add a ReadWriteStream populated from a method call as the value in the Dictionary for each one.

toFile: aCustomHelp

"write the pages of  aCustomHelp class and its subclasses to a .org file"

| oc d filename|

d := OrderedDictionary new.

oc := (aCustomHelp allSubclasses).

oc  addFirst: aCustomHelp.

oc do:[:each |	d add:(each -> nil)	].

d keysDo: [:key | |ios|

      ios := self toStream: key.   <----ReadWriteStream for a class populated here

      d at: key put: ios.].

filename := ((aCustomHelp  name  asString), '.org').

StandardFileStream forceNewFileNamed: filename do: [ :file |   <----the various ReadWriteStreams are aggregated to a StandardFileStream and written to file

            d keysAndValuesDo:[:key :value |

                    file nextPutAll: value contents ]].

"do I need to close the StandardFileStream? " 

The "toStream:" method is just the previous method minus the file write.

toStream: aCustomHelp

|ios recurse  break newline |

"write CustomHelp to a stream and return the stream"

newline := (Character cr asString).

break:= newline, newline.

ios := String streamContents:[:stream|

      stream nextPutAll: ( '*   ', aCustomHelp name asString , newline).

      recurse := [:help |

                        help pages do:[:each | | v  |

                        each asString first isUppercase


                              stream nextPutAll: ( '*  '  , each, break).

                              recurse value: (Smalltalk at: each)]


                              v := help perform: each.

                              stream nextPutAll: ( break, '** ' ,  (v title) , (Character cr asString), break , (v contents)  ,break).


recurse value: aCustomHelp


^ ios

I am guessing there is a more efficient way to do this using just one stream, but if streams are cheap, why not.

Next up is to adjust the output formatting to reflect the nesting level of the classes.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20210904/3046a1d3/attachment.html>

More information about the Squeak-dev mailing list