How to get haml to interpret results as haml?

45 views
Skip to first unread message

Kurt Thams

unread,
May 29, 2012, 6:58:02 PM5/29/12
to ha...@googlegroups.com
If I want to embed a method call in a HAML page that will return some HAML, and thus I want that returned HAML to be parsed and formatted as embedded HAML, is that possible? How do you do it?

Norman Clarke

unread,
May 29, 2012, 7:03:07 PM5/29/12
to ha...@googlegroups.com
Look into the :plain filter.

On Tue, May 29, 2012 at 7:58 PM, Kurt Thams <kurt....@gmail.com> wrote:
If I want to embed a method call in a HAML page that will return some HAML, and thus I want that returned HAML to be parsed and formatted as embedded HAML, is that possible? How do you do it?

--
You received this message because you are subscribed to the Google Groups "Haml" group.
To view this discussion on the web visit https://groups.google.com/d/msg/haml/-/r24zDBfhRPwJ.
To post to this group, send email to ha...@googlegroups.com.
To unsubscribe from this group, send email to haml+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/haml?hl=en.

Kurt Thams

unread,
May 29, 2012, 7:41:00 PM5/29/12
to ha...@googlegroups.com
That appears to go the opposite direction of what I want...

Assume that I have a page like this:

  %p
    = @x.returns_haml

and @x.returns_haml returns a string like this:
  %1
    Hi Mom
  
Then I'd like the resulting HTML to be:

  <p>
    <1>
      Hi Mom
    </1>
  </p>


What I get now is, not-surprisingly: 
  <p>
      %1
    Hi Mom
  </p>




On Tuesday, May 29, 2012 4:03:07 PM UTC-7, Norman Clarke wrote:
Look into the :plain filter.

On Tue, May 29, 2012 at 7:58 PM, Kurt Thams <kurt....@gmail.com> wrote:
If I want to embed a method call in a HAML page that will return some HAML, and thus I want that returned HAML to be parsed and formatted as embedded HAML, is that possible? How do you do it?

--
You received this message because you are subscribed to the Google Groups "Haml" group.
To view this discussion on the web visit https://groups.google.com/d/msg/haml/-/r24zDBfhRPwJ.
To post to this group, send email to ha...@googlegroups.com.
To unsubscribe from this group, send email to haml+unsubscribe@googlegroups.com.

Kurt Thams

unread,
May 29, 2012, 7:53:30 PM5/29/12
to ha...@googlegroups.com
This seems to do the opposite of what I want....

Maybe an example would help:

%p
  @x.returns_haml

Where @x.returns_haml evaluates to the following string:
  %one
    Hello Mom

I would want the HTML to be

<p>
  <one>
    Hello Mom
  </one>
</p>


On Tuesday, May 29, 2012 4:03:07 PM UTC-7, Norman Clarke wrote:
Look into the :plain filter.

On Tue, May 29, 2012 at 7:58 PM, Kurt Thams <kurt....@gmail.com> wrote:
If I want to embed a method call in a HAML page that will return some HAML, and thus I want that returned HAML to be parsed and formatted as embedded HAML, is that possible? How do you do it?

--
You received this message because you are subscribed to the Google Groups "Haml" group.
To view this discussion on the web visit https://groups.google.com/d/msg/haml/-/r24zDBfhRPwJ.
To post to this group, send email to ha...@googlegroups.com.
To unsubscribe from this group, send email to haml+unsubscribe@googlegroups.com.

Norman Clarke

unread,
May 29, 2012, 9:10:05 PM5/29/12
to ha...@googlegroups.com
I see. That's not entirely doable because by your haml-returning method is invoked, the template has already been compiled and it's too late for it to be evaluated along side the rest of the Haml. In order to do this, you can:

1) Make your method that returns Haml code return rendered Haml instead.

class Foo
  def rendered_haml
    Haml::Engine.new(@bar).render
  end
end

%p
  = @foo.rendered_haml

This is fairly expensive and you probably don't want to make heavy use of this, but I don't know your circumstances or demands so I don't recommend either for or against it.

2) Make your method output HTML rather than Haml.

This would be simpler and perform better. Again, I don't know the needs of your application, but in most cases this is what I would probably do.

To view this discussion on the web visit https://groups.google.com/d/msg/haml/-/DimUzl7iq60J.

To post to this group, send email to ha...@googlegroups.com.
To unsubscribe from this group, send email to haml+uns...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages