论坛首页 Ruby版 rails

推荐一个Gem, Rlayout,简化content_for,erb定义layout

浏览 156 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
时间:2008-05-06
Rails Layout Extension

Feature
=======
1. simplifying content_for usage by extracting key/value pair from content_for data like YAML and setting them as content_for variables
简化content_for的使用,采用类似YAML的key/value方式定义content_for变量
2. let erb file can determine layout by changing the default behavior of layout determining, just like java's sitemesh
通过改变默认的layout获取方式,使erb也可以定义layout,类似java的sitemesh

Setup
=======
put the following line into your rails initializer, or bottom of environment.rb
把下列这行代码加到rails的initializer里,或者environment.rb的最后
require 'rlayout'

Usage
=======
1. simplifying content_for

<% content_for :config do %>
title: This is my title
panel: This is my panel
<% end %>


do the same thing as the following:

<%- content_for :title do -%>
This is my title
<%- end -%> 
<%- content_for :panel do -%>
This is my panel
<%- end -%> 


2. determining layout in erb file
<% content_for :config do %>
#note:key layout won't be transferred to a content_for variable, it is only used to determine a view layout
layout: happy
<% end %> 
   
论坛首页 Ruby版 rails

跳转论坛:
JavaEye推荐
    快速回复 引用上一条消息 (Alt+S)