Haml - 如何强制标签属性仅使用双引号以及如何按照我想要的方式排序标签属性?
我对稍后在 PHP 中使用的模板使用 staticmatic。 有一种奇怪的情况,有些标签属性有单引号,而有些标签属性有双引号。 我希望它们全部都有双引号(我猜这并不重要,但我希望它们像那样!)
例如,haml代码:
!!! XML
%html{html_attrs('hr-HR')}
%head
%title Some title
%meta{'http-equiv' => 'Content-Type', :content => 'text/html; charset=utf-8'}/
%meta{'name' => "description", :content => 'Some title - YO!'}/
= stylesheets
= javascripts('test', :other)
%body
= yield
产生以下内容:
<?xml version='1.0' encoding='utf-8' ?>
<html lang='hr-HR' xml:lang='hr-HR' xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>Some title</title>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
<meta content='Some title - YO!' name='description' />
<link href="stylesheets/application.css" media="all" rel="stylesheet" type="text/css"/><link href="stylesheets/grid.css" media="all" rel="stylesheet" type="text/css"/><link href="stylesheets/text.css" media="all" rel="stylesheet" type="text/css"/>
<script language="javascript" src="javascripts/test.js" type="text/javascript"></script><script language="javascript" src="javascripts/other.js" type="text/javascript"></script>
</head>
<body>
<h1>some body stuff!</h1>
utf test šđčćž ŠĐČĆŽ
</body>
</html>
请注意,如果我使用单引号或双引号,这并不重要Haml 代码中的引号,我总是得到相同的输出!
另外,似乎 haml->html 输出按字母顺序对标签属性进行排序,而不是我在 haml 中对它们进行排序的方式。 我怀疑这与 ruby 数组有关,但我不确定,因为除了 staticmatic 中的 haml 之外,我不/不能使用 Ruby。 我怎样才能让它们的顺序与我在 haml 代码中的 ruby 数组中的顺序相同?
I use staticmatic for templates I use later with PHP. There is an odd situation where some tag attributes have single quotes, while some have double quotation marks. I would like all of them to have double quotes exclusively (not that it matters I guess, but I want them like that!)
For example, haml code:
!!! XML
%html{html_attrs('hr-HR')}
%head
%title Some title
%meta{'http-equiv' => 'Content-Type', :content => 'text/html; charset=utf-8'}/
%meta{'name' => "description", :content => 'Some title - YO!'}/
= stylesheets
= javascripts('test', :other)
%body
= yield
produces following:
<?xml version='1.0' encoding='utf-8' ?>
<html lang='hr-HR' xml:lang='hr-HR' xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>Some title</title>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
<meta content='Some title - YO!' name='description' />
<link href="stylesheets/application.css" media="all" rel="stylesheet" type="text/css"/><link href="stylesheets/grid.css" media="all" rel="stylesheet" type="text/css"/><link href="stylesheets/text.css" media="all" rel="stylesheet" type="text/css"/>
<script language="javascript" src="javascripts/test.js" type="text/javascript"></script><script language="javascript" src="javascripts/other.js" type="text/javascript"></script>
</head>
<body>
<h1>some body stuff!</h1>
utf test šđčćž ŠĐČĆŽ
</body>
</html>
note that it doesn't matter if I use single quotes or double quotes in haml code, I always get the same output!
Also, it seems that haml->html output sorts tag attributes alphabetically, not the way I have ordered them in haml. I suspect this has something to do with ruby arrays, but I'm not sure since I don't/can't use Ruby apart from haml in staticmatic. How could I have them ordered the same as I have ordered them in ruby array in haml code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请尝试以下操作:
Try the following:
Haml 确实按字母顺序对属性进行排序,这确实是 Ruby 解析器的结果。 将来,属性可能会尽可能按文档顺序排序,但这在 Haml 2.2 或更高版本之前不太可能发生。
Haml does indeed order attributes alphabetically, and this is indeed a consequence of Ruby's parser. In the future, attributes may be ordered in document order as much as possible, but that's not likely to happen until Haml 2.2 or later.
引用自:http://haml.info/docs/yardoc/file.REFERENCE。 html#选项
Quote from: http://haml.info/docs/yardoc/file.REFERENCE.html#options