Skip to content

Instantly share code, notes, and snippets.

@timfel
Created January 13, 2011 13:03
Show Gist options
  • Save timfel/777826 to your computer and use it in GitHub Desktop.
Save timfel/777826 to your computer and use it in GitHub Desktop.
category fileout squeak
fileOutCategory := [:aCategory || subfolder |
"This creates a sub-folder in the repository for the categories classes"
subfolder := (aCategory asString findBetweenSubStrs: '-') last.
(self package packageClasses intersection: (systemOrganizer superclassOrder: aCategory)) ifNotEmptyDo: [:arr |
self createFolder: ((File path: subfolder) exists
ifFalse: [repoDir createDirectory: subfolder]).
arr do: [:aClass || aStream aFile |
aStream := WriteStream on: (String new: 100).
aClass
fileOutOn: stream
moveSource: false
toFile: 0.
aFile := (repoDir / subfolder), Directory pathSeparator asString , aClass name.
[| converter f fileName |
aStream contents isAsciiString
ifTrue: [converter := MacRomanTextConverter new]
ifFalse: [converter := UTF8TextConverter new].
fileName := aFile , ($. printString , ($s printString , $t printString)).
f := MultiByteFileStream new open: fileName forWrite: true.
f ifNil: [^self error: 'Cannot open file'].
f lineEndConvention: #lf.
(converter isMemberOf: UTF8TextConverter)
ifTrue: [ f binary.
UTF8TextConverter writeBOMOn: f ].
f text.
f converter: converter.
f nextPutAll: aStream contents.
f close.
files add: fileName. ] value.
]
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment