HAML 视图中存在大量语法错误(使用 spree 引擎)

发布于 2024-12-25 17:48:18 字数 2488 浏览 1 评论 0 原文

我有这个简单的 HAML 视图,admin.html.haml:(

!!!
%html{:xmlns => "http://www.w3.org/1999/xhtml"}
  %head{"data-hook" => "admin_inside_head"}

该视图相当大,为了清晰起见,我删除了大部分内容)

转到 http://localhost:3000/admin< /code> 我得到:

SyntaxError in Spree/admin/overview#index

Showing /Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml where line #2 raised:

/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:2: syntax error, unexpected '=', expecting ')'
...ut.attributes({}, nil, :xmlns =&gt; "http://www.w3.org/1999/...
...                               ^
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:2: syntax error, unexpected ')', expecting '}'
..."http://www.w3.org/1999/xhtml")}>\n  <head#{_hamlout.adjust_...
...                               ^
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:3: syntax error, unexpected '=', expecting ')'
...tributes({}, nil, "data-hook" =&gt; "admin_inside_head")}></...
...                               ^
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:3: syntax error, unexpected ')', expecting '}'
...ook" =&gt; "admin_inside_head")}></head>\n</html>\n", -1, fa...
...                               ^
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:3: unknown regexp options - htl
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:3: syntax error, unexpected $undefined
...nside_head")}></head>\n</html>\n", -1, false);::Haml::Util.h...
...                               ^
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:3: unterminated string meets end of file
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:3: syntax error, unexpected $end, expecting '}'
Extracted source (around line #2):

1: !!!
2: %html{:xmlns =&gt; "http://www.w3.org/1999/xhtml"}
3:   %head{"data-hook" =&gt; "admin_inside_head"}
Trace of template inclusion: /Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml

haml gem 已正确加载(与 haml 视图缩进混淆,我得到 Haml::SyntaxError),并且在将 spree 视图切换到 haml 之前,它与 erb 视图一起工作正常。

谁能建议检查什么来解决错误?

I have this simple HAML view, admin.html.haml:

!!!
%html{:xmlns => "http://www.w3.org/1999/xhtml"}
  %head{"data-hook" => "admin_inside_head"}

(the view is quite large, I deleted most of it for clarity)

Going to http://localhost:3000/admin I get:

SyntaxError in Spree/admin/overview#index

Showing /Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml where line #2 raised:

/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:2: syntax error, unexpected '=', expecting ')'
...ut.attributes({}, nil, :xmlns => "http://www.w3.org/1999/...
...                               ^
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:2: syntax error, unexpected ')', expecting '}'
..."http://www.w3.org/1999/xhtml")}>\n  <head#{_hamlout.adjust_...
...                               ^
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:3: syntax error, unexpected '=', expecting ')'
...tributes({}, nil, "data-hook" => "admin_inside_head")}></...
...                               ^
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:3: syntax error, unexpected ')', expecting '}'
...ook" => "admin_inside_head")}></head>\n</html>\n", -1, fa...
...                               ^
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:3: unknown regexp options - htl
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:3: syntax error, unexpected $undefined
...nside_head")}></head>\n</html>\n", -1, false);::Haml::Util.h...
...                               ^
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:3: unterminated string meets end of file
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:3: syntax error, unexpected $end, expecting '}'
Extracted source (around line #2):

1: !!!
2: %html{:xmlns => "http://www.w3.org/1999/xhtml"}
3:   %head{"data-hook" => "admin_inside_head"}
Trace of template inclusion: /Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml

The haml gem is loaded correctly (messing with the haml view indentation I get a Haml::SyntaxError), and it worked ok with erb views, before switching the spree views to haml.

Can anyone suggest what to check, to resolve the errors?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

舂唻埖巳落 2025-01-01 17:48:18

我发现了问题:

Spree 使用 deface ,它与 HAML 不兼容(请参阅 此处)。

解决方案是在特定于环境的配置文件(development.rb、Production.rb 等)中禁用 deface。添加这个:

  # Disable deface
  config.deface.enabled = false 

I spotted the problem:

Spree uses deface which is incompatible with HAML (see here).

The solution is to disable deface in the environment-specific config file (development.rb, production.rb, etc). Add this:

  # Disable deface
  config.deface.enabled = false 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文