English 中文(简体)
Haml 两个空间问题
原标题:haml two spaces issue
  • 时间:2012-05-26 03:10:15
  •  标签:
  • haml

使用仓时,我有跟踪问题。

首先,我想检查一个变量, 之后,使别的东西, 但它仍然应该被嵌套。

让我解释一下

代码 :

.a
  .b

gives:   <div class=a><div class=b></div></div>

当我使用仓,如果不然,我无法在.a.内筑巢.b:

- if id == 3
  .a{style =>  xxx }
- else
  .a{style =>  yyy }

    .b <-- 2 spaces, otherwise it fails. but 2 spaces are causing the following issue:

问题是,因为仓内没有尽头,我不知道如何将.b放入.a div,两种情况(如果是id 3,或其它情况)中。

作为真正的活生生的例子:

- if home != nil
  .home
    home.id
- else
  .home
    empty
- end   <--- can t use
  - if room != nil <-- without end, this will be executed only if home == nil but I wan t this to be executed always
    room.id
  - else
    empty

因为 haml doens t 支持 - end, 我无法使用它。 如果我不使用它, haml 自动关闭 div, 如果我开始切克房间的值, 因为这些值是同一行的 :)

将变量与零进行比较的示例,或仅在变量为零时才采取行动的示例,只是一例而已。我正在寻找一种解决办法,解决先缩进后缩进的问题,这样它才适用于整个语句。

有一个类似的问题:

你当然可以用汉姆尔语写出来 但会很难看

- if id == "3" then val="xxx"
- elsif id == "4" then val="yyy"
- else val="zzz"
.a { :style => val }
 .b

HAML有其优势,但它是不利因素之一的一个例子。

经编辑

或者你可能会发疯 并且像:

.a{:style => if var == "3" then "xxx" elsif var == "4" then "yyy" else "zzz" end}
最佳回答
问题回答

您也可以尝试一下:

- if contition
  - attrs = { class:  .. , id:  ..  }
- else
  - attrs = { style:  ...  }

.a{attrs}
  .b




相关问题
How to debug broken vim completefunc in haml files?

I m using rails.vim and I love how you can use ctrl-x ctrl-u in insert mode to autocomplete long method names like distance_of_time_in_words and accepts_nested_attributes_for. But for some reason it ...

ruby - if string is not contained within an array

I only want to output one anchor here. If the current_page is in the array I get two (.html and -nf.html). If it is not in the array I get as many anchors as there are items in the array. I am using ...

Feasibility of HAML + PHP/CakePHP

Is anyone using a HAML implementation for PHP like phpHaml or pHAML? Both projects have seen no activity for about 2 years, and both are < 1.0. Is it feasible/wise to use HAML for a large PHP ...

How can I use Haml with Catalyst?

Is it possible to use Haml instead of a templating engine with the Catalyst web framework?

Referencing a SASS file from HAML

How do I reference a .sass file from a .haml file? I have the following haml expression that will reference a .css file: %link{ href => /stylesheets/layout.css?cache=1 , rel => stylesheet ...

haml syntax - better way of writing this?

I have a config file full of this.... - if current_page.include? "test_string_one" - @total_index = 3 - @next_location = ../random_string/page0.html - @next_name = title 2 ...

haml syntax - better way of writing this?

There must be a better way of writing this- I m just not sure how (using staticmatic)- - if current_page.include? "0.html" - @current_index = 1 - if current_page.include? "1.html" - @...

热门标签