HAML的点点滴滴

待解决问题:

如何去掉空格?换行难免会产生空格。

 

http://haml-lang.com/

http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#plugin

 

rails view中可以用.erb。为了让.erb文件更简洁,可以用.haml。

实例:

.haml 下者为.erb写法

 

 

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

 

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

 

Rails 3, instead add the following line to the Gemfile:

gem "haml"

 

Once it’s installed, all view files with the ".html.haml" extension will be compiled using Haml. Haml is enabled by default in Merb.

You can access instance variables in Haml templates the same way you do in ERB templates. Helper methods are also available in Haml templates. For example (this example uses Rails, but the principle for Merb is the same):

# file: app/controllers/movies_controller.rb

class MoviesController < ApplicationController
  def index
    @title = "Teen Wolf"
  end
end

-# file: app/views/movies/index.haml

#content
 .title
   %h1= @title
   = link_to 'Home', home_url

may be compiled to:

<div id='content'>
  <div class='title'>
    <h1>Teen Wolf</h1>
    <a href='/'>Home</a>
  </div>
</div>

突然haml不能用了,报错template is missing .只要就可以bundle install一下解决

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值