Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Producing single-line comments with HAML?

I'm trying to generate a comment on a single line at the end of an HTML file:

<!-- generated by SERVER1 -->

I have tried

/
  generated by #{@server_name}

But this outputs it over 3 lines -

<!-- 
    generated by SERVER1 
-->

I've tried

/ generated by #{@server_name}

But that doesn't evaluate the @server_name var -

<!-- generated by #{@server_name} -->

Any ideas?

like image 487
Marklar Avatar asked Apr 12 '12 13:04

Marklar


People also ask

How do you write comments in HAML?

The hyphen followed immediately by the pound sign signifies a silent comment. Any text following this isn't rendered in the resulting document at all.

How do you write HAML in HTML?

In Haml, we write a tag by using the percent sign and then the name of the tag. This works for %strong , %div , %body , %html ; any tag you want. Then, after the name of the tag is = , which tells Haml to evaluate Ruby code to the right and then print out the return value as the contents of the tag.


2 Answers

Just as you can drop back to raw HTML output when you want, so you can drop in raw HTML comments, even with interpolation.

This template:

- @foo = 42
#test1
  /
    Hello #{@foo}
#test2
  <!-- Hello #{@foo} -->

Produces this output:

<div id='test1'>
  <!--
    Hello 42
  -->
</div>
<div id='test2'>
  <!-- Hello 42 -->
</div>

Tested with Haml v3.1.4 (Separated Sally)

like image 188
Phrogz Avatar answered Oct 02 '22 00:10

Phrogz


It's still an open issue: github.com/haml/haml/issues/313. I think you're stuck with the multiline comment for now, even though nex3 says single line interpolation should work.

like image 25
kafuchau Avatar answered Sep 28 '22 00:09

kafuchau