nestive 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +4 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +89 -57
- data/README.md +76 -81
- data/Rakefile +4 -10
- data/app/helpers/nestive/layout_helper.rb +39 -28
- data/config.ru +7 -0
- data/lib/nestive/version.rb +1 -1
- data/nestive.gemspec +14 -11
- data/spec/controllers/nestive_spec.rb +76 -0
- data/spec/internal/app/controllers/application_controller.rb +2 -0
- data/spec/internal/app/controllers/nestive_controller.rb +9 -0
- data/spec/internal/app/views/layouts/extend_one.html.erb +7 -0
- data/spec/internal/app/views/layouts/extend_two.html.erb +6 -0
- data/spec/internal/app/views/layouts/nestive.html.erb +15 -0
- data/spec/internal/app/views/nestive/append.html.erb +6 -0
- data/spec/internal/app/views/nestive/extended_one.html.erb +1 -0
- data/spec/internal/app/views/nestive/extended_two.html.erb +1 -0
- data/spec/internal/app/views/nestive/index.html.erb +1 -0
- data/spec/internal/app/views/nestive/prepend.html.erb +6 -0
- data/spec/internal/app/views/nestive/replace.html.erb +7 -0
- data/spec/internal/config/routes.rb +3 -0
- data/spec/internal/db/schema.rb +2 -0
- data/spec/internal/log/.gitignore +1 -0
- data/spec/internal/public/favicon.ico +0 -0
- data/spec/spec_helper.rb +9 -0
- metadata +105 -58
- data/test/nestive_test.rb +0 -8
- data/test/test_helper.rb +0 -3
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,78 +1,110 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nestive (0.
|
4
|
+
nestive (0.1.0)
|
5
5
|
rails (~> 3.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
rack (~> 1.2
|
21
|
-
rack-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
arel (
|
38
|
-
builder (
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
10
|
+
actionmailer (3.2.8)
|
11
|
+
actionpack (= 3.2.8)
|
12
|
+
mail (~> 2.4.4)
|
13
|
+
actionpack (3.2.8)
|
14
|
+
activemodel (= 3.2.8)
|
15
|
+
activesupport (= 3.2.8)
|
16
|
+
builder (~> 3.0.0)
|
17
|
+
erubis (~> 2.7.0)
|
18
|
+
journey (~> 1.0.4)
|
19
|
+
rack (~> 1.4.0)
|
20
|
+
rack-cache (~> 1.2)
|
21
|
+
rack-test (~> 0.6.1)
|
22
|
+
sprockets (~> 2.1.3)
|
23
|
+
activemodel (3.2.8)
|
24
|
+
activesupport (= 3.2.8)
|
25
|
+
builder (~> 3.0.0)
|
26
|
+
activerecord (3.2.8)
|
27
|
+
activemodel (= 3.2.8)
|
28
|
+
activesupport (= 3.2.8)
|
29
|
+
arel (~> 3.0.2)
|
30
|
+
tzinfo (~> 0.3.29)
|
31
|
+
activeresource (3.2.8)
|
32
|
+
activemodel (= 3.2.8)
|
33
|
+
activesupport (= 3.2.8)
|
34
|
+
activesupport (3.2.8)
|
35
|
+
i18n (~> 0.6)
|
36
|
+
multi_json (~> 1.0)
|
37
|
+
arel (3.0.2)
|
38
|
+
builder (3.0.4)
|
39
|
+
combustion (0.3.2)
|
40
|
+
rails (>= 3.0.0)
|
41
|
+
thor (>= 0.14.6)
|
42
|
+
diff-lcs (1.1.3)
|
43
|
+
erubis (2.7.0)
|
44
|
+
hike (1.2.1)
|
45
|
+
i18n (0.6.1)
|
46
|
+
journey (1.0.4)
|
47
|
+
json (1.7.5)
|
48
|
+
mail (2.4.4)
|
44
49
|
i18n (>= 0.4.0)
|
45
50
|
mime-types (~> 1.16)
|
46
51
|
treetop (~> 1.4.8)
|
47
|
-
mime-types (1.
|
48
|
-
|
49
|
-
|
50
|
-
rack
|
51
|
-
|
52
|
-
|
52
|
+
mime-types (1.19)
|
53
|
+
multi_json (1.3.7)
|
54
|
+
polyglot (0.3.3)
|
55
|
+
rack (1.4.1)
|
56
|
+
rack-cache (1.2)
|
57
|
+
rack (>= 0.4)
|
58
|
+
rack-ssl (1.3.2)
|
59
|
+
rack
|
60
|
+
rack-test (0.6.2)
|
53
61
|
rack (>= 1.0)
|
54
|
-
rails (3.
|
55
|
-
actionmailer (= 3.
|
56
|
-
actionpack (= 3.
|
57
|
-
activerecord (= 3.
|
58
|
-
activeresource (= 3.
|
59
|
-
activesupport (= 3.
|
62
|
+
rails (3.2.8)
|
63
|
+
actionmailer (= 3.2.8)
|
64
|
+
actionpack (= 3.2.8)
|
65
|
+
activerecord (= 3.2.8)
|
66
|
+
activeresource (= 3.2.8)
|
67
|
+
activesupport (= 3.2.8)
|
60
68
|
bundler (~> 1.0)
|
61
|
-
railties (= 3.
|
62
|
-
railties (3.
|
63
|
-
actionpack (= 3.
|
64
|
-
activesupport (= 3.
|
69
|
+
railties (= 3.2.8)
|
70
|
+
railties (3.2.8)
|
71
|
+
actionpack (= 3.2.8)
|
72
|
+
activesupport (= 3.2.8)
|
73
|
+
rack-ssl (~> 1.3.2)
|
65
74
|
rake (>= 0.8.7)
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
75
|
+
rdoc (~> 3.4)
|
76
|
+
thor (>= 0.14.6, < 2.0)
|
77
|
+
rake (0.9.2.2)
|
78
|
+
rdoc (3.12)
|
79
|
+
json (~> 1.4)
|
80
|
+
rspec (2.11.0)
|
81
|
+
rspec-core (~> 2.11.0)
|
82
|
+
rspec-expectations (~> 2.11.0)
|
83
|
+
rspec-mocks (~> 2.11.0)
|
84
|
+
rspec-core (2.11.1)
|
85
|
+
rspec-expectations (2.11.3)
|
86
|
+
diff-lcs (~> 1.1.3)
|
87
|
+
rspec-mocks (2.11.3)
|
88
|
+
rspec-rails (2.11.4)
|
89
|
+
actionpack (>= 3.0)
|
90
|
+
activesupport (>= 3.0)
|
91
|
+
railties (>= 3.0)
|
92
|
+
rspec (~> 2.11.0)
|
93
|
+
sprockets (2.1.3)
|
94
|
+
hike (~> 1.2)
|
95
|
+
rack (~> 1.0)
|
96
|
+
tilt (~> 1.1, != 1.3.0)
|
97
|
+
thor (0.16.0)
|
98
|
+
tilt (1.3.3)
|
99
|
+
treetop (1.4.12)
|
100
|
+
polyglot
|
70
101
|
polyglot (>= 0.3.1)
|
71
|
-
tzinfo (0.3.
|
102
|
+
tzinfo (0.3.35)
|
72
103
|
|
73
104
|
PLATFORMS
|
74
105
|
ruby
|
75
106
|
|
76
107
|
DEPENDENCIES
|
108
|
+
combustion (~> 0.3.2)
|
77
109
|
nestive!
|
78
|
-
rails (~>
|
110
|
+
rspec-rails (~> 2.11)
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
# Nestive
|
1
|
+
# Nestive
|
2
|
+
[![Build Status](https://travis-ci.org/rwz/nestive.png)](https://travis-ci.org/rwz/nestive)
|
3
|
+
## A Nested Inheritable Layouts Plugin for Rails
|
2
4
|
|
3
|
-
**Note: This is ridiculously alpha proof-of-concept seeking feedback. Things will change.**
|
4
5
|
|
5
6
|
Nestive adds powerful layout and view helpers to your Rails app. It's similar to the nested layout technique [already documented in the Rails guides](http://guides.rubyonrails.org/layouts_and_rendering.html#using-nested-layouts) and found in many other nested layout plugins (a technique using `content_for` and rendering the parent layout at the end of the child layout). There's a bunch of problems with this technique, including:
|
6
7
|
|
@@ -9,14 +10,14 @@ Nestive adds powerful layout and view helpers to your Rails app. It's similar to
|
|
9
10
|
|
10
11
|
Nestive is *better* because it addresses these problems.
|
11
12
|
|
12
|
-
## Just five methods (so far) – `area`, `
|
13
|
+
## Just five methods (so far) – `area`, `extends`, `append`, `prepend`, `replace`.
|
13
14
|
|
14
15
|
### Declaring an area of content in your parent layout with `area`:
|
15
16
|
|
16
17
|
The `area` helper is a lot like Rails' own `<%= yield :foo %>`, and is used in layouts to define and render a chunk of content in your layout:
|
17
18
|
|
18
19
|
<%= area :sidebar %>
|
19
|
-
|
20
|
+
|
20
21
|
Unlike `yield`, `area` will allow your parent layouts to add content to the area at the same time using either a String or a block:
|
21
22
|
|
22
23
|
<%= area :sidebar, "Some Content Here" %>
|
@@ -24,41 +25,16 @@ Unlike `yield`, `area` will allow your parent layouts to add content to the area
|
|
24
25
|
<%= area :sidebar do %>
|
25
26
|
Some Content Here
|
26
27
|
<% end %>
|
27
|
-
|
28
|
-
It's important to note that this isn't *default* content, it *is* the content (unless a child changes it).
|
29
|
-
|
30
|
-
### Extending a layout in a child layout (or view):
|
31
|
-
|
32
|
-
Any layout (or view) can declare that it wants to inherit from and extend a parent layout, in this case we're extending `app/views/layouts/application.html.erb`:
|
33
|
-
|
34
|
-
<%= extends :application do %>
|
35
|
-
...
|
36
|
-
<% end %>
|
37
|
-
|
38
|
-
You can nest many levels deep:
|
39
28
|
|
40
|
-
|
41
|
-
<%= extends :blog do %>
|
42
|
-
...
|
43
|
-
<% end %>
|
44
|
-
|
45
|
-
# app/views/layouts/blog.html.erb
|
46
|
-
<%= extends :public do %>
|
47
|
-
...
|
48
|
-
<% end %>
|
49
|
-
|
50
|
-
# app/views/layouts/public.html.erb
|
51
|
-
<%= extends :application do %>
|
52
|
-
...
|
53
|
-
<% end %>
|
29
|
+
It's important to note that this isn't *default* content, it *is* the content (unless a child changes it).
|
54
30
|
|
55
31
|
### Appending content to an area:
|
56
32
|
|
57
33
|
The implementation details are quite different, but the `append` helper works much like Rails' built-in `content_for`. It will work with either a String or block, adding the new content onto the end of any content previously provided by parent layouts:
|
58
34
|
|
59
35
|
<%= extends :application do %>
|
60
|
-
|
61
|
-
|
36
|
+
<% append :sidebar, "More content." %>
|
37
|
+
<% append :sidebar do %>
|
62
38
|
More content.
|
63
39
|
<% end %>
|
64
40
|
<% end %>
|
@@ -85,17 +61,63 @@ You can also replace any content provided by parent layouts:
|
|
85
61
|
<% end %>
|
86
62
|
<% end %>
|
87
63
|
|
64
|
+
### Extending a layout in a child layout (or view):
|
65
|
+
|
66
|
+
Any layout (or view) can declare that it wants to inherit from and extend a parent layout, in this case we're extending `app/views/layouts/application.html.erb`:
|
67
|
+
|
68
|
+
<%= extends :application do %>
|
69
|
+
...
|
70
|
+
<% end %>
|
71
|
+
|
72
|
+
You can nest many levels deep:
|
73
|
+
|
74
|
+
# app/views/layouts/application.html.erb
|
75
|
+
<!DOCTYPE html>
|
76
|
+
<html>
|
77
|
+
<head>
|
78
|
+
<%= area :head do %>
|
79
|
+
<title><%= area :title, 'Nestive' %></title>
|
80
|
+
<% end %>
|
81
|
+
</head>
|
82
|
+
<body>
|
83
|
+
<%= yield %>
|
84
|
+
</body>
|
85
|
+
</html>
|
86
|
+
|
87
|
+
# app/views/layouts/with_sidebar.html.erb
|
88
|
+
<%= extends :application do %>
|
89
|
+
<div class="sidebar"><%= area(:sidebar) do %>
|
90
|
+
here goes sidebar
|
91
|
+
<% end %></div>
|
92
|
+
<%= yield -%>
|
93
|
+
<% end %>
|
94
|
+
|
95
|
+
# app/views/layouts/blog_posts.html.erb
|
96
|
+
<%= extends :with_sidebar do %>
|
97
|
+
<% append :sidebar do %>
|
98
|
+
Blog archive:
|
99
|
+
<%= render_blog_archive %>
|
100
|
+
<% end %>
|
101
|
+
|
102
|
+
<% append :head do %>
|
103
|
+
<%= javascript_include_tag 'fancy_blog_archive_tag_cloud' %>
|
104
|
+
<% end %>
|
105
|
+
|
106
|
+
<%= yield %>
|
107
|
+
<% end %>
|
108
|
+
|
109
|
+
|
88
110
|
|
89
111
|
## The token blog example
|
90
112
|
|
91
|
-
Set-up a global layout defining some content areas.
|
92
|
-
|
113
|
+
Set-up a global layout defining some content areas.
|
114
|
+
|
93
115
|
# app/views/layouts/application.html.erb
|
94
116
|
<!DOCTYPE html>
|
95
117
|
<html>
|
96
118
|
<head>
|
97
119
|
<meta charset="utf-8">
|
98
|
-
<title><%= area :title
|
120
|
+
<title><%= area :title, "JustinFrench.com" %></title>
|
99
121
|
<meta name="description" content="<%= area :description, "This is my website." %>">
|
100
122
|
<meta name="keywords" content="<%= area :keywords, "justin, french, ruby, design" %>">
|
101
123
|
</head>
|
@@ -113,76 +135,49 @@ Set-up a global layout defining some content areas. Note that there is no `<% yi
|
|
113
135
|
<% end %>
|
114
136
|
</div>
|
115
137
|
</div>
|
138
|
+
<%= yield %>
|
116
139
|
</body>
|
117
140
|
</html>
|
118
|
-
|
141
|
+
|
119
142
|
Next, we set-up a `blog` layout that extends `application`, replacing, appending & prepending content to the areas we defined earlier.
|
120
|
-
|
143
|
+
|
121
144
|
# app/views/layouts/blog.html.erb
|
122
145
|
<%= extends :application do %>
|
123
146
|
<% replace :title, "My Blog – " %>
|
124
147
|
<% replace :description, "Justin French blogs here on Ruby, Rails, Design, Formtastic, etc" %>
|
125
148
|
<% prepend :keywords, "blog, weblog, design links, ruby links, formtastic release notes, " %>
|
149
|
+
<%= yield %>
|
126
150
|
<% end %>
|
127
151
|
|
128
|
-
Now our blog index view can
|
129
|
-
|
152
|
+
Now in our blog index view we can use `blog` layout and fill in the areas with content specific to the index action.
|
153
|
+
|
130
154
|
# app/views/posts/index.html.erb
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
<% render @articles %>
|
135
|
-
<% end %>
|
136
|
-
|
137
|
-
<% append :content do %>
|
138
|
-
<h2>Blog Roll</h2>
|
139
|
-
<% render @links %>
|
140
|
-
<% end %>
|
155
|
+
<% replace :content do %>
|
156
|
+
<h1>My Blog</h1>
|
157
|
+
<%= render @articles %>
|
141
158
|
<% end %>
|
142
|
-
|
143
|
-
We also need to instruct the `PostsController` not to wrap the view in a layout of it's own (default Rails behavior), which can be done on an individual action:
|
144
159
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
end
|
150
|
-
end
|
160
|
+
<% append :sidebar do %>
|
161
|
+
<h2>Blog Roll</h2>
|
162
|
+
<%= render @links %>
|
163
|
+
<% end %>
|
151
164
|
|
152
|
-
|
165
|
+
We also need to instruct the `PostsController` to use this `blog` layout:
|
153
166
|
|
154
167
|
# app/controllers/posts_controller.rb
|
155
168
|
class PostsController < ApplicationController
|
156
|
-
layout
|
169
|
+
layout 'blog'
|
157
170
|
end
|
158
|
-
|
159
|
-
Or for every controller:
|
160
|
-
|
161
|
-
# app/controllers/application_controller.rb
|
162
|
-
class ApplicationController < ActionController::Base
|
163
|
-
layout nil
|
164
|
-
end
|
165
|
-
|
166
|
-
We'll find a way to make this easier or a bit more obvious in a future version.
|
167
171
|
|
168
172
|
|
169
173
|
## Installation
|
170
174
|
|
171
|
-
* add `gem 'nestive', '~> 0.
|
175
|
+
* add `gem 'nestive', '~> 0.2'` to your gemfile
|
172
176
|
* run `bundle`
|
173
|
-
* add `layout nil` to ApplicationController or the specific controllers you want to use Nestive on (see above)
|
174
|
-
|
175
|
-
|
176
|
-
## TODO
|
177
|
-
|
178
|
-
* Figure out how to test it
|
179
|
-
* Actually use it in an app
|
180
|
-
* You know, everything!
|
181
|
-
|
182
177
|
|
183
178
|
## Compatibility
|
184
179
|
|
185
|
-
|
180
|
+
Nestive should work properly with any Rails 3.*. It should probably work with 2.* too, but we don't have test coverage for this.
|
186
181
|
|
187
182
|
*Nestive doesn't monkey patch or fiddle with any default behaviors in Rails.* Use it when you want to, don't when you don't.
|
188
183
|
|
@@ -195,5 +190,5 @@ Only testing it with Rails 3.1 RCs right now, but it should work with Rails 2 &
|
|
195
190
|
|
196
191
|
## Twitter
|
197
192
|
|
198
|
-
* [@
|
199
|
-
* [@justinfrench](http://twitter.com/justinfrench)
|
193
|
+
* [@rwz](https://twitter.com/rwz) — current maintainer
|
194
|
+
* [@justinfrench](http://twitter.com/justinfrench) — author
|
data/Rakefile
CHANGED
@@ -1,21 +1,15 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
require '
|
2
|
+
require 'rspec/core/rake_task'
|
3
3
|
require 'rdoc/task'
|
4
4
|
|
5
5
|
require 'bundler'
|
6
6
|
Bundler::GemHelper.install_tasks
|
7
7
|
|
8
8
|
|
9
|
-
|
10
|
-
task :default => :test
|
9
|
+
task :default => :spec
|
11
10
|
|
12
|
-
desc '
|
13
|
-
|
14
|
-
t.libs << 'lib'
|
15
|
-
t.libs << 'test'
|
16
|
-
t.pattern = 'test/**/*_test.rb'
|
17
|
-
t.verbose = true
|
18
|
-
end
|
11
|
+
desc 'Run specs'
|
12
|
+
RSpec::Core::RakeTask.new
|
19
13
|
|
20
14
|
desc 'Generate documentation for the nestive plugin.'
|
21
15
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Nestive
|
2
|
-
|
2
|
+
|
3
3
|
# The Nestive LayoutHelper provides a handful of helper methods for use in your layouts and views.
|
4
4
|
#
|
5
|
-
# See the documentation for each individual method for detailed information, but at a high level,
|
6
|
-
# your parent layouts define `area`s of content. You can define an area and optionally add content
|
5
|
+
# See the documentation for each individual method for detailed information, but at a high level,
|
6
|
+
# your parent layouts define `area`s of content. You can define an area and optionally add content
|
7
7
|
# to it at the same time using either a String, or a block:
|
8
8
|
#
|
9
9
|
# # app/views/layouts/global.html.erb
|
@@ -24,11 +24,11 @@ module Nestive
|
|
24
24
|
# </body>
|
25
25
|
# </html>
|
26
26
|
#
|
27
|
-
# Your child layouts (or views) inherit and modify the parent by wrapping in an `
|
28
|
-
# helper. You can then either `append`, `prepend` or `replace` the content that has previously
|
27
|
+
# Your child layouts (or views) inherit and modify the parent by wrapping in an `extends` block
|
28
|
+
# helper. You can then either `append`, `prepend` or `replace` the content that has previously
|
29
29
|
# been assigned to each area by parent layouts.
|
30
30
|
#
|
31
|
-
# The `append`, `prepend` or `replace` helpers are *similar* to Rails' own `content_for`, which
|
31
|
+
# The `append`, `prepend` or `replace` helpers are *similar* to Rails' own `content_for`, which
|
32
32
|
# accepts content for the named area with either a String or with a block). They're different to
|
33
33
|
# `content_for` because they're only used modify the content assigned to the area, not retrieve it:
|
34
34
|
#
|
@@ -51,7 +51,7 @@ module Nestive
|
|
51
51
|
# <% end %>
|
52
52
|
# <% end %>
|
53
53
|
module LayoutHelper
|
54
|
-
|
54
|
+
|
55
55
|
# Declares that the current layour (or view) is inheriting from and extending another layout.
|
56
56
|
#
|
57
57
|
# @param [Symbol] name
|
@@ -70,10 +70,10 @@ module Nestive
|
|
70
70
|
# class Admin::PostsController < ApplicationController
|
71
71
|
# # You can disable Rails' layout rendering for all actions
|
72
72
|
# layout nil
|
73
|
-
#
|
73
|
+
#
|
74
74
|
# # Or disable Rails' layout rendering per-controller
|
75
75
|
# def index
|
76
|
-
# render :layout => nil
|
76
|
+
# render :layout => nil
|
77
77
|
# end
|
78
78
|
# end
|
79
79
|
#
|
@@ -81,12 +81,20 @@ module Nestive
|
|
81
81
|
# <%= extends :admin do %>
|
82
82
|
# ...
|
83
83
|
# <% end %>
|
84
|
-
def extends(
|
85
|
-
|
86
|
-
|
84
|
+
def extends(layout, &block)
|
85
|
+
# Make sure it's a string
|
86
|
+
layout = layout.to_s
|
87
|
+
|
88
|
+
# If there's no directory component, presume a plain layout name
|
89
|
+
layout = layout.include?('/') ? layout : "layouts/#{layout}"
|
90
|
+
|
91
|
+
# Capture the content to be placed inside the extended layout
|
92
|
+
content_for(:layout).replace capture(&block)
|
93
|
+
|
94
|
+
render :file => layout
|
87
95
|
end
|
88
|
-
|
89
|
-
# Defines an area of content in your layout that can be modified or replaced by child layouts
|
96
|
+
|
97
|
+
# Defines an area of content in your layout that can be modified or replaced by child layouts
|
90
98
|
# that extend it. You can optionally add content to an area using either a String, or a block.
|
91
99
|
#
|
92
100
|
# Areas are declared in a parent layout and modified by a child layout, but since Nestive
|
@@ -121,13 +129,13 @@ module Nestive
|
|
121
129
|
append(name, content)
|
122
130
|
render_area(name)
|
123
131
|
end
|
124
|
-
|
132
|
+
|
125
133
|
def block(name, content=nil, &block)
|
126
134
|
ActiveSupport::Deprecation.warn("block() is deprecated and will be removed very soon, please use area() instead")
|
127
135
|
area(name, content, &block)
|
128
136
|
end
|
129
|
-
|
130
|
-
# Appends content to an area previously defined or modified in parent layout(s). You can provide
|
137
|
+
|
138
|
+
# Appends content to an area previously defined or modified in parent layout(s). You can provide
|
131
139
|
# the content using either a String, or a block.
|
132
140
|
#
|
133
141
|
# @example Appending content with a String
|
@@ -146,9 +154,10 @@ module Nestive
|
|
146
154
|
def append(name, content=nil, &block)
|
147
155
|
content = capture(&block) if block_given?
|
148
156
|
add_instruction_to_area(name, :push, content)
|
157
|
+
nil
|
149
158
|
end
|
150
159
|
|
151
|
-
# Prepends content to an area previously declared or modified in parent layout(s). You can
|
160
|
+
# Prepends content to an area previously declared or modified in parent layout(s). You can
|
152
161
|
# provide the content using either a String, or a block.
|
153
162
|
#
|
154
163
|
# @example Prepending content with a String
|
@@ -167,9 +176,10 @@ module Nestive
|
|
167
176
|
def prepend(name, content=nil, &block)
|
168
177
|
content = capture(&block) if block_given?
|
169
178
|
add_instruction_to_area(name, :unshift, content)
|
179
|
+
nil
|
170
180
|
end
|
171
|
-
|
172
|
-
# Replaces the content of an area previously declared or modified in parent layout(s). You can
|
181
|
+
|
182
|
+
# Replaces the content of an area previously declared or modified in parent layout(s). You can
|
173
183
|
# provide the content using either a String, or a block.
|
174
184
|
#
|
175
185
|
# @example Prepending content with a String
|
@@ -188,20 +198,21 @@ module Nestive
|
|
188
198
|
def replace(name, content=nil, &block)
|
189
199
|
content = capture(&block) if block_given?
|
190
200
|
add_instruction_to_area(name, :replace, [content])
|
201
|
+
nil
|
191
202
|
end
|
192
|
-
|
203
|
+
|
193
204
|
private
|
194
|
-
|
205
|
+
|
195
206
|
# We record the instructions (declaring, appending, prepending and replacing) for an area of
|
196
207
|
# content into an array that we can later retrieve and replay. Instructions are stored in an
|
197
|
-
# instance variable Hash `@_area_for`, with each key representing an area name, and each value
|
198
|
-
# an Array of instructions. Each instruction is a two element array containing a instruction
|
208
|
+
# instance variable Hash `@_area_for`, with each key representing an area name, and each value
|
209
|
+
# an Array of instructions. Each instruction is a two element array containing a instruction
|
199
210
|
# method (eg `:push`, `:unshift`, `:replace`) and a value (content String).
|
200
211
|
#
|
201
212
|
# @_area_for[:sidebar] # => [ [:push,"World"], [:unshift,"Hello"] ]
|
202
213
|
#
|
203
214
|
# Due to the way we extend layouts (render the parent layout after the child), the instructions
|
204
|
-
# are captured in reverse order. `render_area` reversed them and plays them back at rendering
|
215
|
+
# are captured in reverse order. `render_area` reversed them and plays them back at rendering
|
205
216
|
# time.
|
206
217
|
#
|
207
218
|
# @example
|
@@ -211,12 +222,12 @@ module Nestive
|
|
211
222
|
@_area_for[name] ||= []
|
212
223
|
@_area_for[name] << [instruction, value]
|
213
224
|
end
|
214
|
-
|
225
|
+
|
215
226
|
# Take the instructions we've gathered for the area and replay them one after the other on
|
216
227
|
# an empty array. These instructions will push, unshift or replace items into our output array,
|
217
228
|
# which we then join and mark as html_safe.
|
218
229
|
#
|
219
|
-
# These instructions are reversed and replayed when we render the block (rather than as they
|
230
|
+
# These instructions are reversed and replayed when we render the block (rather than as they
|
220
231
|
# happen) due to the way they are gathered by the layout extension process (in reverse).
|
221
232
|
#
|
222
233
|
# @todo is `html_safe` "safe" here?
|
@@ -229,4 +240,4 @@ module Nestive
|
|
229
240
|
end
|
230
241
|
|
231
242
|
end
|
232
|
-
end
|
243
|
+
end
|
data/config.ru
ADDED
data/lib/nestive/version.rb
CHANGED
data/nestive.gemspec
CHANGED
@@ -1,23 +1,26 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path(
|
3
|
-
require
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'nestive/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "nestive"
|
7
7
|
s.version = Nestive::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = [
|
10
|
-
s.email = [
|
11
|
-
s.homepage =
|
12
|
-
s.summary =
|
13
|
-
s.description =
|
9
|
+
s.authors = ['Justin French', 'Pavel Pravosud']
|
10
|
+
s.email = ['justin@indent.com.au', 'pavel@pravosud.com']
|
11
|
+
s.homepage = 'https://github.com/rwz/nestive'
|
12
|
+
s.summary = 'A Rails plugin/gem for awesome nested templates and layouts'
|
13
|
+
s.description = 'A Rails plugin/gem for awesome nested templates and layouts'
|
14
14
|
|
15
|
-
s.rubyforge_project =
|
15
|
+
s.rubyforge_project = 'nestive'
|
16
16
|
|
17
17
|
s.files = `git ls-files`.split("\n")
|
18
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
-
s.require_paths = [
|
21
|
-
|
22
|
-
s.add_dependency
|
20
|
+
s.require_paths = ['lib']
|
21
|
+
|
22
|
+
s.add_dependency 'rails', '~> 3.0'
|
23
|
+
s.add_development_dependency 'combustion', '~> 0.3.2'
|
24
|
+
s.add_development_dependency 'rspec-rails', '~> 2.11'
|
25
|
+
|
23
26
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NestiveController do
|
4
|
+
render_views
|
5
|
+
|
6
|
+
context '#area' do
|
7
|
+
it 'is empty by default' do
|
8
|
+
get :index
|
9
|
+
assert_select '#empty-area', ''
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'shows initial value if any' do
|
13
|
+
get :index
|
14
|
+
assert_select 'title', 'Nestive'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'can accept blocks as initial value' do
|
18
|
+
get :index
|
19
|
+
assert_select '#some-area', 'Some content'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context '#append' do
|
24
|
+
it 'appends content to area as a string' do
|
25
|
+
get :append
|
26
|
+
assert_select 'title', 'Nestive is awesome'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'appends content to area as a block' do
|
30
|
+
get :append
|
31
|
+
assert_select '#some-area', "Some content\n Another content"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context '#prepend' do
|
36
|
+
it 'prepends content to area as a string' do
|
37
|
+
get :prepend
|
38
|
+
assert_select 'title', 'Awesome Nestive'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'prepends content to area as a block' do
|
42
|
+
get :prepend
|
43
|
+
assert_select '#some-area', "Prepended\n Some content"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context '#replace' do
|
48
|
+
it 'replaces area content with string' do
|
49
|
+
get :replace
|
50
|
+
assert_select 'title', 'Lolwut'
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'replaces area content with block' do
|
54
|
+
get :replace
|
55
|
+
assert_select '#some-area', 'replaced'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context '#extends' do
|
60
|
+
it 'extends layouts' do
|
61
|
+
get :extended_one
|
62
|
+
assert_select 'p', 'extended: one'
|
63
|
+
assert_select 'title', 'extended: one'
|
64
|
+
assert_select 'h2', 'extended: one'
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'can extend already extended layouts' do
|
68
|
+
get :extended_two
|
69
|
+
assert_select 'p', 'extended: two'
|
70
|
+
assert_select 'title', 'extended: one'
|
71
|
+
assert_select '#some-area', 'extended: two'
|
72
|
+
assert_select 'h2', 'extended: one'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title><%= area :title, 'Nestive' %></title>
|
5
|
+
</head>
|
6
|
+
<body>
|
7
|
+
<%= yield %>
|
8
|
+
<div id="some-area">
|
9
|
+
<%= area :some_area do -%>
|
10
|
+
Some content
|
11
|
+
<%- end -%>
|
12
|
+
</div>
|
13
|
+
<div id="empty-area"><%= area :empty_area %></div>
|
14
|
+
</body>
|
15
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
<p>extended: one</p>
|
@@ -0,0 +1 @@
|
|
1
|
+
<p>extended: two</p>
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>Hello World</h1>
|
@@ -0,0 +1 @@
|
|
1
|
+
*.log
|
File without changes
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,49 +1,75 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: nestive
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 0.1.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Justin French
|
9
|
+
- Pavel Pravosud
|
14
10
|
autorequire:
|
15
11
|
bindir: bin
|
16
12
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
13
|
+
date: 2012-11-10 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
22
16
|
name: rails
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
25
18
|
none: false
|
26
|
-
requirements:
|
19
|
+
requirements:
|
27
20
|
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 3
|
32
|
-
- 0
|
33
|
-
version: "3.0"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3.0'
|
34
23
|
type: :runtime
|
35
|
-
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '3.0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: combustion
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 0.3.2
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.3.2
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec-rails
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.11'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '2.11'
|
36
63
|
description: A Rails plugin/gem for awesome nested templates and layouts
|
37
|
-
email:
|
64
|
+
email:
|
38
65
|
- justin@indent.com.au
|
66
|
+
- pavel@pravosud.com
|
39
67
|
executables: []
|
40
|
-
|
41
68
|
extensions: []
|
42
|
-
|
43
69
|
extra_rdoc_files: []
|
44
|
-
|
45
|
-
files:
|
70
|
+
files:
|
46
71
|
- .gitignore
|
72
|
+
- .travis.yml
|
47
73
|
- .yardopts
|
48
74
|
- Gemfile
|
49
75
|
- Gemfile.lock
|
@@ -51,6 +77,7 @@ files:
|
|
51
77
|
- README.md
|
52
78
|
- Rakefile
|
53
79
|
- app/helpers/nestive/layout_helper.rb
|
80
|
+
- config.ru
|
54
81
|
- init.rb
|
55
82
|
- install.rb
|
56
83
|
- lib/nestive.rb
|
@@ -58,43 +85,63 @@ files:
|
|
58
85
|
- lib/nestive/railtie.rb
|
59
86
|
- lib/nestive/version.rb
|
60
87
|
- nestive.gemspec
|
61
|
-
-
|
62
|
-
-
|
88
|
+
- spec/controllers/nestive_spec.rb
|
89
|
+
- spec/internal/app/controllers/application_controller.rb
|
90
|
+
- spec/internal/app/controllers/nestive_controller.rb
|
91
|
+
- spec/internal/app/views/layouts/extend_one.html.erb
|
92
|
+
- spec/internal/app/views/layouts/extend_two.html.erb
|
93
|
+
- spec/internal/app/views/layouts/nestive.html.erb
|
94
|
+
- spec/internal/app/views/nestive/append.html.erb
|
95
|
+
- spec/internal/app/views/nestive/extended_one.html.erb
|
96
|
+
- spec/internal/app/views/nestive/extended_two.html.erb
|
97
|
+
- spec/internal/app/views/nestive/index.html.erb
|
98
|
+
- spec/internal/app/views/nestive/prepend.html.erb
|
99
|
+
- spec/internal/app/views/nestive/replace.html.erb
|
100
|
+
- spec/internal/config/routes.rb
|
101
|
+
- spec/internal/db/schema.rb
|
102
|
+
- spec/internal/log/.gitignore
|
103
|
+
- spec/internal/public/favicon.ico
|
104
|
+
- spec/spec_helper.rb
|
63
105
|
- uninstall.rb
|
64
|
-
|
65
|
-
homepage: ""
|
106
|
+
homepage: https://github.com/rwz/nestive
|
66
107
|
licenses: []
|
67
|
-
|
68
108
|
post_install_message:
|
69
109
|
rdoc_options: []
|
70
|
-
|
71
|
-
require_paths:
|
110
|
+
require_paths:
|
72
111
|
- lib
|
73
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
113
|
none: false
|
75
|
-
requirements:
|
76
|
-
- -
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
|
79
|
-
|
80
|
-
- 0
|
81
|
-
version: "0"
|
82
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
119
|
none: false
|
84
|
-
requirements:
|
85
|
-
- -
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
|
88
|
-
segments:
|
89
|
-
- 0
|
90
|
-
version: "0"
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
91
124
|
requirements: []
|
92
|
-
|
93
125
|
rubyforge_project: nestive
|
94
|
-
rubygems_version: 1.
|
126
|
+
rubygems_version: 1.8.24
|
95
127
|
signing_key:
|
96
128
|
specification_version: 3
|
97
129
|
summary: A Rails plugin/gem for awesome nested templates and layouts
|
98
|
-
test_files:
|
99
|
-
-
|
100
|
-
-
|
130
|
+
test_files:
|
131
|
+
- spec/controllers/nestive_spec.rb
|
132
|
+
- spec/internal/app/controllers/application_controller.rb
|
133
|
+
- spec/internal/app/controllers/nestive_controller.rb
|
134
|
+
- spec/internal/app/views/layouts/extend_one.html.erb
|
135
|
+
- spec/internal/app/views/layouts/extend_two.html.erb
|
136
|
+
- spec/internal/app/views/layouts/nestive.html.erb
|
137
|
+
- spec/internal/app/views/nestive/append.html.erb
|
138
|
+
- spec/internal/app/views/nestive/extended_one.html.erb
|
139
|
+
- spec/internal/app/views/nestive/extended_two.html.erb
|
140
|
+
- spec/internal/app/views/nestive/index.html.erb
|
141
|
+
- spec/internal/app/views/nestive/prepend.html.erb
|
142
|
+
- spec/internal/app/views/nestive/replace.html.erb
|
143
|
+
- spec/internal/config/routes.rb
|
144
|
+
- spec/internal/db/schema.rb
|
145
|
+
- spec/internal/log/.gitignore
|
146
|
+
- spec/internal/public/favicon.ico
|
147
|
+
- spec/spec_helper.rb
|
data/test/nestive_test.rb
DELETED
data/test/test_helper.rb
DELETED