nested-layouts 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
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 "GitHub":http://github.com.
10
+ Add the following line to your @config/environment.rb@:
11
+ <pre><code>
12
+ config.gem "sunteya-nested-layouts", :source => "http://gems.github.com", :lib => "nested-layouts"
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
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 1
4
+ :patch: 1
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
@@ -0,0 +1,45 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{nested-layouts}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Sunteya"]
12
+ s.date = %q{2009-10-19}
13
+ s.email = %q{Sunteya@gmail.com}
14
+ s.extra_rdoc_files = [
15
+ "README.textile"
16
+ ]
17
+ s.files = [
18
+ ".gitignore",
19
+ "README.textile",
20
+ "Rakefile",
21
+ "VERSION.yml",
22
+ "init.rb",
23
+ "lib/nested_layouts.rb",
24
+ "nested-layouts.gemspec",
25
+ "rails/inti.rb"
26
+ ]
27
+ s.homepage = %q{http://github.com/sunteya/nested-layouts}
28
+ s.rdoc_options = ["--charset=UTF-8"]
29
+ s.require_paths = ["lib"]
30
+ s.rubygems_version = %q{1.3.5}
31
+ s.summary = %q{Plugin allows to specify outer layouts for particular layout thus creating nested layouts.}
32
+
33
+ if s.respond_to? :specification_version then
34
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
35
+ s.specification_version = 3
36
+
37
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
38
+ s.add_runtime_dependency(%q<actionpack>, [">= 2.3"])
39
+ else
40
+ s.add_dependency(%q<actionpack>, [">= 2.3"])
41
+ end
42
+ else
43
+ s.add_dependency(%q<actionpack>, [">= 2.3"])
44
+ end
45
+ end
data/rails/inti.rb ADDED
@@ -0,0 +1 @@
1
+ require 'nested_layouts'
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nested-layouts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
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
+ - nested-layouts.gemspec
41
+ - rails/inti.rb
42
+ has_rdoc: true
43
+ homepage: http://github.com/sunteya/nested-layouts
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --charset=UTF-8
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.5
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Plugin allows to specify outer layouts for particular layout thus creating nested layouts.
70
+ test_files: []
71
+