待解决问题:
如何去掉空格?换行难免会产生空格。
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一下解决