因为我对HTML标签感到恼火,所以我开始将我的项目转换为HAML,因为它的结构更好。我很高兴安装提供工具html2haml
来帮助我。
虽然在语法上是正确的,但处理文件会给我一个奇怪的错误,我不太明白:
/stories/_story.html.haml:28: syntax error, unexpected keyword_ensure, expecting keyword_end
...:Util.html_safe(_erbout);ensure;@haml_buffer = @haml_buffer....
... ^
/stories/_story.html.haml:31: syntax error, unexpected $end, expecting keyword_end
我的haml源只有27行,因为我对此很新,我不知道它出错的地方......这是代码:
%h1= story.title
%center
%i
by #{link_to story.user.name, story.user}
#story-short= story.short_desc
- if logged_in? and @current_user.id == story.user_id
.list-buttons
%center
= link_to 'Edit', edit_story_path(story)
|
\#{link_to 'Delete', story, :method => 'delete', :confirm => 'Are you really sure?'}
#story-body
- story.body.split("\n").each do |line|
- if line.strip.empty?
%hr/
- else
%p= line.strip
#comments
%p{:onclick => "$('#comments').find('dl').slideToggle();"} Comments to this story (click to expand)
%dl
= render :partial => 'comment', :collection => @story.comments
- if logged_in? and @current_user.id != story.user_id
%dt Leave a comment:
%dd
= form_for [story, story.comments.build] do |f|
.field= f.text_area :body
.actions= f.submit "Comment!"
所以是的,我真的很想知道这是错的。检查了几次,也许是一个bug?
感谢您的时间。
答案 0 :(得分:9)
- story.body.split("\n").each do |line|
下面的行没有缩进。这意味着Haml不知道为块自动添加end
,这导致了有问题的错误。