nested_layouts 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/README.textile +151 -0
- data/Rakefile +17 -0
- data/VERSION.yml +4 -0
- data/init.rb +1 -0
- data/lib/nested_layouts.rb +23 -0
- data/rails/inti.rb +1 -0
- metadata +70 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/README.textile
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
h1. NestedLayouts
|
2
|
+
|
3
|
+
This is a gem version for "radar/nested-layouts":http://github.com/radar/nested-layouts plugin.
|
4
|
+
|
5
|
+
Plugin allows to specify outer layouts for particular layout thus creating nested layouts.
|
6
|
+
|
7
|
+
h2. Usage
|
8
|
+
|
9
|
+
You can be installed as a gem from "Gemcutter":http://gemcutter.org.
|
10
|
+
Add the following line to your @config/environment.rb@:
|
11
|
+
<pre><code>
|
12
|
+
config.gem "nested_layouts", :source => "http://gemcutter.org"
|
13
|
+
</code></pre>
|
14
|
+
|
15
|
+
h2. Wrapping layout into another layout
|
16
|
+
|
17
|
+
Let's assume you have controller which action 'hello' just was called.
|
18
|
+
Controller was set up to use 'inner' layout:
|
19
|
+
|
20
|
+
app/controllers/hello_controller.rb
|
21
|
+
|
22
|
+
<pre><code>
|
23
|
+
class HelloController < ApplicationController
|
24
|
+
layout 'inner'
|
25
|
+
|
26
|
+
def hello
|
27
|
+
render :text => 'Hello, world!'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
</code></pre>
|
31
|
+
|
32
|
+
app/views/layouts/inner.rhtml
|
33
|
+
|
34
|
+
<pre><code>
|
35
|
+
<% inside_layout 'outer' do -%>
|
36
|
+
<div class="hello">
|
37
|
+
<h1>Greetings</h1>
|
38
|
+
<%= yield %>
|
39
|
+
</div>
|
40
|
+
<% end -%>
|
41
|
+
</code></pre>
|
42
|
+
|
43
|
+
app/views/layouts/outer.rhtml
|
44
|
+
|
45
|
+
<pre><code>
|
46
|
+
<html>
|
47
|
+
<body>
|
48
|
+
<div class="content">
|
49
|
+
<%= yield %>
|
50
|
+
</div>
|
51
|
+
</body>
|
52
|
+
</html>
|
53
|
+
</code></pre>
|
54
|
+
|
55
|
+
Result will look like this (formatted for better reading):
|
56
|
+
|
57
|
+
<pre><code>
|
58
|
+
<html>
|
59
|
+
<body>
|
60
|
+
<div class="content">
|
61
|
+
<div class="hello">
|
62
|
+
<h1>Greetings</h1>
|
63
|
+
Hello, world!
|
64
|
+
</div>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
68
|
+
</code></pre>
|
69
|
+
|
70
|
+
h2. Concept
|
71
|
+
|
72
|
+
Concept of layout nesting here is based on the assumption that every
|
73
|
+
inner layout is used only to _customize_ it's outer layout and thus every
|
74
|
+
inner layout is used only with one specific outer layout. With this in
|
75
|
+
mind we can conclude that every layout must know it's outer layout and
|
76
|
+
thus information about outer layout must be embeded directly into inner
|
77
|
+
layout. Controller doesn't need to know about the whole stack of layouts,
|
78
|
+
so you should just specify the most inner layout in it.
|
79
|
+
|
80
|
+
h2. Passing data
|
81
|
+
|
82
|
+
You can pass data from inner layout to outer one, e.g.:
|
83
|
+
|
84
|
+
layouts/inner.rhtml
|
85
|
+
|
86
|
+
<pre><code>
|
87
|
+
<% content_for 'menu' do -%>
|
88
|
+
<ul>
|
89
|
+
<li><a href="about_us">About Us</a></li>
|
90
|
+
<li><a href="products">Products</a></li>
|
91
|
+
</ul>
|
92
|
+
<% end -%>
|
93
|
+
|
94
|
+
<% inside_layout 'outer' do -%>
|
95
|
+
<% @other_data_for_outer_layout = 'foo' -%>
|
96
|
+
<%= yield %>
|
97
|
+
<% end -%>
|
98
|
+
</code></pre>
|
99
|
+
|
100
|
+
layouts/outer.rhtml
|
101
|
+
|
102
|
+
<pre><code>
|
103
|
+
<%= yield 'menu' %>
|
104
|
+
<br/>
|
105
|
+
The data was: <%= @other_data_for_outer_layout %>
|
106
|
+
<br/>
|
107
|
+
<%= yield %>
|
108
|
+
</code></pre>
|
109
|
+
|
110
|
+
h2. Inline layouts
|
111
|
+
|
112
|
+
Instead of using layout stored in file system, you can use
|
113
|
+
+inside_inline_layout+ to wrap template part into some template
|
114
|
+
code passed as a string. It is usefull if you want to use
|
115
|
+
layouts that are stored in DB:
|
116
|
+
|
117
|
+
|
118
|
+
Layout model
|
119
|
+
|
120
|
+
<pre><code>
|
121
|
+
class Layout < ActiveRecord::Base
|
122
|
+
# Has attributes 'name' and 'contents'
|
123
|
+
end
|
124
|
+
</code></pre>
|
125
|
+
|
126
|
+
Helper
|
127
|
+
|
128
|
+
<pre><code>
|
129
|
+
module ApplicationHelper
|
130
|
+
def inside_db_layout(name, &block)
|
131
|
+
layout = Layout.find_by_name(name)
|
132
|
+
template = layout ? layout.contents : '<%= yield %>'
|
133
|
+
inside_inline_layout(template, &block)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
</code></pre>
|
137
|
+
|
138
|
+
View
|
139
|
+
|
140
|
+
<pre><code>
|
141
|
+
<% inside_db_layout 'layout_from_db1' do %>
|
142
|
+
Content
|
143
|
+
<% end %>
|
144
|
+
</code></pre>
|
145
|
+
|
146
|
+
|
147
|
+
== Bugs & Feedback
|
148
|
+
|
149
|
+
Plugin originally by Ryan Bigg (radarlistener@gmail.com)
|
150
|
+
|
151
|
+
Home Page: "http://github.com/radar/nested-layouts":http://github.com/radar/nested-layouts
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "nested_layouts"
|
8
|
+
gem.summary = "Plugin allows to specify outer layouts for particular layout thus creating nested layouts."
|
9
|
+
gem.email = "Sunteya@gmail.com"
|
10
|
+
gem.homepage = "http://github.com/sunteya/nested_layouts"
|
11
|
+
gem.authors = ["Sunteya"]
|
12
|
+
gem.add_dependency "actionpack", ">= 2.3"
|
13
|
+
end
|
14
|
+
Jeweler::RubyforgeTasks.new
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
data/VERSION.yml
ADDED
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/rails/init.rb"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ActionView #:nodoc:
|
2
|
+
module Helpers #:nodoc:
|
3
|
+
module NestedLayoutsHelper
|
4
|
+
|
5
|
+
# Wrap part of the template into layout.
|
6
|
+
# All layout files must be in app/views/layouts.
|
7
|
+
def inside_layout(layout, &block)
|
8
|
+
layout_template = @template.view_paths.find_template(layout.to_s =~ /layouts\// ? layout : "layouts/#{layout}", :html)
|
9
|
+
@template.instance_variable_set('@content_for_layout', capture(&block))
|
10
|
+
concat( layout_template.render_template(@template) )
|
11
|
+
end
|
12
|
+
|
13
|
+
# Wrap part of the template into inline layout.
|
14
|
+
# Same as +inside_layout+ but takes layout template content rather than layout template name.
|
15
|
+
def inside_inline_layout(template_content, &block)
|
16
|
+
@template.instance_variable_set('@content_for_layout', capture(&block))
|
17
|
+
concat( @template.render(:inline => template_content) )
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
ActionView::Base.send :include, ActionView::Helpers::NestedLayoutsHelper
|
data/rails/inti.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'nested_layouts'
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nested_layouts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sunteya
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-19 00:00:00 +08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: actionpack
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "2.3"
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: Sunteya@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.textile
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- README.textile
|
36
|
+
- Rakefile
|
37
|
+
- VERSION.yml
|
38
|
+
- init.rb
|
39
|
+
- lib/nested_layouts.rb
|
40
|
+
- rails/inti.rb
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://github.com/sunteya/nested_layouts
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options:
|
47
|
+
- --charset=UTF-8
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.3.5
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Plugin allows to specify outer layouts for particular layout thus creating nested layouts.
|
69
|
+
test_files: []
|
70
|
+
|