gpt4 book ai didi

ruby-on-rails-3.2 - Rails + Slim 源输出

转载 作者:行者123 更新时间:2023-12-04 07:44:01 24 4
gpt4 key购买 nike

我已经搜索过了,但找不到任何东西,也许我搜索的信息有误,因为似乎应该在某处提及。基本上我有一个关于 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

slim

应用程序/views/layouts/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

app/views/layouts/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>

最佳答案

输出没有任何问题,Slim 只是压缩它以获得最佳性能。浏览器不关心它的外观,只要它能工作即可。

然而,在开发过程中,您可能需要一个更具可读性的版本来进行调试,这是可以理解的。

您可以 configure Slim像这样产生漂亮的输出:

# Indent html for pretty debugging and do not sort attributes
Slim::Engine.set_default_options :pretty => true, :sort_attrs => false

例如,只需将其放入 config/environments/development.rb 即可。

关于ruby-on-rails-3.2 - Rails + Slim 源输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17291030/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com