rlayout 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/MIT-LICENSE +20 -0
- data/README +41 -0
- data/Rakefile +29 -0
- data/lib/rlayout/layout.rb +51 -0
- data/lib/rlayout.rb +7 -0
- metadata +61 -0
data/CHANGELOG
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
Rails Layout Extension, release 0.1.0 (May. 2008)
|
2
|
+
|
3
|
+
Feature
|
4
|
+
=======
|
5
|
+
1. simplifying content_for usage by extracting key/value pair from content_for data like YAML and setting them as content_for variables
|
6
|
+
��content_for��ʹ�ã���������YAML��key/value��ʽ����content_for����
|
7
|
+
2. let erb file can determine layout by changing the default behavior of layout determining, just like java's sitemesh
|
8
|
+
ͨ���ı�Ĭ�ϵ�layout��ȡ��ʽ��ʹerbҲ���Զ���layout������java��sitemesh
|
9
|
+
|
10
|
+
Setup
|
11
|
+
=======
|
12
|
+
put the following line into your rails initializer, or bottom of environment.rb
|
13
|
+
���������д���ӵ�rails��initializer�����environment.rb�����
|
14
|
+
require 'rlayout'
|
15
|
+
|
16
|
+
Usage
|
17
|
+
=======
|
18
|
+
1. determining layout in erb file
|
19
|
+
<% content_for :config do %>
|
20
|
+
layout: happy
|
21
|
+
<% end %>
|
22
|
+
|
23
|
+
2. simplifying content_for
|
24
|
+
|
25
|
+
<% content_for :config do %>
|
26
|
+
#note��key layout won't be transferred to a content_for variable, it is only used to determine a view layout
|
27
|
+
layout: happy
|
28
|
+
title: This is my title
|
29
|
+
panel: This is my panel
|
30
|
+
<% end %>
|
31
|
+
|
32
|
+
do the same thing as the following:
|
33
|
+
|
34
|
+
<%- content_for :title do -%>
|
35
|
+
This is my title
|
36
|
+
<%- end -%>
|
37
|
+
<%- content_for :panel do -%>
|
38
|
+
This is my panel
|
39
|
+
<%- end -%>
|
40
|
+
|
41
|
+
Copyright (c) 2008 Leon Li, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
PKG_NAME = "rlayout"
|
4
|
+
PKG_VERSION = "0.1.0"
|
5
|
+
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
6
|
+
PKG_FILES = FileList[
|
7
|
+
'[A-Z]*',
|
8
|
+
'lib/**/*'
|
9
|
+
]
|
10
|
+
spec = Gem::Specification.new do |s|
|
11
|
+
s.platform = Gem::Platform::RUBY
|
12
|
+
s.summary = "improve rails layout such as simplifying content_for usage and let erb file can determine layout"
|
13
|
+
s.name = PKG_NAME
|
14
|
+
s.version = PKG_VERSION
|
15
|
+
s.require_path = 'lib'
|
16
|
+
s.homepage = %q{http://rlayout.rubyforge.org/}
|
17
|
+
s.rubyforge_project = 'Rails Layout Extension'
|
18
|
+
s.has_rdoc = false
|
19
|
+
s.authors = ["Leon Li"]
|
20
|
+
s.email = "scorpio_leon@hotmail.com"
|
21
|
+
s.files = PKG_FILES
|
22
|
+
s.description = <<-EOF
|
23
|
+
improve rails layout such as simplifying content_for usage and let erb file can determine layout
|
24
|
+
EOF
|
25
|
+
end
|
26
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
27
|
+
pkg.need_zip = true
|
28
|
+
pkg.need_tar = true
|
29
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
=begin Rlayout
|
2
|
+
author: Leon Li(scorpio_leon@hotmail.com)
|
3
|
+
=end
|
4
|
+
module Rlayout
|
5
|
+
module Layout
|
6
|
+
def self.included(base)
|
7
|
+
if base.method_defined?(:render_with_no_layout)
|
8
|
+
base.class_eval do
|
9
|
+
alias_method :render, :render_with_a_layout_ext
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
def render_with_a_layout_ext(options = nil, &block) #:nodoc:
|
14
|
+
template_with_options = options.is_a?(Hash)
|
15
|
+
|
16
|
+
#get layout from view
|
17
|
+
options_new = options.dup.merge :layout => false if template_with_options
|
18
|
+
content_for_layout = render_with_no_layout(options_new, &block)
|
19
|
+
new_layout = nil
|
20
|
+
page_config = @template.instance_variable_get("@content_for_config").strip
|
21
|
+
page_config.split("\n").each do |pair|
|
22
|
+
key, value = pair.split(": ")
|
23
|
+
if key == 'layout'
|
24
|
+
new_layout = value
|
25
|
+
else
|
26
|
+
@template.instance_variable_set("@content_for_#{key}", value)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
unless new_layout.nil? || new_layout.empty?
|
30
|
+
options[:layout] = new_layout == 'none' ? false : new_layout
|
31
|
+
end
|
32
|
+
|
33
|
+
if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options))
|
34
|
+
assert_existence_of_template_file(layout)
|
35
|
+
|
36
|
+
options = options.merge :layout => false if template_with_options
|
37
|
+
logger.info("Rendering template within #{layout}") if logger
|
38
|
+
#content_for_layout = render_with_no_layout(options, &block)
|
39
|
+
erase_render_results
|
40
|
+
add_variables_to_assigns
|
41
|
+
@template.instance_variable_set("@content_for_layout", content_for_layout)
|
42
|
+
response.layout = layout
|
43
|
+
status = template_with_options ? options[:status] : nil
|
44
|
+
render_for_text(@template.render_file(layout, true), status)
|
45
|
+
else
|
46
|
+
#render_with_no_layout(options, &block)
|
47
|
+
content_for_layout
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/rlayout.rb
ADDED
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rlayout
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Leon Li
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-05-06 00:00:00 +08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: improve rails layout such as simplifying content_for usage and let erb file can determine layout
|
17
|
+
email: scorpio_leon@hotmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- CHANGELOG
|
26
|
+
- lib
|
27
|
+
- MIT-LICENSE
|
28
|
+
- pkg
|
29
|
+
- Rakefile
|
30
|
+
- README
|
31
|
+
- lib/rlayout
|
32
|
+
- lib/rlayout/layout.rb
|
33
|
+
- lib/rlayout.rb
|
34
|
+
has_rdoc: false
|
35
|
+
homepage: http://rlayout.rubyforge.org/
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
requirements: []
|
54
|
+
|
55
|
+
rubyforge_project: Rails Layout Extension
|
56
|
+
rubygems_version: 1.0.1
|
57
|
+
signing_key:
|
58
|
+
specification_version: 2
|
59
|
+
summary: improve rails layout such as simplifying content_for usage and let erb file can determine layout
|
60
|
+
test_files: []
|
61
|
+
|