【问题标题】:Missing keyword_end on haml partial template processinghaml 部分模板处理中缺少keyword_end
【发布时间】:2010-10-19 16:37:57
【问题描述】:

因为我对 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?

感谢您的宝贵时间。

【问题讨论】:

    标签: ruby-on-rails haml


    【解决方案1】:

    - story.body.split("\n").each do |line| 下面的行没有缩进。这意味着 Haml 不知道自动为该块添加 end,这导致了有问题的错误。

    【讨论】:

    • 可能是 html2haml 中的错误?还是谢谢!
    • 如果它是一个 html2haml 错误,我有兴趣修复它。您能否提供转换为该 Haml 的原始 ERB?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-12
    • 1970-01-01
    • 2016-02-25
    相关资源
    最近更新 更多