List Info

Thread: multiline ruby code




multiline ruby code
country flaguser name
United States
2007-10-15 00:20:39
Hi,

I just started using haml and quickly ran into problem. I am
trying to
write equivalent of following in haml:
<% if flash[:notice] -%>
    <p style="color: green;"><%=
flash[:notice] %></p>
<% end -%>

I thought that something like
.message
  = if flash[:notice]
  %p= flash[:notice]
  = end

I tried few variations but nothing helps. From errors I can
conclude
that it doesn't pick up 'end' . Can you show/explain what
should I do
here.

Thanks.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Haml" group.
To post to this group, send email to hamlgooglegroups.com
To unsubscribe from this group, send email to
haml-unsubscribegooglegroups.com
For more options, visit this group at http://grou
ps.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: multiline ruby code
country flaguser name
United States
2007-10-15 00:35:09
  .message
    - if flash[:notice]
      %p= flash[:notice]

The hyphen means "run this code, but don't output the
result." If 
there's an indented section of code after the hyphen, it
automatically 
adds an "end" at the end, so you can do blocks
elegantly. It's also 
smart enough not to add an end if you don't need one, so you
can do 
stuff like

  .message
    - if flash[:notice]
      %p= flash[:notice]
    - elsif flash[:error]
      %p.error= flash[:error]

- Nathan

Zeljko wrote:
> Hi,
>
> I just started using haml and quickly ran into problem.
I am trying to
> write equivalent of following in haml:
> <% if flash[:notice] -%>
>     <p style="color: green;"><%=
flash[:notice] %></p>
> <% end -%>
>
> I thought that something like
> .message
>   = if flash[:notice]
>   %p= flash[:notice]
>   = end
>
> I tried few variations but nothing helps. From errors I
can conclude
> that it doesn't pick up 'end' . Can you show/explain
what should I do
> here.
>
> Thanks.
>
>
> >
>
>   


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Haml" group.
To post to this group, send email to hamlgooglegroups.com
To unsubscribe from this group, send email to
haml-unsubscribegooglegroups.com
For more options, visit this group at http://grou
ps.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: multiline ruby code
country flaguser name
United States
2007-10-15 00:38:52
Wow. Thanks for speedy reply. This is really awesome.

On Oct 15, 12:35 am, Nathan Weizenbaum <nex...gmail.com> wrote:
>   .message
>     - if flash[:notice]
>       %p= flash[:notice]


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Haml" group.
To post to this group, send email to hamlgooglegroups.com
To unsubscribe from this group, send email to
haml-unsubscribegooglegroups.com
For more options, visit this group at http://grou
ps.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )