开发者

Whitespace Between Tags in HAML

Is there a way to specify "pretty-print"-like formatting开发者_Go百科 around HTML tags? I want to be able to put whitespace between blocks of HTML, so this:

<!-- container -->
<div id='container'>
</div>
<!-- footer -->
<div id="footer">
</div>
<!-- analytics -->
...

...is converted to this:

<!-- container -->
<div id='container'>
</div>


<!-- footer -->
<div id="footer">
</div>


<!-- analytics -->
...

I know you can do comments with /, is there something like that for whitespace between tags? Maybe something like this

/ container
#container
\
\
/ footer
#footer
:s
:s
/ analytics

Where the \ or :s could be custom filters?

Or even something like = space(10) for 10 line breaks? Or maybe even ~ by itself but that doesn't work.


#container
- haml_concat("\n" * 5)
#footer

The haml_concat helper directly concatenates text onto the output buffer, without any sort of pre-processing.


You can evaluate Ruby block to insert additional newlines:

.main
  .container
    %p Something

  ~ "\n" * 5

  .footer
    %p Footer

This also uses ~ - whitespace preservation.


\#container  
= ('< br />'*5).html_safe 

\#footer


I wrote special filter for that kind of thing: https://gist.github.com/dmitry/6050231

To use is, you just need to add :s, like in your example:

#footer
:s
:s
/ analytics
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜