[Seaside] WAJsonCanvas
Johan Brichau
johan at inceptive.be
Sat Feb 22 20:15:00 UTC 2014
Hi Esteban,
I don't think you need the extra #element method.
How about the following:
WAJsonCanvas builder render: [ :json |
json array: [
WADocument allSubclasses do:[:each |
json value: [ json object: [ json key: 'name' value: each name ] ]]]
this produces:
'[{"name": "WAXmlDocument"}, {"name": "WAJsonDocument"}, {"name": "WAHtmlDocument"}, {"name": "WAUnescapedDocument"}, {"name": "WAPrettyPrintedDocument"}]'
But this example makes me think... I would actually want to write it as follows:
WAJsonCanvas builder render: [ :json |
json array: [
WADocument allSubclasses do:[:each |
json object: [ json key: 'name' value: each name ]]]]
i.e. without the #value: message. I would expect the canvas to put a comma in between different objects. An 'object' is actually a 'value' in the json syntax.
It might make sense.
Johan
On 21 Feb 2014, at 16:23, Esteban A. Maringolo <emaringolo at gmail.com> wrote:
> I migrated to Seaside 3.1, and I had a mix of NeoJSON and old style
> #jsonOn: implementations.
>
> By fixing the old style #jsonOn: to work with a WAJsonCanvas, I found
> I don't have a way to create an array definition specifying each
> element.
>
> It is, the implementation delegates the rendering to the Collection
> class, but I can't control it to do it manually:
>
>
> However, I implemented an #element: selector in WAJsonCanvas as follows:
> WAJsonCanvas>>#element: aValueObject
> ^ (self brush: (WAJsonElementBrush new)) with: aValueObject
>
> And then I could do:
>
> WAJsonCanvas builder render: [ :json |
> json array: [
> WADocument allSubclasses do:[:each |
> json element: [
> json object: [ json key: 'name' value: each name ]
> ]
> ]
> ]
> ]
>
> which generates the following output:
> [{"name": "WAXmlDocument"}, {"name": "WAJsonDocument"}, {"name":
> "WAHtmlDocument"}, {"name": "WAUnescapedDocument"}, {"name":
> "WAPrettyPrintedDocument"}]
>
> Without using the #element: brush all the elements aren't comma
> separated. Maybe there is another way of doing it, delegating it to
> the array brush.
>
> Is this okay? Can this be added to Seaside-JSON-Core?
>
> Regards,
>
> Esteban A. Maringolo
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
More information about the seaside
mailing list