erb,haml或苗条:您建议哪一个?又为什么呢 [英] erb, haml or slim: which one do you suggest? And why?

查看:75
本文介绍了erb,haml或苗条:您建议哪一个?又为什么呢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Rails,并且已经看过这些模板引擎。我对他们没有经验(只有erb)。

I am learning Rails and I have seen these template engines. I have no experience with them (only erb).

但是作为我的初学者,我真的很困惑。您建议哪一个,为什么? Erb,Haml还是Slim?请说出您偏爱一个的理由。如有其他建议,请告诉我们。

But as I am a beginner, I am really confused. Which one do you suggest and why? Erb, Haml or Slim? Please tell your reason for preferring one over the others. And if you have any other recommendations, please let us know.

编辑:
我在这里没有寻找胜利者。我只想听听您对它们的意见,它们的语法,执行速度等等。

I am NOT looking for a winner here. I just want to hear your opinions about them, their syntax, speed of execution, and so on.

推荐答案

ERB主要是很好的如果您的网页设计师可以使用纯HTML,并且不知道haml或slim。这样他就可以编写HTML,并且可以在Ruby代码中嵌入适当的标签。

ERB is good mainly if you have a web designer that will work on plain HTML and does not know either haml or slim. This way he can write HTML and you can embed ruby logic with the proper tags.

如果您同时使用HTML和ruby逻辑,或者您的设计师准备学习一些东西新功能(例如HAML),我会选择HAML。与ERB相比,它对红宝石的友好程度更高,减少了字符数,可读性也大大提高了。

If you work on both HTML and ruby logic, or your designer is ready to learn something new (like HAML) I'd go for HAML. It is a lot more ruby-friendly, reduces char count by much and a lot more readable than ERB.

例如(取自官方HAML网站):

在ERB中,您的视图应如下所示:

In ERB your view will look like this:

<div id="profile">
  <div class="left column">
    <div id="date"><%= print_date %></div>
    <div id="address"><%= current_user.address %></div>
  </div>
  <div class="right column">
    <div id="email"><%= current_user.email %></div>
    <div id="bio"><%= current_user.bio %></div>
  </div>
</div>

在HAML中看起来像这样:

While in HAML it will look like this:

#profile
  .left.column
    #date= print_date
    #address= current_user.address
  .right.column
    #email= current_user.email
    #bio= current_user.bio

干净很多!

至于HAML和SLIM之间的区别-我从未真正使用过SLIM,但我想这只是一个趣味问题-看一下这两种语法并确定哪种语法在你眼中看起来更好。我认为这两个之间(HAML / SLIM)没有确定的赢家。

As for the difference between HAML and SLIM - I never really worked with SLIM but I guess it is a matter of taste - take a look at both syntaxes and decide which looks better in you eyes. I don't think there is a definite winner between those two (HAML/SLIM).

这篇关于erb,haml或苗条:您建议哪一个?又为什么呢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆