ending haml comments

拟墨画扇 提交于 2019-12-23 07:27:41

问题


I am new to haml and this is stumping me. I don't like to delete code where I can comment it out but I have no idea how to properly end a comment in haml.

Here is a code snippit:

.field
 = f.label :member_id
 %br/
 = f.text_field :member_id
.field
 = f.label :instrument_type
 %br/

I'm trying to comment out the first field so I used:

/
.field
 = f.label :member_id
 %br/
 = f.text_field :member_id
.field
 = f.label :instrument_type
 %br/

but that commented out everything after the first field.

Then I tried:

/
 .field
  = f.label :member_id
  %br/
  = f.text_field :member_id
.field
 = f.label :instrument_type
 %br/

but it didn't like that either, or:

 -#.field
 -# = f.label :member_id
 -# %br/
 -# = f.text_field :member_id
.field
 = f.label :instrument_type
 %br/

I must be missing something. I looked all over but the examples never show code after the comment.


回答1:


It's your spacing that is causing the problem, not your method. Here is the proper way to comment out those lines in HAML:

Your 4th example is really close:

 -#.field
 -# = f.label :member_id
 -# %br/
 -# = f.text_field :member_id
.field
 = f.label :instrument_type
 %br/

Commented out properly:

-#.field
-#  = f.label :member_id
-#  %br
-#  = f.text_field :member_id
.field
  = f.label :instrument_type
  %br

This is awfully close to what you posted on your last example, with a notable exception: Your comment lines begin with a space preceding the -#. That space at the beginning will break HAML. I also noticed that your source code is indenting by one space instead of two. This will also break HAML. It must be two spaces of indentation.

P.S. You can remove the trailing slash from your %br lines.




回答2:


A / on a blank line, followed by code, comments an indented section of code which is probably why your entire section of code is getting commented out.

Try commenting each line.

/.field<br>
/ = f.label :member_id<br>
/ %br/<br>
/ = f.text_field :member_id<br>
.field<br>
 = f.label :instrument_type<br>
 %br/<br>

Or, alternatively a blank line between the fields may give the comment a hint as to where it should end.

/    
.field<br>
 = f.label :member_id<br>
 %br/<br>
 = f.text_field :member_id<br>

.field<br>
 = f.label :instrument_type<br>
 %br/<br>


来源:https://stackoverflow.com/questions/6310761/ending-haml-comments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!