[squeak-dev] CustomHelpToOrg dev question.
leves at caesar.elte.hu
Fri Sep 3 18:49:41 UTC 2021
On Fri, 3 Sep 2021, gettimothy via Squeak-dev wrote:
> Hi Folks
> I am working on dumping the contents of a CustomHelp to a foo.org file in Org format as a first stab at a markup.
> It is going ok, but I really stink at Streams, so I thought I would ask here for pointers.
> DocCustomHelpToOrg toTestFile: PostgresV3Help.
> is a call and the method is:
> toTestFile: aCustomHelp
> |recurse ios contents spacer|
> spacer := (Character cr asString),(Character cr asString).
> contents := '* ', aCustomHelp name asString , spacer.
> ios := FileStream newFileNamed: ((aCustomHelp name asString), '.org').
> recurse := [:help |
> help pages do:[:each | | v |
> each asString first isUppercase
> contents := contents , '* ' .
> recurse value: (Smalltalk at: each)]
> v := help perform: each.
> contents := spacer , contents , '** ' , (v title) , (Character cr asString), spacer , (v contents) , spacer.
> recurse value: aCustomHelp.
> contents printOn: ios.
> ios close.
> try not to puke or spew diet soda out your nose.
Using #, works, but it is quite suboptimal. It'll result in the creation
of many intermediate objects and will result in quadratic runtime.
An easy way to avoid that would be to write directly into the file stream,
but Squeak's file streams are not write-buffered, so I advise against
Instead, you should create an in-memory stream, and write data into that
stream. Once done, write the contents of the stream into the file.
| contents |
contents := String streamContents: [ :stream |
<write stuff to the stream here with #nextPut:, #nextPutAll:, etc> ].
FileStream newFileNamed: <file name here> do: [ :file |
file nextPutAll: contents ]
> I am getting "ok" output, but the first issue is that the entire output is wrapped in single quotes.
That's because of the line
contents printOn: ios.
#printOn: will quote the string. What you're looking for is #nextPutAll::
ios nextPutAll: contents
More information about the Squeak-dev