我已经搜索过,但找不到任何东西,也许我正在搜索错误的信息,因为这似乎应该在某处提及。基本上我有一个关于 Slim 模板引擎的问题。
在使用 Slim 时,当我查看浏览器输出的源代码时,它没有正确嵌套,看起来不专业,不像 HAML,它可以正确嵌套标签。我不确定我是否做错了什么,如果我做错了,请指出正确的方向,因为我真的很喜欢 Slim,但不幸的是,源输出对我来说是一个交易破坏者。我在下面有 Slim 和 HAML 的示例代码和输出。
我不确定它是否相关,因为我对 Rails 还是很陌生,但我的开发机器的规格如下:
*Fedora 18 x86_64
*Apache 2.4.4
*Ruby 2.0.0p195
*Rails 3.2.13
The Gem Versions for HAML and Slim:
haml (4.0.3)
haml-rails (0.4)
slim (2.0.0)
slim-rails (2.0.1)
*Apache configuration is set to: RailsEnv development
瘦
应用程序/视图/布局/application.html.slim:
doctype html
html
head
title Test Website
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "application"
= csrf_meta_tags
body
= yield
源输出:
<!DOCTYPE html><html><head><title>Test Website</title><link href="/assets/application.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/home.css?body=1" media="all" rel="stylesheet" type="text/css" /><script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/home.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script><meta content="authenticity_token" name="csrf-param" />
<meta content="EFA1Dzi1D1DY4GVBlAJ+IIyhm7ZvYch8t5v2a6cj42k=" name="csrf-token" /></head><body><h1>Home#index</h1><p>Find me in app/views/home/index.html.slim</p></body></html>
HAML
应用程序/视图/布局/application.html.haml:
!!!
%html
%head
%title Test Website
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "application"
= csrf_meta_tags
%body
=yield
源输出:
<!DOCTYPE html>
<html>
<head>
<title>Test Website</title>
<link href="/assets/application.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/home.css?body=1" media="all" rel="stylesheet" type="text/css" />
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/home.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
<meta content="authenticity_token" name="csrf-param" />
<meta content="RmxaPGwJapEf16Uw8ApQG0CpCHtr4My4aD8UO9w80dY=" name="csrf-token" />
</head>
<body>
<h1>Home#index</h1>
<p>Find me in app/views/home/index.html.haml</p>
</body>
</html>