The Haml template has all the methods accessible from the context 
object. So in order to give it ActionView helpers, you should pass in an 
instance of ActionView::Base.

Also, if you're going to be rendering the same string repeatedly, I 
strongly urge you to use Haml::Engine#def_method so Haml doesn't have to 
re-parse the string repeatedly.

InetDavid wrote:
> HAML has been working wonderfully for ALL of our Rails templates, but
> I'm hitting a problem I could use some help with.
>
> I'm trying to create some dynamic forms and would love to use snippets
> of HAML to create the pieces of the form.  To do this, I'd like to be
> able to take a string of HAML and convert it into a string of HTML.
> Searching the web I've found the following method for doing this:
>
> engine = Haml::Engine.new("<HAML STRING>")
> engine.render(Object.new, locals)    # where locals is a string of
> local variables to make available to the template.
>
> However, I'd like to include Rails tag helpers (like link_to or
> text_field) in the templates, and when using the above method those
> helpers aren't available and generate errors like "undefined method
> `text_field' for #<Object:0x7fbb9fc>".
>
> I see that the render and render_proc methods allow you to provide a
> binding instead of an object, but I'm afraid my ruby expertise isn't
> quite up to the task of figuring out how this would be done to provide
> the capability of using rails tag helpers in the render so I can do
> the conversion.
>
> Any experts out there that could point me in the right direction so I
> can parse HAML (with Rails tag helpers) from a string of HAML to a
> string of HTML?
>
> Thank you,
>
> David Schmidt
>
> >
>
>   


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to