[squeak-dev] "Reflection and dynamic class creation and method compilation is the easiest thing evahhhh!!!!" Said no programmer ever.
gettimothy
gettimothy at zoho.com
Sat Sep 11 18:38:38 UTC 2021
Hi Folks.
I am trying to compile:
this single string is currently residing in a HelpTopic within a method named 'contents'. Below is copy-n-paste from the inspector.
'
DocOrgToX is a set of Squeak Doc classes used to convert between CustomHelp to Markup and back again.
The DocCustomHelpToOrg and DocOrgToCustomHelp classes convert from CustomHelp to Org and back again.
https://orgmode.org/guide/
MCHttpRepository
location: ''http://www.squeaksource.com/Doc''
user: ''tty''
password: ''''
'
I am trying to compile this thing dynamically to create CustomHelp stuff.
createSubclass: aHelpTopic
|newclassname methodSourceFoo|
aHelpTopic inspect.
newclassname := aHelpTopic key asSymbol.
[[ (Smalltalk at: newclassname ) isNil
ifFalse:[self inform: 'class ', newclassname, ' exists. delete it first'. ^nil]. "could use an are you sure here."
] on: Error do: []] value.
CustomHelp subclass: newclassname
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Doc-Help'.
methodSourceFoo := 'bookName ^', (aHelpTopic title).
(Smalltalk at: newclassname) class compile: methodSourceFoo . < -----WORKS FINE TO HERE.
aHelpTopic subtopics do:[:ht | |methodsource ios|
(ht key asLowercase) = (ht key)
ifTrue:[
ios := ReadStream on: (ht key) , '^HelpTopic title: ' , (ht title surroundedBySingleQuotes), ' contents: ', (ht contents asSmalltalkComment applyContortionsToRemoveBeginningAndEndingDoubleQuotes surroundedBySingleQuotes).
methodsource := (ios contents).
(Smalltalk at: newclassname) class compile: methodsource.]
].
but I 'know' there has to be an elegant way to do this besides ."asSmalltalkComment applyContortionsToRemoveBeginningAndEndingDoubleQuotes surroundedBySingleQuotes" which is not working anyway.
Any pointers greatly appreaciated!
thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20210911/6b75ffb9/attachment.html>
More information about the Squeak-dev
mailing list
|