cells 3.8.8 → 3.9.0
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.
- checksums.yaml +7 -0
- data/.gitignore +2 -1
- data/.travis.yml +5 -2
- data/CHANGES.textile +23 -15
- data/Gemfile +1 -1
- data/README.md +412 -0
- data/Rakefile +2 -2
- data/cells.gemspec +5 -6
- data/gemfiles/Gemfile.rails3-0 +2 -2
- data/gemfiles/Gemfile.rails3-1 +1 -1
- data/gemfiles/Gemfile.rails3-2 +1 -2
- data/gemfiles/Gemfile.rails4-0 +7 -0
- data/lib/cell.rb +27 -0
- data/lib/cell/base.rb +31 -18
- data/lib/cell/builder.rb +11 -10
- data/lib/cell/dsl.rb +7 -0
- data/lib/cell/rack.rb +5 -9
- data/lib/cell/rails.rb +19 -11
- data/lib/cell/rails/view_model.rb +115 -0
- data/lib/cell/rails3_0_strategy.rb +1 -1
- data/lib/cell/rails3_1_strategy.rb +1 -1
- data/lib/cell/rails4_0_strategy.rb +1 -2
- data/lib/cell/test_case.rb +11 -11
- data/lib/cells.rb +4 -3
- data/lib/cells/rails.rb +16 -3
- data/lib/cells/version.rb +1 -1
- data/test/app/cells/bassist_cell.rb +9 -1
- data/test/app/cells/rails_helper_api_test/bassist/edit.html.erb +3 -3
- data/test/app/cells/song/dashboard.haml +7 -0
- data/test/app/cells/song/details.html.haml +1 -0
- data/test/app/cells/song/info.html.haml +1 -0
- data/test/app/cells/song/lyrics.html.haml +6 -0
- data/test/app/cells/song/plays.haml +1 -0
- data/test/app/cells/song/show.html.haml +3 -0
- data/test/app/cells/song/title.html.haml +1 -0
- data/test/app/cells/view_model_test/comments/show.haml +7 -0
- data/test/cell_module_test.rb +39 -41
- data/test/cell_test.rb +28 -0
- data/test/dummy/app/views/musician/featured_with_block.html.erb +1 -1
- data/test/dummy/app/views/musician/title.erb +1 -0
- data/test/dummy/config/routes.rb +1 -0
- data/test/helper_test.rb +13 -10
- data/test/rails/caching_test.rb +75 -73
- data/test/rails/cells_test.rb +25 -23
- data/test/rails/integration_test.rb +80 -61
- data/test/rails/view_model_test.rb +119 -0
- data/test/rails_helper_api_test.rb +11 -13
- metadata +41 -61
- data/README.rdoc +0 -279
- data/about.yml +0 -7
- data/test/app/cells/producer/capture.html.erb +0 -1
- data/test/app/cells/producer/content_for.html.erb +0 -2
- data/test/rails/capture_test.rb +0 -70
metadata
CHANGED
|
@@ -1,144 +1,113 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cells
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 3.9.0
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- Nick Sutterer
|
|
9
8
|
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date: 2013-
|
|
11
|
+
date: 2013-10-22 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
14
|
name: actionpack
|
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
|
17
|
-
none: false
|
|
18
16
|
requirements:
|
|
19
|
-
- -
|
|
17
|
+
- - '>='
|
|
20
18
|
- !ruby/object:Gem::Version
|
|
21
19
|
version: '3.0'
|
|
22
20
|
type: :runtime
|
|
23
21
|
prerelease: false
|
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
-
none: false
|
|
26
23
|
requirements:
|
|
27
|
-
- -
|
|
24
|
+
- - '>='
|
|
28
25
|
- !ruby/object:Gem::Version
|
|
29
26
|
version: '3.0'
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
|
31
28
|
name: railties
|
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
|
33
|
-
none: false
|
|
34
30
|
requirements:
|
|
35
|
-
- -
|
|
31
|
+
- - '>='
|
|
36
32
|
- !ruby/object:Gem::Version
|
|
37
33
|
version: '3.0'
|
|
38
34
|
type: :runtime
|
|
39
35
|
prerelease: false
|
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
-
none: false
|
|
42
37
|
requirements:
|
|
43
|
-
- -
|
|
38
|
+
- - '>='
|
|
44
39
|
- !ruby/object:Gem::Version
|
|
45
40
|
version: '3.0'
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
|
47
42
|
name: rake
|
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
|
49
|
-
none: false
|
|
50
44
|
requirements:
|
|
51
|
-
- -
|
|
45
|
+
- - '>='
|
|
52
46
|
- !ruby/object:Gem::Version
|
|
53
47
|
version: '0'
|
|
54
48
|
type: :development
|
|
55
49
|
prerelease: false
|
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
-
none: false
|
|
58
51
|
requirements:
|
|
59
|
-
- -
|
|
52
|
+
- - '>='
|
|
60
53
|
- !ruby/object:Gem::Version
|
|
61
54
|
version: '0'
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
|
63
56
|
name: haml
|
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
|
65
|
-
none: false
|
|
66
58
|
requirements:
|
|
67
|
-
- -
|
|
59
|
+
- - '>='
|
|
68
60
|
- !ruby/object:Gem::Version
|
|
69
61
|
version: '0'
|
|
70
62
|
type: :development
|
|
71
63
|
prerelease: false
|
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
-
none: false
|
|
74
65
|
requirements:
|
|
75
|
-
- -
|
|
66
|
+
- - '>='
|
|
76
67
|
- !ruby/object:Gem::Version
|
|
77
68
|
version: '0'
|
|
78
69
|
- !ruby/object:Gem::Dependency
|
|
79
70
|
name: slim
|
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
|
81
|
-
none: false
|
|
82
72
|
requirements:
|
|
83
|
-
- -
|
|
73
|
+
- - '>='
|
|
84
74
|
- !ruby/object:Gem::Version
|
|
85
75
|
version: '0'
|
|
86
76
|
type: :development
|
|
87
77
|
prerelease: false
|
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
89
|
-
none: false
|
|
90
79
|
requirements:
|
|
91
|
-
- -
|
|
92
|
-
- !ruby/object:Gem::Version
|
|
93
|
-
version: '0'
|
|
94
|
-
- !ruby/object:Gem::Dependency
|
|
95
|
-
name: simple_form
|
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
|
97
|
-
none: false
|
|
98
|
-
requirements:
|
|
99
|
-
- - ! '>='
|
|
100
|
-
- !ruby/object:Gem::Version
|
|
101
|
-
version: '0'
|
|
102
|
-
type: :development
|
|
103
|
-
prerelease: false
|
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
105
|
-
none: false
|
|
106
|
-
requirements:
|
|
107
|
-
- - ! '>='
|
|
80
|
+
- - '>='
|
|
108
81
|
- !ruby/object:Gem::Version
|
|
109
82
|
version: '0'
|
|
110
83
|
- !ruby/object:Gem::Dependency
|
|
111
84
|
name: tzinfo
|
|
112
85
|
requirement: !ruby/object:Gem::Requirement
|
|
113
|
-
none: false
|
|
114
86
|
requirements:
|
|
115
|
-
- -
|
|
87
|
+
- - '>='
|
|
116
88
|
- !ruby/object:Gem::Version
|
|
117
89
|
version: '0'
|
|
118
90
|
type: :development
|
|
119
91
|
prerelease: false
|
|
120
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
-
none: false
|
|
122
93
|
requirements:
|
|
123
|
-
- -
|
|
94
|
+
- - '>='
|
|
124
95
|
- !ruby/object:Gem::Version
|
|
125
96
|
version: '0'
|
|
126
97
|
- !ruby/object:Gem::Dependency
|
|
127
98
|
name: minitest
|
|
128
99
|
requirement: !ruby/object:Gem::Requirement
|
|
129
|
-
none: false
|
|
130
100
|
requirements:
|
|
131
|
-
- -
|
|
101
|
+
- - ~>
|
|
132
102
|
- !ruby/object:Gem::Version
|
|
133
|
-
version:
|
|
103
|
+
version: 4.7.5
|
|
134
104
|
type: :development
|
|
135
105
|
prerelease: false
|
|
136
106
|
version_requirements: !ruby/object:Gem::Requirement
|
|
137
|
-
none: false
|
|
138
107
|
requirements:
|
|
139
|
-
- -
|
|
108
|
+
- - ~>
|
|
140
109
|
- !ruby/object:Gem::Version
|
|
141
|
-
version:
|
|
110
|
+
version: 4.7.5
|
|
142
111
|
description: Cells are view components for Rails. They are lightweight controllers,
|
|
143
112
|
can be rendered in views and thus provide an elegant and fast way for encapsulation
|
|
144
113
|
and component-orientation.
|
|
@@ -152,20 +121,23 @@ files:
|
|
|
152
121
|
- .travis.yml
|
|
153
122
|
- CHANGES.textile
|
|
154
123
|
- Gemfile
|
|
155
|
-
- README.
|
|
124
|
+
- README.md
|
|
156
125
|
- Rakefile
|
|
157
|
-
- about.yml
|
|
158
126
|
- cells.gemspec
|
|
159
127
|
- gemfiles/Gemfile.rails3-0
|
|
160
128
|
- gemfiles/Gemfile.rails3-1
|
|
161
129
|
- gemfiles/Gemfile.rails3-2
|
|
130
|
+
- gemfiles/Gemfile.rails4-0
|
|
131
|
+
- lib/cell.rb
|
|
162
132
|
- lib/cell/base.rb
|
|
163
133
|
- lib/cell/builder.rb
|
|
164
134
|
- lib/cell/caching.rb
|
|
165
135
|
- lib/cell/deprecations.rb
|
|
136
|
+
- lib/cell/dsl.rb
|
|
166
137
|
- lib/cell/rack.rb
|
|
167
138
|
- lib/cell/rails.rb
|
|
168
139
|
- lib/cell/rails/helper_api.rb
|
|
140
|
+
- lib/cell/rails/view_model.rb
|
|
169
141
|
- lib/cell/rails3_0_strategy.rb
|
|
170
142
|
- lib/cell/rails3_1_strategy.rb
|
|
171
143
|
- lib/cell/rails4_0_strategy.rb
|
|
@@ -215,15 +187,22 @@ files:
|
|
|
215
187
|
- test/app/cells/club_security/medic_cell.rb
|
|
216
188
|
- test/app/cells/layouts/b.erb
|
|
217
189
|
- test/app/cells/layouts/metal.html.erb
|
|
218
|
-
- test/app/cells/producer/capture.html.erb
|
|
219
|
-
- test/app/cells/producer/content_for.html.erb
|
|
220
190
|
- test/app/cells/rails_helper_api_test/bassist/edit.html.erb
|
|
221
191
|
- test/app/cells/shouter/sing.html.erb
|
|
192
|
+
- test/app/cells/song/dashboard.haml
|
|
193
|
+
- test/app/cells/song/details.html.haml
|
|
194
|
+
- test/app/cells/song/info.html.haml
|
|
195
|
+
- test/app/cells/song/lyrics.html.haml
|
|
196
|
+
- test/app/cells/song/plays.haml
|
|
197
|
+
- test/app/cells/song/show.html.haml
|
|
198
|
+
- test/app/cells/song/title.html.haml
|
|
222
199
|
- test/app/cells/trumpeter/promote.html.erb
|
|
223
200
|
- test/app/cells/trumpeter_cell.rb
|
|
201
|
+
- test/app/cells/view_model_test/comments/show.haml
|
|
224
202
|
- test/app/views/shared/_dong.html.erb
|
|
225
203
|
- test/cell_generator_test.rb
|
|
226
204
|
- test/cell_module_test.rb
|
|
205
|
+
- test/cell_test.rb
|
|
227
206
|
- test/cells_module_test.rb
|
|
228
207
|
- test/deprecations_test.rb
|
|
229
208
|
- test/dummy/Rakefile
|
|
@@ -234,6 +213,7 @@ files:
|
|
|
234
213
|
- test/dummy/app/views/musician/featured.html.erb
|
|
235
214
|
- test/dummy/app/views/musician/featured_with_block.html.erb
|
|
236
215
|
- test/dummy/app/views/musician/hamlet.html.haml
|
|
216
|
+
- test/dummy/app/views/musician/title.erb
|
|
237
217
|
- test/dummy/config.ru
|
|
238
218
|
- test/dummy/config/application.rb
|
|
239
219
|
- test/dummy/config/boot.rb
|
|
@@ -256,37 +236,37 @@ files:
|
|
|
256
236
|
- test/helper_test.rb
|
|
257
237
|
- test/rack_test.rb
|
|
258
238
|
- test/rails/caching_test.rb
|
|
259
|
-
- test/rails/capture_test.rb
|
|
260
239
|
- test/rails/cells_test.rb
|
|
261
240
|
- test/rails/integration_test.rb
|
|
262
241
|
- test/rails/render_test.rb
|
|
263
242
|
- test/rails/router_test.rb
|
|
243
|
+
- test/rails/view_model_test.rb
|
|
264
244
|
- test/rails/view_test.rb
|
|
265
245
|
- test/rails_helper_api_test.rb
|
|
266
246
|
- test/test_case_test.rb
|
|
267
247
|
- test/test_helper.rb
|
|
268
248
|
homepage: http://cells.rubyforge.org
|
|
269
|
-
licenses:
|
|
249
|
+
licenses:
|
|
250
|
+
- MIT
|
|
251
|
+
metadata: {}
|
|
270
252
|
post_install_message:
|
|
271
253
|
rdoc_options: []
|
|
272
254
|
require_paths:
|
|
273
255
|
- lib
|
|
274
256
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
275
|
-
none: false
|
|
276
257
|
requirements:
|
|
277
|
-
- -
|
|
258
|
+
- - '>='
|
|
278
259
|
- !ruby/object:Gem::Version
|
|
279
260
|
version: '0'
|
|
280
261
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
281
|
-
none: false
|
|
282
262
|
requirements:
|
|
283
|
-
- -
|
|
263
|
+
- - '>='
|
|
284
264
|
- !ruby/object:Gem::Version
|
|
285
265
|
version: '0'
|
|
286
266
|
requirements: []
|
|
287
267
|
rubyforge_project:
|
|
288
|
-
rubygems_version:
|
|
268
|
+
rubygems_version: 2.0.3
|
|
289
269
|
signing_key:
|
|
290
|
-
specification_version:
|
|
270
|
+
specification_version: 4
|
|
291
271
|
summary: View Components for Rails.
|
|
292
272
|
test_files: []
|
data/README.rdoc
DELETED
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
= Cells
|
|
2
|
-
|
|
3
|
-
<em>View Components for Rails.</em>
|
|
4
|
-
|
|
5
|
-
{<img src="https://secure.travis-ci.org/apotonick/cells.png" />}[http://travis-ci.org/apotonick/cells]
|
|
6
|
-
|
|
7
|
-
== Overview
|
|
8
|
-
|
|
9
|
-
Say you're writing a Rails online shop - the shopping cart is reappearing again and again in every view. You're thinking about a clean solution for that part. A mixture of controller code, before-filters, partials and helpers?
|
|
10
|
-
|
|
11
|
-
No. That sucks. Take Cells.
|
|
12
|
-
|
|
13
|
-
Cells are View Components for Rails. They look and feel like controllers. They don't have no +DoubleRenderError+. They can be rendered everywhere in your controllers or views. They are cacheable, testable, fast and wonderful. They bring back OOP to your view and improve your software design.
|
|
14
|
-
|
|
15
|
-
And the best: You can have as many cells in your page as you need!
|
|
16
|
-
|
|
17
|
-
== Installation
|
|
18
|
-
|
|
19
|
-
It's a gem!
|
|
20
|
-
|
|
21
|
-
Rails >= 3.0:
|
|
22
|
-
|
|
23
|
-
gem install cells
|
|
24
|
-
|
|
25
|
-
Rails 2.3:
|
|
26
|
-
|
|
27
|
-
gem install cells -v 3.3.9
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
== Generate
|
|
31
|
-
|
|
32
|
-
Creating a cell is nothing more than
|
|
33
|
-
|
|
34
|
-
$ rails generate cell cart show -e haml
|
|
35
|
-
create app/cells/
|
|
36
|
-
create app/cells/cart
|
|
37
|
-
create app/cells/cart_cell.rb
|
|
38
|
-
create app/cells/cart/show.html.haml
|
|
39
|
-
create test/cells/cart_test.rb
|
|
40
|
-
|
|
41
|
-
That looks very familiar.
|
|
42
|
-
|
|
43
|
-
== Render the cell
|
|
44
|
-
|
|
45
|
-
Now, render your cart. Why not put it in <tt>layouts/application.html.erb</tt> for now?
|
|
46
|
-
|
|
47
|
-
<div id="header">
|
|
48
|
-
<%= render_cell :cart, :show, :user => @current_user %>
|
|
49
|
-
|
|
50
|
-
Feels like rendering a controller action. For good encapsulation we pass the current +user+ from outside into the cell - a dependency injection.
|
|
51
|
-
|
|
52
|
-
== Code
|
|
53
|
-
|
|
54
|
-
Time to improve our cell code. Let's start with <tt>app/cells/cart_cell.rb</tt>:
|
|
55
|
-
|
|
56
|
-
class CartCell < Cell::Rails
|
|
57
|
-
def show(args)
|
|
58
|
-
user = args[:user]
|
|
59
|
-
@items = user.items_in_cart
|
|
60
|
-
|
|
61
|
-
render # renders show.html.haml
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
Is that a controller? Hell, yeah. We even got a +#render+ method as we know it from the good ol' +ActionController+.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
== Views
|
|
69
|
-
|
|
70
|
-
Since a plain call to +#render+ will start rendering <tt>app/cells/cart/show.html.haml</tt> we should put some meaningful markup there.
|
|
71
|
-
|
|
72
|
-
#cart
|
|
73
|
-
You have #{@items.size} items in your shopping cart.
|
|
74
|
-
|
|
75
|
-
=== ERB? Haml? Builder?
|
|
76
|
-
|
|
77
|
-
Yes, Cells support all template types that are supported by Rails itself. Remember- it's a controller!
|
|
78
|
-
|
|
79
|
-
=== Helpers
|
|
80
|
-
|
|
81
|
-
Yes, Cells have helpers just like controllers. If you need some specific helper, do
|
|
82
|
-
|
|
83
|
-
class CartCell < Cell::Rails
|
|
84
|
-
helper MyExtraHelper
|
|
85
|
-
|
|
86
|
-
and it will be around in your cart views.
|
|
87
|
-
|
|
88
|
-
=== Partials?
|
|
89
|
-
|
|
90
|
-
Yeah, we do support rendering partials in views. Nevertheless, we discourage _partials_ at all.
|
|
91
|
-
|
|
92
|
-
The distinction between partials and views is making things more complex, so why should we have two kinds of view types? Use ordinary views instead, they're fine.
|
|
93
|
-
|
|
94
|
-
%p
|
|
95
|
-
= render :view => 'items'
|
|
96
|
-
|
|
97
|
-
=== Rendering Global Partials
|
|
98
|
-
|
|
99
|
-
Sometimes you need to render a global partial from <tt>app/views</tt> within a cell. For instance, the +gmaps4rails+ helper depends on a global partial. While this breaks encapsulation it's still possible in cells - just add the global view path.
|
|
100
|
-
|
|
101
|
-
class MapCell < Cell::Rails
|
|
102
|
-
append_view_path "app/views"
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
== View Inheritance
|
|
106
|
-
|
|
107
|
-
This is where OOP comes back to your view.
|
|
108
|
-
|
|
109
|
-
* <b>Inherit code</b> into your cells by deriving more abstract cells.
|
|
110
|
-
* <b>Inherit views</b> from parent cells.
|
|
111
|
-
|
|
112
|
-
=== Builders
|
|
113
|
-
|
|
114
|
-
Let +render_cell+ take care of creating the right cell. Just configure your super-cell properly.
|
|
115
|
-
|
|
116
|
-
class LoginCell < Cell::Rails
|
|
117
|
-
build do
|
|
118
|
-
UnauthorizedUserCell unless logged_in?
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
A call to
|
|
122
|
-
|
|
123
|
-
render_cell(:login, :box)
|
|
124
|
-
|
|
125
|
-
will render the configured +UnauthorizedUserCell+ instead of the original +LoginCell+ if the login test fails.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
== Caching
|
|
129
|
-
|
|
130
|
-
Cells do strict view caching. No cluttered fragment caching. Add
|
|
131
|
-
|
|
132
|
-
class CartCell < Cell::Rails
|
|
133
|
-
cache :show, :expires_in => 10.minutes
|
|
134
|
-
|
|
135
|
-
and your cart will be re-rendered after 10 minutes.
|
|
136
|
-
|
|
137
|
-
You can expand the state's cache key - why not use a versioner block to do just this?
|
|
138
|
-
|
|
139
|
-
class CartCell < Cell::Rails
|
|
140
|
-
cache :show do |cell, options|
|
|
141
|
-
options[:items].md5
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
The block's return value is appended to the state key: <tt>"cells/cart/show/0ecb1360644ce665a4ef"</tt>.
|
|
145
|
-
|
|
146
|
-
Check the {API to learn more}[http://rdoc.info/gems/cells/Cell/Caching/ClassMethods#cache-instance_method].
|
|
147
|
-
|
|
148
|
-
== Testing
|
|
149
|
-
|
|
150
|
-
Another big advantage compared to monolithic controller/helper/partial piles is the ability to test your cells isolated.
|
|
151
|
-
|
|
152
|
-
=== Test::Unit
|
|
153
|
-
|
|
154
|
-
So what if you wanna test the cart cell? Use the generated <tt>test/cells/cart_cell_test.rb</tt> test.
|
|
155
|
-
|
|
156
|
-
class CartCellTest < Cell::TestCase
|
|
157
|
-
test "show" do
|
|
158
|
-
invoke :show, :user => @user_fixture
|
|
159
|
-
assert_select "#cart", "You have 3 items in your shopping cart."
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
Don't forget to put <tt>require 'cell/test_case'</tt> in your project's <tt>test/test_helper.rb</tt> file.
|
|
163
|
-
|
|
164
|
-
Then, run your tests with
|
|
165
|
-
|
|
166
|
-
$ rake test:cells
|
|
167
|
-
|
|
168
|
-
That's easy, clean and strongly improves your component-driven software quality. How'd you do that with partials?
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
=== RSpec
|
|
172
|
-
|
|
173
|
-
If you prefer RSpec examples, use the {rspec-cells}[http://github.com/apotonick/rspec-cells] gem for specing.
|
|
174
|
-
|
|
175
|
-
it "should render the posts count" do
|
|
176
|
-
render_cell(:posts, :count).should have_selector("p", :content => "4 posts!")
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
To run your specs we got a rake task, too!
|
|
180
|
-
|
|
181
|
-
$ rake spec:cells
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
== Mountable Cells
|
|
185
|
-
|
|
186
|
-
Cells 3.8 got rid of the ActionController dependency. This essentially means you can mount Cells to routes or use them like a Rack middleware. All you need to do is derive from Cell::Base.
|
|
187
|
-
|
|
188
|
-
class PostCell < Cell::Base
|
|
189
|
-
..
|
|
190
|
-
|
|
191
|
-
In your <tt>routes.rb</tt> file, mount the cell like a Rack app.
|
|
192
|
-
|
|
193
|
-
match "/posts" => proc { |env|
|
|
194
|
-
[ 200, {}, [ Cell::Base.render_cell_for(:post, :show) ]]
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
=== Cells in ActionMailer
|
|
198
|
-
|
|
199
|
-
ActionMailer doesn't have request object, so if you inherit from Cell::Rails you will receive an error. Cell::Base will fix that problem, but you will not be able to use any of routes inside your cells.
|
|
200
|
-
|
|
201
|
-
You can fix that with {actionmailer_with_request}[https://github.com/weppos/actionmailer_with_request] which (suprise!) brings request object to the ActionMailer.
|
|
202
|
-
|
|
203
|
-
== Using Rails Gems Like simple_form Outside Of Rails
|
|
204
|
-
|
|
205
|
-
Cells can be used outside of Rails. A new module brought in 3.8.5 provides the Rails view "API" making it possible to use gems like the popular {simple_form}[https://github.com/plataformatec/simple_form] outside Rails!
|
|
206
|
-
|
|
207
|
-
All you need to do is providing the cell with some helpers, usually it's the polymorphic routing paths required by the gems.
|
|
208
|
-
|
|
209
|
-
module RoutingHelpers
|
|
210
|
-
def musician_path(model)
|
|
211
|
-
"/musicians/#{model.id}"
|
|
212
|
-
end
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
Then, use the Cell::Rails::HelperAPI module and it should work fine (depending on the quality of the gem you're desiring to use).
|
|
216
|
-
|
|
217
|
-
require 'cell/base'
|
|
218
|
-
require "cell/rails/helper_api"
|
|
219
|
-
require "simple_form"
|
|
220
|
-
|
|
221
|
-
class BassistCell < Cell::Base
|
|
222
|
-
include Cell::Rails::HelperAPI
|
|
223
|
-
|
|
224
|
-
self._helpers = RoutingHelpers
|
|
225
|
-
|
|
226
|
-
def show
|
|
227
|
-
@musician = Musician.find(:first)
|
|
228
|
-
end
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
Your views can now use the gem's helpers.
|
|
232
|
-
|
|
233
|
-
<%= simple_form_for @musician do |f| %>
|
|
234
|
-
<%= f.input :name %>
|
|
235
|
-
<%= f.button :submit %>
|
|
236
|
-
<% end %>
|
|
237
|
-
|
|
238
|
-
Note that this currently "only" works with Rails 3.2-4.0.
|
|
239
|
-
|
|
240
|
-
== Cells is Rails::Engine aware!
|
|
241
|
-
|
|
242
|
-
Now <tt>Rails::Engine</tt>s can contribute to Cells view paths. By default, any 'app/cells' found inside any Engine is automatically included into Cells view paths. If you need to, you can customize the view paths changing/appending to the <tt>'app/cell_views'</tt> path configuration. See the @Cell::EngineIntegration@ for more details.
|
|
243
|
-
|
|
244
|
-
== Generators
|
|
245
|
-
|
|
246
|
-
By default, generated cells inherit from <code>Cell::Rails</code>. If you want to change this, specify your new class name in <code>config/application.rb</code>:
|
|
247
|
-
|
|
248
|
-
module MyApp
|
|
249
|
-
class Application < Rails::Application
|
|
250
|
-
config.generators do |g|
|
|
251
|
-
g.base_cell_class "ApplicationCell"
|
|
252
|
-
end
|
|
253
|
-
end
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
== Rails 2.3 note
|
|
257
|
-
|
|
258
|
-
In order to copy the cells rake tasks to your app, run
|
|
259
|
-
|
|
260
|
-
$ script/generate cells_install
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
== More features
|
|
264
|
-
|
|
265
|
-
Cells can do more.
|
|
266
|
-
|
|
267
|
-
<b>No Limits</b>:: Have as many cells in your page as you need - no limitation to your +render_cell+ calls.
|
|
268
|
-
<b>Cell Nesting</b>:: Have complex cell hierarchies as you can call +render_cell+ within cells, too.
|
|
269
|
-
|
|
270
|
-
Go for it, you'll love it!
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
== LICENSE
|
|
274
|
-
|
|
275
|
-
Copyright (c) 2007-2011, Nick Sutterer
|
|
276
|
-
|
|
277
|
-
Copyright (c) 2007-2008, Solide ICT by Peter Bex and Bob Leers
|
|
278
|
-
|
|
279
|
-
Released under the MIT License.
|