Cool! Thanks!
It works even! :)
Happy happy joy joy! ....
Thanks my best firend, Nathan!
Regards,
- evgeny
On 5/11/07, Nathan Weizenbaum <[EMAIL PROTECTED]> wrote:
>
> Oh, I should have caught that before! The trick is that there are two ways
> of getting text to the output buffer. The first is to use "=" and include it
> as a string; the second is to directly write to the buffer. Haml code
> directly writes to the buffer, so when you call "yield", that's what's
> happening. There are two ways around this. You can either capture the Haml
> as a string and use that:
>
> def round_corners
> "<div class='rc'>#{capture { yield }}</div>"
> end
>
> Or you can use the "open" helper to create your tags, which will write to
> the buffer:
>
> def round_corners
> open 'div', :class => 'rc' { yield }
> end
>
> This way is more elegant and thus recommended. Note that it won't output
> anything, so you'll want to have
>
> - round_corners do
> %span some text
>
> in your view.
>
> - Nathan
>
> On 5/11/07, Evgeny <[EMAIL PROTECTED]> wrote:
> >
> > Oh well...
> >
> > it does not work.
> >
> > this helper:
> > def round_corners
> > "<div class='rc'>#{yield}</div>"
> > end
> >
> > this haml:
> > = round_corners do
> > %span some text
> >
> > renders this html:
> > <span>some text</span>
> > <div class='rc'>false</div>
> >
> >
> > I tried variations on yield.to_s, and using a block parameter ...
> > couldn't find something that works.
> >
> >
> > Help again please ......
> >
> >
> > Thank you!
> >
> >
> >
> >
> > On 5/11/07, Evgeny <[EMAIL PROTECTED]> wrote:
> > >
> > > Yey! So all I was missing is the "do"! :)
> > > Thanks!
> > >
> > > My example for a helper was written in the mail body, not copied there
> > > ... so I guess I wrote something that should not work, sorry. The actual
> > > helper has different div tags.
> > >
> > >
> > > Thank you again!!
> > >
> > > Now I'll be off DRYing my code ....
> > >
> > > all those round corners everywhere taking 6 lines of haml will not
> > > take 1 !
> > >
> > >
> > > Yey! :)
> > >
> > > Regards,
> > >
> > > - evgeny
> > >
> > > On 5/11/07, Nathan Weizenbaum <[EMAIL PROTECTED]> wrote:
> > > >
> > > > The reason it's breaking is that you aren't actually passing it a
> > > > block. What you're looking for is
> > > > = round_corner do
> > > > %span Some text
> > > > Also, your helper produces invalid HTML. A closing tag can't have
> > > > attributes.
> > > >
> > > > - Nathan
> > > >
> > > > Evgeny wrote:
> > > >
> > > > Greetings Haml users,
> > > >
> > > > I tried to write a simple helper method that will use a block to put
> > > > haml content inside.
> > > >
> > > > The divs are a little bit more compilcated, but what it does is this
> > > > :
> > > > def round_corner
> > > > "<div class='top_rc'>#{yield}</div class='bottom_rc'>"
> > > > end
> > > >
> > > >
> > > > And the Haml code to go with it:
> > > >
> > > > = round_corner
> > > > %span Some text
> > > >
> > > >
> > > >
> > > > Any idea why it would throw an error and not work?
> > > >
> > > > (using haml stable)
> > > >
> > > >
> > > > Regards,
> > > >
> > > >
> > > > - evgeny
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> >
> >
> >
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Haml" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---