Now I did
addDescriptionBodyIn: aStream forItems: descriptionItems
aStream print: (STON toStringPretty: descriptionItems)
and it works sometimes.
testDescriptionBuilder
| builder string |
builder := ChrysalConfigurationBuilder new.
string := String
streamContents: [ :s | builder
addDescriptionBodyIn: s
forItems:
ChrysalConfigurationDescription itemDescriptionForXX ].
self
assert: (STON fromString: string) size
equals: ChrysalConfigurationDescription itemDescriptionForXX size
And I have no idea why I get 47 and 13 instead of 13 and 13. This is
super super strange.
Stef
On Tue, Mar 13, 2018 at 6:09 PM, Stephane Ducasse
<[email protected]> wrote:
> I originally did
>
> addDescriptionMethodBodyIn: aStream forItems: descriptionItems
> aStream nextPutAll: 'STON fromString: '.
> STON put: descriptionItems onStream: aStream
>
>
> and I get
>
> STON fromString:
> [StringConfigurationItem{#propertyName:'title',#default:'my super cool
> book'},BooleanConfigurationItem{#propertyName:'verbose',#default:'true'},StringConfigurationItem{#propertyName:'attribution',#default:'me,
> myself and I'},StringConfigurationItem{#propertyName:'series',#default:'Square
> Bracket Associate
> Collection'},StringConfigurationItem{#propertyName:'keywords',#default:'Pharo'},FolderConfigurationItem{#propertyName:'outputDirectory',#default:'build'},FileConfigurationItem{#propertyName:'mainDocument',#default:'book'},FileConfigurationItem{#propertyName:'latexTemplate',#default:'_support/templates/main.latex.mustache'},FileConfigurationItem{#propertyName:'latexChapterTemplate',#default:'_support/templates/chapter.latex.mustache'},FileConfigurationItem{#propertyName:'htmlTemplate',#default:'_support/templates/html.mustache'},FileConfigurationItem{#propertyName:'htmlChapterTemplate',#default:'_support/templates/html.mustache'},NewLineConfigurationItem{#propertyName:'newLine',#defaultKey:#unix},SymbolConfigurationItem{#propertyName:'latexWriter',#default:#'latex:sbabook'}]
>
> I see that you pass via a string and me via a stream but I wonder why
> with my solution strings where not escaped.
>
>
>
> Stef
>
> On Tue, Mar 13, 2018 at 5:13 PM, Stephane Ducasse
> <[email protected]> wrote:
>> On Tue, Mar 13, 2018 at 5:12 PM, Stephane Ducasse
>> <[email protected]> wrote:
>>> Tx sven got caught by a flu... freezing in my bed.
>>> I will check.
>>>
>>> On Mon, Mar 12, 2018 at 11:01 PM, Sven Van Caekenberghe <[email protected]>
>>> wrote:
>>>> So I guess that you want a Smalltalk expression that, when evaluated,
>>>> returns an arbitrary STON-ified object as a real object.
>>>>
>>>> Let's say you want to STON-ify the following object:
>>>>
>>>> { #firstName->'Stéphane'. #lastName->'Ducasse'. #note->'Look: '', that was
>>>> a single quote.' } asDictionary.
>>>>
>>>> Note there is a single quote character inside the #note.
>>>>
>>>> You can do that using #print: when needed. Here is an expression to see
>>>> how that works:
>>>>
>>>> Compiler evaluate: (String streamContents: [ :out |
>>>> out
>>>> nextPutAll: 'STON fromString: ';
>>>> print: (STON toString: ({ #firstName->'Stéphane'.
>>>> #lastName->'Ducasse'. #note->'Look: '', that was a single quote.' }
>>>> asDictionary)) ]).
>>>>
>>>> The Smalltalk expression then looks like this:
>>>>
>>>> STON fromString: '{#note:''Look: \'', that was a single
>>>> quote.'',#firstName:''Stéphane'',#lastName:''Ducasse''}'
>>>>
>>>> The double single quotes are Smalltalk's syntax's escaping, while the
>>>> backslashes are STON's. Yes, that is a bit confusing, but consistent.
>>>>
>>>> Is this what you need ?
>>>>
>>>>> On 12 Mar 2018, at 22:43, Stephane Ducasse <[email protected]>
>>>>> wrote:
>>>>>
>>>>> Hi
>>>>>
>>>>> I want to write a method that generate a method that when I execute
>>>>> this recreates the objects that I STONified.
>>>>> (I love STON).
>>>>>
>>>>> So I did something like that
>>>>>
>>>>> descriptionMethodFrom: descriptionItems
>>>>> "self new descriptionMethodFrom: ChrysalConfigurationDescription
>>>>> itemDescriptionForXX"
>>>>>
>>>>> ^ String streamContents: [ :s |
>>>>> s nextPutAll: 'descriptions'; cr.
>>>>> s nextPutAll: '^ STON fromString: '.
>>>>> s nextPutAll: (STON toStringPretty: descriptionItems) ]
>>>>>
>>>>> and I get of course something wrong :) because the strings are not
>>>>> doubel quoted and the first expression is not surrounded by single
>>>>> quote.
>>>>>
>>>>> And I could do it but I want a smart way to do it. I was thinking that
>>>>> may be I'm missing something obvious.
>>>>>
>>>>> descriptions
>>>>> ^ STON fromString: [
>>>>> StringConfigurationItem {
>>>>> #propertyName : 'title',
>>>>> #default : 'my super cool book'
>>>>> },
>>>>> BooleanConfigurationItem {
>>>>> #propertyName : 'verbose',
>>>>> #default : 'true'
>>>>> },
>>>>> StringConfigurationItem {
>>>>> #propertyName : 'attribution',
>>>>> #default : 'me, myself and I'
>>>>> },
>>>>> StringConfigurationItem {
>>>>> #propertyName : 'series',
>>>>> #default : 'Square Bracket Associate Collection'
>>>>> }
>>>>> ]
>>>>>
>>>>
>>>>