Leahcim
Leahcim

Reputation: 41919

Haml to HTML/erb...can anyone see the mistake I'm making

I forked a Rails project that uses Haml, which I haven't really learned. There's an online converter that helped me with the HTML, but it ignores the erb, and when I tested my own conversion, the flash messages didn't have the classes associated with them, so I know I did it wrong, but I can't see why.

Note (don't worry about spacing in the haml. in the code i have

Original haml

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

faulty Html translation

<% if flash[:notice] %>
    <div class="alert-message.warning">
    <p>
     <%= flash[:notice] %>
    </p>
    </div>
 <% end %>
   <% if flash[:error] %>
   <div class="alert-message.error">
   <p>
   <%= flash[:error] %>
   </p>
   </div>
   <% end %>

Upvotes: 1

Views: 1827

Answers (1)

ck3g
ck3g

Reputation: 5929

You have a huge indentation after first line. It should be 2 spaces.

edited: In case you need to convert small part of haml you can learn how to convert it manually. There is the little haml tutorial where you can learn some basics. That part of haml can be turned into following erb:

<% if flash[:notice] %>
  <div class="alert-message warning">
   <p><%= flash[:notice] %></p>
  </div>
<% end %>
<% if flash[:error] %>
  <div class="alert-message error">
   <p><%= flash[:error] %></p>
  </div>
<% end %>

where: - same as <%

= same as <%=

%p (%tag_name) -> <p>

.class -> %div.class -> <div class="class"

edited#2: judging by generated html <div class="alert-message.warning"> should be <div class="alert-message warning"> (dot replaced by space between classes)

Upvotes: 2

Related Questions