Haml - 如何强制标记属性仅使用双引号?如何按照我想要的方式命令标记属性?

时间:2022-09-15 15:07:48

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!)

我将staticmatic用于稍后用PHP的模板。有一种奇怪的情况,其中一些标记属性具有单引号,而一些标记属性具有双引号。我希望他们所有人都有双引号(不是我猜的很重要,但我希望他们这样!)

For example, haml code:

例如,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

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!

请注意,如果我在haml代码中使用单引号或双引号并不重要,我总是得到相同的输出!

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?

此外,似乎haml-> html输出按字母顺序排序标记属性,而不是我用haml命令它们的方式。我怀疑这与ruby数组有关,但我不确定,因为我不能/不能在静态的情况下使用Ruby而不是haml。我怎么能按照我在haml代码中用ruby数组中的顺序订购它们?

3 个解决方案

#1


28  

Try the following:

请尝试以下方法:

Haml::Template.options[:attr_wrapper] = '"'

#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.

Haml确实按字母顺序排序属性,这确实是Ruby解析器的结果。将来,属性可能会按文档顺序排序,但直到Haml 2.2或更高版本才可能发生。

#3


0  

Quote from: http://haml.info/docs/yardoc/file.REFERENCE.html#options

引自:http://haml.info/docs/yardoc/file.REFERENCE.html#options

Haml understands various configuration options that affect its performance and output.

Haml了解影响其性能和输出的各种配置选项。

In Rails, options can be set by setting the Haml::Template.options hash in an initializer:

在Rails中,可以通过在初始化程序中设置Haml :: Template.options哈希来设置选项:

# config/initializers/haml.rb

#config / initializers / haml.rb

Haml::Template.options[:format] = :html5

Outside Rails, you can set them by configuring them globally in Haml::Options.defaults:

在Rails之外,您可以通过在Haml :: Options.defaults中全局配置它们来设置它们:

Haml::Options.defaults[:format] = :html5

Finally, you can also set them by passing an options hash to [Haml::Engine#initialize][1]. For the complete list of available options, please see [Haml::Options][2].

最后,您还可以通过将选项哈希传递给[Haml :: Engine#initialize] [1]来设置它们。有关可用选项的完整列表,请参阅[Haml :: Options] [2]。

[1]: http://haml.info/docs/yardoc/Haml/Engine.html#initialize-instance_method

[1]:http://haml.info/docs/yardoc/Haml/Engine.html#initialize-instance_method

[2]: http://haml.info/docs/yardoc/Haml/Options.html

[2]:http://haml.info/docs/yardoc/Haml/Options.html

#1


28  

Try the following:

请尝试以下方法:

Haml::Template.options[:attr_wrapper] = '"'

#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.

Haml确实按字母顺序排序属性,这确实是Ruby解析器的结果。将来,属性可能会按文档顺序排序,但直到Haml 2.2或更高版本才可能发生。

#3


0  

Quote from: http://haml.info/docs/yardoc/file.REFERENCE.html#options

引自:http://haml.info/docs/yardoc/file.REFERENCE.html#options

Haml understands various configuration options that affect its performance and output.

Haml了解影响其性能和输出的各种配置选项。

In Rails, options can be set by setting the Haml::Template.options hash in an initializer:

在Rails中,可以通过在初始化程序中设置Haml :: Template.options哈希来设置选项:

# config/initializers/haml.rb

#config / initializers / haml.rb

Haml::Template.options[:format] = :html5

Outside Rails, you can set them by configuring them globally in Haml::Options.defaults:

在Rails之外,您可以通过在Haml :: Options.defaults中全局配置它们来设置它们:

Haml::Options.defaults[:format] = :html5

Finally, you can also set them by passing an options hash to [Haml::Engine#initialize][1]. For the complete list of available options, please see [Haml::Options][2].

最后,您还可以通过将选项哈希传递给[Haml :: Engine#initialize] [1]来设置它们。有关可用选项的完整列表,请参阅[Haml :: Options] [2]。

[1]: http://haml.info/docs/yardoc/Haml/Engine.html#initialize-instance_method

[1]:http://haml.info/docs/yardoc/Haml/Engine.html#initialize-instance_method

[2]: http://haml.info/docs/yardoc/Haml/Options.html

[2]:http://haml.info/docs/yardoc/Haml/Options.html