In version 1.5, there's no really god way to do this. You could use
Haml::Engine to render it using string insertion, like so:
def ariekeren_attribute(str)
Haml::Engine.new("%span#ariekeren_attribute #{str}").render
end
You could also just do the plain HTML, as in your example; there's
nothing wrong with that, although it's not quite as elegant as Haml.
In the Haml trunk, however, there's a helper method, called "open", that
allows you to create HTML elements in a more elegant way. The syntax is
as such:
def ariekeren_attribute(str)
open :span, str, :id => 'ariekeren_attribute'
end
You can also use open for more complicated nested tags, using blocks.
Although this isn't actually Haml, it's designed to be similar, and
allows you to define more complicated HTML structures in your helpers.
For example:
def ariekeren_attribute(str)
open :p, :id => 'ariekeren_attribute' do
[:span, :em, :strong].each do |tag|
open tag, str
end
end
end
I hope that's helpful. If you have any ideas about what might be an
easier way to use Haml, or something like it, in Helpers, please let us
know.
- Nathan
Arie Kusuma Atmaja wrote:
> sayang:~/langsungbuang/haml_helper arie$ cat app/views/demo/index.haml
> = Time.now
>
> = ariekeren_attribute("a Field from DB".capitalize)
>
>
> sayang:~/langsungbuang/haml_helper arie$ cat app/helpers/demo_helper.rb
> module DemoHelper
>
> def ariekeren_attribute(str)
> # %Q~<span id="ariekeren_attribute">#{str}</span>~
> %span{:id => "ariekeren_attribute"} str
> end
>
> end
> sayang:~/langsungbuang/haml_helper arie$
>
>
>
> is it possible to convert simple html to haml ? in Haml TODO?
>
> Thanks.
>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---