There might be a more succinct way to do this but I think you'd want
to do something like this:
def sub_section(&block)
capture_haml do
haml_tag :div {:class => 'sub_section'} do
haml_concat capture_haml(&block)
end
end
end
def top(&block)
capture_haml do
haml_tag :div {:class => 'top'} do
haml_concat capture_haml(&block)
end
end
end
def bottom(&block)
capture_haml do
haml_tag :div {:class => 'bottom'} do
haml_concat capture_haml(&block)
end
end
end
Presumably you are doing this with something more complex than simply
making a way to replace your ".top" line with a "=top do" line...you'd
just add more haml_tag calls inside the capture_haml block of the
helper method to do whatever you want. Though, at some point, I think
you'd rather make a partial. For me that threshold is around 3 or 4
tags.
On Mar 25, 6:24 pm, Josh <[email protected]> wrote:
> Has anyone written helpers that accept blocks of haml? I've got the
> following code that I'd like to turn into helpers
>
> .sub_section
> .top
> %h2= pluralize(@collection_count, 'Project')
> = "(Showing [email protected]})" if @collection_count > 10
> .bottom
> View by: Name | Creation Date
>
> I'd envision the code being converted to something like this and then
> writing three methods: sub_section, top, bottom that accept a haml
> block. How could I write those helpers?
>
> =sub_section do
> =top do
> %h2= pluralize(@collection_count, 'Project')
> = "(Showing [email protected]})" if @collection_count > 10
> =bottom do
> View by: Name | Creation Date
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---