Mixing Ruby code and literal markup with Haml

How to write this ERB in HAML

<%= some_ruby_code %>: # OR <%= some_ruby_code %><br /> 

I can:

 =some_ruby_code + ":" # and =some_ruby_code %br 

but I don't want to concatenate here, and I want to write it inline:

 (=some_ruby_code): # and (=some_ruby_code)%br 
+4
source share
2 answers
 =some_ruby_code + ":" -# and =some_ruby_code + "<br/>" 

EDIT 1:

I'm not sure exactly what you are looking for. Do you want one of them?

 ==#{some_ruby_code}: -# and ==#{some_ruby_code}<br/> 

or

 ==#{some_ruby_code}: -# and =some_ruby_code %br 

It is not possible to use %br in HAML unless this is the first thing other than a line space, to my knowledge.

+6
source

Try something like

 = some_ruby_code : = some_ruby_code %br 

Note that even if the colon is on a new line, it does not fit on a new line in HTML.

Or

 #{some_ruby_code}: #{some_ruby_code} %br 

HAML can do native Ruby interpolation with # {}.

+8
source

All Articles