Can a block be a string?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Can a block be a string?

Andy Burnett
I am playing around with Seaside 3 and noticed that, for example:

html paragraph: 'text', and 
html paragraph: [html text: 'hello'].

Are both valid. 

When I looked at the definition for paragraph:  it says that takes a aBlock, but then doesn't seem to do a value: aBlock.  So, what I am wondering is whether it is valid to give a string as a block, or whether this is just a slightly loose definition of block?

Cheers
Andy

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Can a block be a string?

Randal L. Schwartz
>>>>> "Andy" == Andy Burnett <[hidden email]> writes:

Andy> When I looked at the definition for paragraph:  it says that takes a aBlock,
Andy> but then doesn't seem to do a value: aBlock.  So, what I am wondering is
Andy> whether it is valid to give a string as a block, or whether this is just a
Andy> slightly loose definition of block?

As I recall, the seaside things that have contents accept "renderables",
which is anything that understands #renderOn:.  Seaside monkey-patches
Object to ensure that *everything* has a #renderOn:, but there are special
overrides for Collection, String, and, as you've discovered, BlockContext.

Browse all implementors of #renderOn: for more illumination.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Can a block be a string?

Matthias Berth-2
In reply to this post by Andy Burnett
Andy,

a string and a block are two distinct things in Smalltalk. Seaside
just lets you provide one or the other as an argument for messages
like paragraph: because that's convenient when you write a web
application. Sometimes you want to have plain text in that paragraph,
then you use

  html paragraph: 'some text'.

Other times you want to nest more html structures inside the
paragraph, then you do something like

  html paragraph: [
    html span
      class: 'highlight';
      with: 'more text'
  ]

or, maybe more illustrative of the idea:

  html table: [
    html tableRow: [
      html tableData: 'cell 1'.
      html tableData: 'cell 2'
    ].
    html tableRow: [
      html tableData: 'cell 3'.
      html tableData: 'cell 4'
    ].
  ]


Somewhere in the Seaside code there is a dispatch that processes
strings and blocks differently.


HTH

Matthias

On Thu, Feb 18, 2010 at 11:33 PM, Andy Burnett
<[hidden email]> wrote:

> I am playing around with Seaside 3 and noticed that, for example:
>
> html paragraph: 'text', and
> html paragraph: [html text: 'hello'].
>
> Are both valid.
>
> When I looked at the definition for paragraph:  it says that takes a aBlock,
> but then doesn't seem to do a value: aBlock.  So, what I am wondering is
> whether it is valid to give a string as a block, or whether this is just a
> slightly loose definition of block?
>
> Cheers
> Andy
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
>
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Can a block be a string?

Amir Ansari
In reply to this post by Andy Burnett
This is a question better suited to the Seaside mailing list...!


On Thu, 18 Feb 2010 17:33:21 -0500
Andy Burnett <[hidden email]> wrote:

> I am playing around with Seaside 3 and noticed that, for example:
>
> html paragraph: 'text', and
> html paragraph: [html text: 'hello'].
>
> Are both valid.
>
> When I looked at the definition for paragraph:  it says that takes a aBlock,
> but then doesn't seem to do a value: aBlock.  So, what I am wondering is
> whether it is valid to give a string as a block, or whether this is just a
> slightly loose definition of block?
>
> Cheers
> Andy
>
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Can a block be a string?

Andy Burnett
In reply to this post by Andy Burnett
Thanks guys

I just wanted to make sure I hadn't completely misunderstood blocks!

Cheers
Andy

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Can a block be a string?

Randal L. Schwartz
>>>>> "Andy" == Andy Burnett <[hidden email]> writes:

Andy> I just wanted to make sure I hadn't completely misunderstood blocks!

No, not completely. :)

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners