cells 3.4.0.beta3 → 3.4.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.
- data/README.rdoc +12 -3
- data/Rakefile +3 -38
- data/lib/cell.rb +45 -7
- data/lib/cell/caching.rb +1 -1
- data/lib/cell/rails.rb +120 -132
- data/lib/cells.rb +62 -10
- data/lib/cells/rails.rb +0 -3
- data/lib/cells/version.rb +1 -3
- data/test/active_helper_test.rb +2 -2
- data/test/assertions_helper_test.rb +2 -3
- data/test/cell_generator_test.rb +2 -2
- data/test/cell_module_test.rb +30 -0
- data/test/helper_test.rb +1 -2
- data/test/rails/caching_test.rb +1 -2
- data/test/rails/capture_test.rb +2 -3
- data/test/rails/cells_test.rb +2 -7
- data/test/rails/integration_test.rb +2 -2
- data/test/rails/render_test.rb +2 -4
- data/test/rails/router_test.rb +1 -1
- data/test/rails/view_test.rb +2 -4
- metadata +64 -74
- data/lib/cell/base_methods.rb +0 -100
- data/lib/generators/cells_install/USAGE +0 -3
- data/lib/generators/cells_install/cells_install_generator.rb +0 -12
- data/lib/generators/cells_install/templates/initializer.rb +0 -9
- data/test/base_methods_test.rb +0 -40
data/README.rdoc
CHANGED
|
@@ -18,11 +18,11 @@ It's a gem!
|
|
|
18
18
|
|
|
19
19
|
Rails 3:
|
|
20
20
|
|
|
21
|
-
gem install cells
|
|
21
|
+
gem install cells
|
|
22
22
|
|
|
23
23
|
Rails 2.3:
|
|
24
24
|
|
|
25
|
-
gem install cells
|
|
25
|
+
gem install cells -v 3.3.4
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
== Generate
|
|
@@ -84,6 +84,15 @@ Yes, Cells have helpers just like controllers. If you need some specific helper,
|
|
|
84
84
|
|
|
85
85
|
and it will be around in your cart views.
|
|
86
86
|
|
|
87
|
+
=== Partials?
|
|
88
|
+
|
|
89
|
+
Yeah, we do support rendering partials in views. Nevertheless, we discourage _partials_ at all.
|
|
90
|
+
|
|
91
|
+
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.
|
|
92
|
+
|
|
93
|
+
%p
|
|
94
|
+
= render :view => 'items'
|
|
95
|
+
|
|
87
96
|
|
|
88
97
|
== Caching
|
|
89
98
|
|
|
@@ -135,4 +144,4 @@ Copyright (c) 2007-2010, Nick Sutterer
|
|
|
135
144
|
|
|
136
145
|
Copyright (c) 2007-2008, Solide ICT by Peter Bex and Bob Leers
|
|
137
146
|
|
|
138
|
-
Released under the MIT License.
|
|
147
|
+
Released under the MIT License.
|
data/Rakefile
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
1
|
require 'rake'
|
|
3
2
|
require 'rake/testtask'
|
|
4
3
|
require 'rake/rdoctask'
|
|
@@ -11,44 +10,10 @@ task :default => :test
|
|
|
11
10
|
desc 'Test the cells plugin.'
|
|
12
11
|
Rake::TestTask.new(:test) do |test|
|
|
13
12
|
test.libs << 'test'
|
|
14
|
-
test.test_files = FileList['test/*_test.rb', 'test/rails/*_test.rb']
|
|
13
|
+
test.test_files = FileList['test/*_test.rb', 'test/rails/*_test.rb'] - ['test/rails/capture_test.rb']
|
|
15
14
|
test.verbose = true
|
|
16
15
|
end
|
|
17
16
|
|
|
18
|
-
desc 'Generate documentation for the cells plugin.'
|
|
19
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
20
|
-
rdoc.rdoc_dir = 'rdoc'
|
|
21
|
-
rdoc.title = 'Cells Documentation'
|
|
22
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
|
23
|
-
rdoc.rdoc_files.include('README.rdoc')
|
|
24
|
-
rdoc.rdoc_files.include('init.rb')
|
|
25
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# rdoc -m "README.rdoc" init.rb lib/ generators/ README.rdoc
|
|
29
|
-
|
|
30
|
-
# Gem managment tasks.
|
|
31
|
-
#
|
|
32
|
-
# == Bump gem version (any):
|
|
33
|
-
#
|
|
34
|
-
# rake version:bump:major
|
|
35
|
-
# rake version:bump:minor
|
|
36
|
-
# rake version:bump:patch
|
|
37
|
-
#
|
|
38
|
-
# == Generate gemspec, build & install locally:
|
|
39
|
-
#
|
|
40
|
-
# rake gemspec
|
|
41
|
-
# rake build
|
|
42
|
-
# sudo rake install
|
|
43
|
-
#
|
|
44
|
-
# == Git tag & push to origin/master
|
|
45
|
-
#
|
|
46
|
-
# rake release
|
|
47
|
-
#
|
|
48
|
-
# == Release to Gemcutter.org:
|
|
49
|
-
#
|
|
50
|
-
# rake gemcutter:release
|
|
51
|
-
#
|
|
52
17
|
begin
|
|
53
18
|
gem 'jeweler'
|
|
54
19
|
require 'jeweler'
|
|
@@ -56,8 +21,8 @@ begin
|
|
|
56
21
|
Jeweler::Tasks.new do |spec|
|
|
57
22
|
spec.name = "cells"
|
|
58
23
|
spec.version = ::Cells::VERSION
|
|
59
|
-
spec.summary = %{
|
|
60
|
-
spec.description =
|
|
24
|
+
spec.summary = %{View Components for Rails.}
|
|
25
|
+
spec.description = %{Cells are lightweight controllers for Rails and can be rendered in views, providing an elegant and fast way for encapsulation and component-orientation.}
|
|
61
26
|
spec.homepage = "http://cells.rubyforge.org"
|
|
62
27
|
spec.authors = ["Nick Sutterer"]
|
|
63
28
|
spec.email = "apotonick@gmail.com"
|
data/lib/cell.rb
CHANGED
|
@@ -1,8 +1,46 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
1
|
module Cell
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
autoload :Caching, 'cell/caching'
|
|
3
|
+
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
module ClassMethods
|
|
7
|
+
def render_cell_for(controller, name, state, opts={})
|
|
8
|
+
create_cell_for(controller, name, opts).render_state(state)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Creates a cell instance.
|
|
12
|
+
def create_cell_for(controller, name, opts={})
|
|
13
|
+
class_from_cell_name(name).new(controller, opts)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Return the default view path for +state+. Override this if you cell has a differing naming style.
|
|
17
|
+
def view_for_state(state)
|
|
18
|
+
"#{cell_name}/#{state}"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Returns all possible view paths for +state+ by invoking #view_for_state on all classes up
|
|
22
|
+
# the inheritance chain.
|
|
23
|
+
def find_class_view_for_state(state)
|
|
24
|
+
return [view_for_state(state)] unless superclass.respond_to?(:find_class_view_for_state)
|
|
25
|
+
|
|
26
|
+
superclass.find_class_view_for_state(state) << view_for_state(state)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# The cell name, underscored with +_cell+ removed.
|
|
30
|
+
def cell_name
|
|
31
|
+
name.underscore.sub(/_cell$/, '')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# The cell class constant for +cell_name+.
|
|
35
|
+
def class_from_cell_name(cell_name)
|
|
36
|
+
"#{cell_name}_cell".classify.constantize
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
module InstanceMethods
|
|
41
|
+
# Computes all possible paths for +state+ by traversing up the inheritance chain.
|
|
42
|
+
def possible_paths_for_state(state)
|
|
43
|
+
self.class.find_class_view_for_state(state).reverse!
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
data/lib/cell/caching.rb
CHANGED
data/lib/cell/rails.rb
CHANGED
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
require 'abstract_controller'
|
|
2
|
-
require 'action_controller'
|
|
3
2
|
|
|
4
3
|
module Cell
|
|
5
|
-
class Rails <
|
|
6
|
-
include
|
|
4
|
+
class Rails < AbstractController::Base
|
|
5
|
+
include Cell
|
|
7
6
|
include AbstractController
|
|
8
|
-
include Rendering, Layouts, Helpers, Callbacks, Translation
|
|
7
|
+
include Rendering, Layouts, Helpers, Callbacks, Translation, Logger
|
|
9
8
|
include ActionController::RequestForgeryProtection
|
|
10
9
|
|
|
11
|
-
module Rendering
|
|
12
|
-
def render_state(state)
|
|
13
|
-
rack_response = dispatch(state, parent_controller.request)
|
|
14
|
-
|
|
15
|
-
str = '' # copied from Response#body.
|
|
16
|
-
rack_response[2].each { |part| str << part.to_s }
|
|
17
|
-
str.html_safe # in fact, i'd love to return a real OutputBuffer here.
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
10
|
|
|
21
11
|
class View < ActionView::Base
|
|
22
12
|
def render(options = {}, locals = {}, &block)
|
|
@@ -28,27 +18,48 @@ module Cell
|
|
|
28
18
|
end
|
|
29
19
|
end
|
|
30
20
|
|
|
21
|
+
|
|
22
|
+
module Rendering
|
|
23
|
+
# Invoke the state method for +state+ which usually renders something nice.
|
|
24
|
+
def render_state(state)
|
|
25
|
+
dispatch(state, parent_controller.request)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
module Metal
|
|
31
|
+
def dispatch(name, request)
|
|
32
|
+
@_request = request
|
|
33
|
+
@_env = request.env
|
|
34
|
+
@_env['action_controller.instance'] = self
|
|
35
|
+
process(name)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def params
|
|
39
|
+
@_params ||= request.parameters # DISCUSS: let rails helper access @controller.params!
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
delegate :request, :to => :parent_controller
|
|
43
|
+
delegate :config, :to => :parent_controller
|
|
44
|
+
delegate :session, :to => :parent_controller
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
include Metal
|
|
31
49
|
include Rendering
|
|
32
50
|
include Caching
|
|
33
51
|
|
|
34
|
-
#include AbstractController::Logger
|
|
35
|
-
|
|
36
52
|
|
|
37
|
-
#include Cell::ActiveHelper
|
|
38
53
|
cattr_accessor :url_helpers ### TODO: discuss if we really need that or can handle that in cells.rb already.
|
|
54
|
+
attr_reader :parent_controller
|
|
39
55
|
|
|
40
56
|
abstract!
|
|
41
57
|
|
|
42
|
-
|
|
43
|
-
def initialize(parent_controller=nil, options={})
|
|
58
|
+
|
|
59
|
+
def initialize(parent_controller=nil, options={})
|
|
44
60
|
@parent_controller = parent_controller
|
|
45
61
|
@opts = @options = options
|
|
46
62
|
end
|
|
47
|
-
attr_reader :parent_controller
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def log(*args); end
|
|
51
|
-
|
|
52
63
|
|
|
53
64
|
def self.view_context_class
|
|
54
65
|
controller = self
|
|
@@ -66,120 +77,97 @@ module Cell
|
|
|
66
77
|
def self.controller_path
|
|
67
78
|
@controller_path ||= name.sub(/Cell$/, '').underscore unless anonymous?
|
|
68
79
|
end
|
|
69
|
-
|
|
70
|
-
def process(*) # defined in AC::Metal.
|
|
71
|
-
self.response_body = super
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
delegate :request, :to => :parent_controller
|
|
75
|
-
delegate :config, :to => :parent_controller # DISCUSS: what if a cell has its own config (eg for assets, cells/bassist/images)?
|
|
76
|
-
# DISCUSS: let @controller point to @parent_controller in views, and @cell is the actual real controller?
|
|
77
80
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
# Just use <tt>:view</tt> and enjoy.
|
|
127
|
-
def render(opts={})
|
|
128
|
-
render_view_for(opts, self.action_name)
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
|
|
81
|
+
# Renders the view for the current state and returns the markup.
|
|
82
|
+
# Don't forget to return the markup itself from the state method.
|
|
83
|
+
#
|
|
84
|
+
# === Options
|
|
85
|
+
# +:view+:: Specifies the name of the view file to render. Defaults to the current state name.
|
|
86
|
+
# +:layout+:: Renders the state wrapped in the layout. Layouts reside in <tt>app/cells/layouts</tt>.
|
|
87
|
+
# +:locals+:: Makes the named parameters available as variables in the view.
|
|
88
|
+
# +:text+:: Just renders plain text.
|
|
89
|
+
# +:inline+:: Renders an inline template as state view. See ActionView::Base#render for details.
|
|
90
|
+
# +:file+:: Specifies the name of the file template to render.
|
|
91
|
+
# +:nothing+:: Doesn't invoke the rendering process.
|
|
92
|
+
# +:state+:: Instantly invokes another rendering cycle for the passed state and returns.
|
|
93
|
+
#
|
|
94
|
+
# Example:
|
|
95
|
+
# class MusicianCell < ::Cell::Base
|
|
96
|
+
# def sing
|
|
97
|
+
# # ... laalaa
|
|
98
|
+
# render
|
|
99
|
+
# end
|
|
100
|
+
#
|
|
101
|
+
# renders the view <tt>musician/sing.html</tt>.
|
|
102
|
+
#
|
|
103
|
+
# def sing
|
|
104
|
+
# # ... laalaa
|
|
105
|
+
# render :view => :shout, :layout => 'metal'
|
|
106
|
+
# end
|
|
107
|
+
#
|
|
108
|
+
# renders <tt>musician/shout.html</tt> and wrap it in <tt>app/cells/layouts/metal.html.erb</tt>.
|
|
109
|
+
#
|
|
110
|
+
# === #render is explicit!
|
|
111
|
+
# You can also alter the markup from #render. Just remember to return it.
|
|
112
|
+
#
|
|
113
|
+
# def sing
|
|
114
|
+
# render + render + render
|
|
115
|
+
# end
|
|
116
|
+
#
|
|
117
|
+
# will render three concated views.
|
|
118
|
+
#
|
|
119
|
+
# === Partials?
|
|
120
|
+
#
|
|
121
|
+
# In Cells we abandoned the term 'partial' in favor of plain 'views' - we don't need to distinguish
|
|
122
|
+
# between both terms. A cell view is both, a view and a kind of partial as it represents only a fragment
|
|
123
|
+
# of the page.
|
|
124
|
+
#
|
|
125
|
+
# Just use <tt>:view</tt> and enjoy.
|
|
126
|
+
def render(opts={})
|
|
127
|
+
render_view_for(opts, self.action_name)
|
|
128
|
+
end
|
|
132
129
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
130
|
+
# Climbs up the inheritance chain, looking for a view for the current +state+.
|
|
131
|
+
def find_family_view_for_state(state)
|
|
132
|
+
missing_template_exception = nil
|
|
136
133
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
end
|
|
134
|
+
possible_paths_for_state(state).each do |template_path|
|
|
135
|
+
begin
|
|
136
|
+
template = find_template(template_path)
|
|
137
|
+
return template if template
|
|
138
|
+
rescue ::ActionView::MissingTemplate => missing_template_exception
|
|
143
139
|
end
|
|
144
|
-
|
|
145
|
-
raise missing_template_exception
|
|
146
140
|
end
|
|
147
141
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if opts[:text] ### FIXME: generic option?
|
|
156
|
-
elsif opts[:inline]
|
|
157
|
-
elsif opts[:file]
|
|
158
|
-
elsif opts[:state] ### FIXME: generic option
|
|
159
|
-
opts[:text] = render_state(opts[:state])
|
|
160
|
-
else
|
|
161
|
-
# handle :layout, :template_format, :view
|
|
162
|
-
opts = defaultize_render_options_for(opts, state)
|
|
163
|
-
|
|
164
|
-
#template = find_family_view_for_state_with_caching(opts[:view], action_view)
|
|
165
|
-
template = find_family_view_for_state(opts[:view])
|
|
166
|
-
opts[:template] = template
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
opts = sanitize_render_options(opts)
|
|
170
|
-
|
|
171
|
-
render_to_string(opts)
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
# Defaultize the passed options from #render.
|
|
175
|
-
def defaultize_render_options_for(opts, state)
|
|
176
|
-
opts[:template_format] ||= self.class.default_template_format
|
|
177
|
-
opts[:view] ||= state
|
|
178
|
-
opts
|
|
179
|
-
end
|
|
142
|
+
raise missing_template_exception
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Renders the view belonging to the given state. Will raise ActionView::MissingTemplate
|
|
146
|
+
# if it can't find a view.
|
|
147
|
+
def render_view_for(opts, state)
|
|
148
|
+
return "" if opts[:nothing]
|
|
180
149
|
|
|
181
|
-
|
|
182
|
-
|
|
150
|
+
rails_options = [:text, :inline, :file]
|
|
151
|
+
if (opts.keys & rails_options).present?
|
|
152
|
+
elsif opts[:state]
|
|
153
|
+
opts[:text] = render_state(opts[:state])
|
|
154
|
+
else
|
|
155
|
+
opts = defaultize_render_options_for(opts, state)
|
|
156
|
+
template = find_family_view_for_state(opts[:view])
|
|
157
|
+
opts[:template] = template
|
|
183
158
|
end
|
|
184
|
-
|
|
185
|
-
|
|
159
|
+
|
|
160
|
+
opts = sanitize_render_options(opts)
|
|
161
|
+
render_to_string(opts)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# Defaultize the passed options from #render.
|
|
165
|
+
def defaultize_render_options_for(opts, state)
|
|
166
|
+
opts.reverse_merge!(:view => state)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def sanitize_render_options(opts)
|
|
170
|
+
opts.except!(:view, :state)
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|
data/lib/cells.rb
CHANGED
|
@@ -1,17 +1,69 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# = Cells
|
|
2
|
+
#
|
|
3
|
+
# Cells are view components for Rails. Being lightweight controllers with actions and views, cells are the
|
|
4
|
+
# answer to <tt>DoubleRenderError</tt>s and the long awaited ability to render actions within actions.
|
|
5
|
+
#
|
|
6
|
+
# == Directory structure
|
|
7
|
+
#
|
|
8
|
+
# Cells live in +app/cells/+ and have a similar file layout as controllers.
|
|
9
|
+
#
|
|
10
|
+
# app/
|
|
11
|
+
# cells/
|
|
12
|
+
# shopping_cart_cell.rb
|
|
13
|
+
# shopping_cart/
|
|
14
|
+
# status.html.erb
|
|
15
|
+
# product_list.haml
|
|
16
|
+
# layouts/
|
|
17
|
+
# box.html.erb
|
|
18
|
+
#
|
|
19
|
+
# == Cell nesting
|
|
20
|
+
#
|
|
21
|
+
# Is is good practice to split up complex cell views into multiple states or views. Remember, you can always use
|
|
22
|
+
# <tt>render :view => ...</tt> and <tt>render :state => ...</tt> in your views.
|
|
23
|
+
#
|
|
24
|
+
# Following this, you stick to encapsulation and save your code from getting inscrutable, as it happens in most
|
|
25
|
+
# controller views, partials, and so called "helpers".
|
|
26
|
+
#
|
|
27
|
+
# Given the following setup:
|
|
28
|
+
#
|
|
29
|
+
# class ShoppingCartCell < Cell::Base
|
|
30
|
+
# def cart
|
|
31
|
+
# @items = items_in_cart
|
|
32
|
+
# render
|
|
33
|
+
# end
|
|
34
|
+
#
|
|
35
|
+
# def order_button
|
|
36
|
+
# render
|
|
37
|
+
# end
|
|
38
|
+
#
|
|
39
|
+
# You could now render the "Order!" button in the +cart.haml+ view.
|
|
40
|
+
#
|
|
41
|
+
# - for item in @items
|
|
42
|
+
# = @item.title
|
|
43
|
+
#
|
|
44
|
+
# render :state => :order_button
|
|
45
|
+
#
|
|
46
|
+
# which is more than just a partial, as you may execute additional code in the state method.
|
|
47
|
+
#
|
|
48
|
+
# == View inheritance
|
|
49
|
+
#
|
|
50
|
+
# Unlike controllers, Cells can form a class hierarchy. Even Views are inherited, which is pretty useful
|
|
51
|
+
# when overriding only small parts of the view.
|
|
52
|
+
#
|
|
53
|
+
# So if you'd need a special "Order!" button with sparkling stars on christmas, your cell would go like this.
|
|
54
|
+
#
|
|
55
|
+
# class XmasCartCell < ShoppingCartCell
|
|
56
|
+
# end
|
|
57
|
+
#
|
|
58
|
+
# Beside your new class you'd provide a star-sprangled button view in +xmas_cart/order_button.haml+.
|
|
59
|
+
# When rendering the +cart+ state, the states as well as the "missing" views are inherited from ancesting cells,
|
|
60
|
+
# this is pretty DRY and object-oriented, isn't it?
|
|
4
61
|
require 'action_controller'
|
|
5
62
|
|
|
6
|
-
|
|
7
|
-
require 'cell/base_methods'
|
|
8
|
-
|
|
9
63
|
require 'cell'
|
|
10
|
-
require 'cells/rails'
|
|
64
|
+
require 'cells/rails'
|
|
11
65
|
require 'cell/rails'
|
|
12
66
|
|
|
13
|
-
require 'cells/helpers'
|
|
14
|
-
|
|
15
67
|
|
|
16
68
|
module Cells
|
|
17
69
|
# Any config should be placed here using +mattr_accessor+.
|
|
@@ -70,4 +122,4 @@ class Cells::Railtie < Rails::Railtie
|
|
|
70
122
|
#ActiveSupport::Dependencies.load_paths << Rails.root.join(*%w[app cells])
|
|
71
123
|
### DISCUSS: how are cell classes found by Rails?
|
|
72
124
|
end
|
|
73
|
-
end
|
|
125
|
+
end
|
data/lib/cells/rails.rb
CHANGED
data/lib/cells/version.rb
CHANGED
data/test/active_helper_test.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
### DISCUSS: how can we limit that test to systems where ActiveHelper's around?
|
|
4
4
|
|
|
@@ -54,4 +54,4 @@ class ActiveHelperTest < ActiveSupport::TestCase
|
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
|
-
end
|
|
57
|
+
end
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
|
1
|
+
require 'test_helper'
|
|
3
2
|
|
|
4
3
|
class AssertionsHelperTest < ActionController::TestCase
|
|
5
4
|
context "A TestCase" do
|
|
@@ -30,4 +29,4 @@ class AssertionsHelperTest < ActionController::TestCase
|
|
|
30
29
|
assert_equal({:topic => :peace}, cell(:bassist, :topic => :peace) { def opts; @opts; end }.opts)
|
|
31
30
|
end
|
|
32
31
|
end
|
|
33
|
-
end
|
|
32
|
+
end
|
data/test/cell_generator_test.rb
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class CellModuleTest < ActiveSupport::TestCase
|
|
4
|
+
context "Cell::Base" do
|
|
5
|
+
|
|
6
|
+
should "provide AbstractBase.render_cell_for" do
|
|
7
|
+
assert_equal "Doo", Cell::Base.render_cell_for(@controller, :bassist, :play)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
should "provide possible_paths_for_state" do
|
|
11
|
+
assert_equal ["bad_guitarist/play", "bassist/play", "cell/rails/play"], cell(:bad_guitarist).possible_paths_for_state(:play)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
should "provide Cell.cell_name" do
|
|
15
|
+
assert_equal 'bassist', cell(:bassist).class.cell_name
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
should "provide cell_name for modules, too" do
|
|
19
|
+
class SingerCell < Cell::Base
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
assert_equal "cell_module_test/singer", CellModuleTest::SingerCell.cell_name
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
should "provide class_from_cell_name" do
|
|
27
|
+
assert_equal BassistCell, ::Cell::Base.class_from_cell_name('bassist')
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
data/test/helper_test.rb
CHANGED
data/test/rails/caching_test.rb
CHANGED
data/test/rails/capture_test.rb
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
require File.join(File.dirname(__FILE__), '/../test_helper')
|
|
1
|
+
require 'test_helper'
|
|
3
2
|
|
|
4
3
|
class ProducerCell < Cell::Base
|
|
5
4
|
helper ::Cells::Helpers::CaptureHelper
|
|
@@ -49,4 +48,4 @@ class RailsCaptureTest < ActionController::TestCase
|
|
|
49
48
|
assert_equal "\n<pre>DummDooDiiDoo</pre>", @response.body
|
|
50
49
|
end
|
|
51
50
|
end
|
|
52
|
-
end
|
|
51
|
+
end
|
data/test/rails/cells_test.rb
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
require
|
|
2
|
-
|
|
1
|
+
require 'test_helper'
|
|
3
2
|
|
|
4
3
|
class RailsCellsTest < ActiveSupport::TestCase
|
|
5
4
|
context "A rails cell" do
|
|
@@ -16,11 +15,8 @@ class RailsCellsTest < ActiveSupport::TestCase
|
|
|
16
15
|
|
|
17
16
|
context "invoking defaultize_render_options_for" do
|
|
18
17
|
should "set default values" do
|
|
19
|
-
cell(:bassist).class.default_template_format = :html ### FIXME: remove and get it working.
|
|
20
|
-
|
|
21
18
|
options = cell(:bassist).defaultize_render_options_for({}, :play)
|
|
22
19
|
|
|
23
|
-
assert_equal :html, options[:template_format]
|
|
24
20
|
assert_equal :play, options[:view]
|
|
25
21
|
end
|
|
26
22
|
|
|
@@ -61,7 +57,6 @@ class RailsCellsTest < ActiveSupport::TestCase
|
|
|
61
57
|
@request = ActionController::TestRequest.new
|
|
62
58
|
@request.env["action_dispatch.request.request_parameters"] = {:song => "Creatures"}
|
|
63
59
|
@cell = cell(:bassist)
|
|
64
|
-
@cell.request= @request
|
|
65
60
|
end
|
|
66
61
|
|
|
67
62
|
should_eventually "delegate log" do
|
|
@@ -85,4 +80,4 @@ class RailsCellsTest < ActiveSupport::TestCase
|
|
|
85
80
|
end
|
|
86
81
|
|
|
87
82
|
end
|
|
88
|
-
end
|
|
83
|
+
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
class RailsIntegrationTest < ActionController::TestCase
|
|
4
4
|
tests MusicianController
|
|
@@ -36,4 +36,4 @@ class RailsIntegrationTest < ActionController::TestCase
|
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
end
|
|
39
|
+
end
|
data/test/rails/render_test.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
require 'builder'
|
|
3
3
|
|
|
4
4
|
class RailsRenderTest < ActiveSupport::TestCase
|
|
@@ -129,12 +129,10 @@ class RailsRenderTest < ActiveSupport::TestCase
|
|
|
129
129
|
|
|
130
130
|
@request.env["action_dispatch.request.request_parameters"] = {:what => 'get'}
|
|
131
131
|
@cell = cell(:bassist)
|
|
132
|
-
@cell.request = @request ### FIXME.
|
|
133
132
|
|
|
134
133
|
assert_equal "Come and get me!", @cell.render_state(:pose)
|
|
135
134
|
end
|
|
136
135
|
|
|
137
136
|
|
|
138
137
|
end
|
|
139
|
-
|
|
140
|
-
end
|
|
138
|
+
end
|
data/test/rails/router_test.rb
CHANGED
data/test/rails/view_test.rb
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
require File.join(File.dirname(__FILE__), '../test_helper')
|
|
1
|
+
require 'test_helper'
|
|
3
2
|
|
|
4
3
|
class RailsViewTest < ActiveSupport::TestCase
|
|
5
4
|
context "A cell view" do
|
|
@@ -18,7 +17,6 @@ class RailsViewTest < ActiveSupport::TestCase
|
|
|
18
17
|
assert_equal "Dumm Dooom", render_cell(:bassist, :compose)
|
|
19
18
|
end
|
|
20
19
|
end
|
|
21
|
-
|
|
22
20
|
|
|
23
21
|
end
|
|
24
|
-
end
|
|
22
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cells
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
5
|
-
prerelease: true
|
|
4
|
+
prerelease: false
|
|
6
5
|
segments:
|
|
7
6
|
- 3
|
|
8
7
|
- 4
|
|
9
8
|
- 0
|
|
10
|
-
|
|
11
|
-
version: 3.4.0.beta3
|
|
9
|
+
version: 3.4.0
|
|
12
10
|
platform: ruby
|
|
13
11
|
authors:
|
|
14
12
|
- Nick Sutterer
|
|
@@ -16,11 +14,11 @@ autorequire:
|
|
|
16
14
|
bindir: bin
|
|
17
15
|
cert_chain: []
|
|
18
16
|
|
|
19
|
-
date: 2010-09-
|
|
17
|
+
date: 2010-09-29 00:00:00 +02:00
|
|
20
18
|
default_executable:
|
|
21
19
|
dependencies: []
|
|
22
20
|
|
|
23
|
-
description: Cells are lightweight controllers for Rails and can be rendered in
|
|
21
|
+
description: Cells are lightweight controllers for Rails and can be rendered in views, providing an elegant and fast way for encapsulation and component-orientation.
|
|
24
22
|
email: apotonick@gmail.com
|
|
25
23
|
executables: []
|
|
26
24
|
|
|
@@ -38,7 +36,6 @@ files:
|
|
|
38
36
|
- lib/cell.rb
|
|
39
37
|
- lib/cell/active_helper.rb
|
|
40
38
|
- lib/cell/base.rb
|
|
41
|
-
- lib/cell/base_methods.rb
|
|
42
39
|
- lib/cell/caching.rb
|
|
43
40
|
- lib/cell/rails.rb
|
|
44
41
|
- lib/cells.rb
|
|
@@ -53,45 +50,42 @@ files:
|
|
|
53
50
|
- lib/generators/cells/templates/cell_test.rb
|
|
54
51
|
- lib/generators/cells/templates/view.erb
|
|
55
52
|
- lib/generators/cells/templates/view.haml
|
|
56
|
-
-
|
|
57
|
-
- lib/generators/cells_install/cells_install_generator.rb
|
|
58
|
-
- lib/generators/cells_install/templates/initializer.rb
|
|
53
|
+
- test/active_helper_test.rb
|
|
59
54
|
- test/assertions_helper_test.rb
|
|
55
|
+
- test/rails/router_test.rb
|
|
56
|
+
- test/rails/view_test.rb
|
|
57
|
+
- test/rails/capture_test.rb
|
|
58
|
+
- test/rails/integration_test.rb
|
|
59
|
+
- test/rails/render_test.rb
|
|
60
|
+
- test/rails/cells_test.rb
|
|
61
|
+
- test/rails/caching_test.rb
|
|
62
|
+
- test/cell_generator_test.rb
|
|
60
63
|
- test/test_helper.rb
|
|
61
|
-
- test/
|
|
62
|
-
- test/
|
|
63
|
-
- test/app/cells/test_cell.rb
|
|
64
|
-
- test/app/helpers/helper_using_cell_helper.rb
|
|
65
|
-
- test/app/helpers/application_helper.rb
|
|
66
|
-
- test/dummy/app/controllers/application_controller.rb
|
|
67
|
-
- test/dummy/app/controllers/musician_controller.rb
|
|
68
|
-
- test/dummy/app/helpers/application_helper.rb
|
|
69
|
-
- test/dummy/config/environments/test.rb
|
|
70
|
-
- test/dummy/config/environments/production.rb
|
|
71
|
-
- test/dummy/config/environments/development.rb
|
|
72
|
-
- test/dummy/config/boot.rb
|
|
73
|
-
- test/dummy/config/environment.rb
|
|
74
|
-
- test/dummy/config/initializers/secret_token.rb
|
|
75
|
-
- test/dummy/config/initializers/backtrace_silencers.rb
|
|
64
|
+
- test/support/internal_assertions_helper.rb
|
|
65
|
+
- test/dummy/config/application.rb
|
|
76
66
|
- test/dummy/config/initializers/session_store.rb
|
|
77
67
|
- test/dummy/config/initializers/mime_types.rb
|
|
68
|
+
- test/dummy/config/initializers/secret_token.rb
|
|
78
69
|
- test/dummy/config/initializers/inflections.rb
|
|
79
|
-
- test/dummy/config/
|
|
70
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
|
80
71
|
- test/dummy/config/routes.rb
|
|
81
|
-
- test/dummy/
|
|
72
|
+
- test/dummy/config/boot.rb
|
|
73
|
+
- test/dummy/config/environment.rb
|
|
74
|
+
- test/dummy/config/environments/production.rb
|
|
75
|
+
- test/dummy/config/environments/test.rb
|
|
76
|
+
- test/dummy/config/environments/development.rb
|
|
82
77
|
- test/dummy/tmp/test/cells/blog_cell_test.rb
|
|
83
|
-
- test/
|
|
84
|
-
- test/
|
|
85
|
-
- test/
|
|
86
|
-
- test/
|
|
87
|
-
- test/rails/view_test.rb
|
|
88
|
-
- test/rails/caching_test.rb
|
|
89
|
-
- test/rails/cells_test.rb
|
|
90
|
-
- test/rails/integration_test.rb
|
|
91
|
-
- test/rails/router_test.rb
|
|
92
|
-
- test/rails/capture_test.rb
|
|
78
|
+
- test/dummy/tmp/app/cells/blog_cell.rb
|
|
79
|
+
- test/dummy/app/controllers/musician_controller.rb
|
|
80
|
+
- test/dummy/app/controllers/application_controller.rb
|
|
81
|
+
- test/dummy/app/helpers/application_helper.rb
|
|
93
82
|
- test/helper_test.rb
|
|
94
|
-
- test/
|
|
83
|
+
- test/cell_module_test.rb
|
|
84
|
+
- test/app/cells/bassist_cell.rb
|
|
85
|
+
- test/app/cells/test_cell.rb
|
|
86
|
+
- test/app/cells/bad_guitarist_cell.rb
|
|
87
|
+
- test/app/helpers/application_helper.rb
|
|
88
|
+
- test/app/helpers/helper_using_cell_helper.rb
|
|
95
89
|
has_rdoc: true
|
|
96
90
|
homepage: http://cells.rubyforge.org
|
|
97
91
|
licenses: []
|
|
@@ -106,62 +100,58 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
106
100
|
requirements:
|
|
107
101
|
- - ">="
|
|
108
102
|
- !ruby/object:Gem::Version
|
|
109
|
-
hash: 3
|
|
110
103
|
segments:
|
|
111
104
|
- 0
|
|
112
105
|
version: "0"
|
|
113
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
107
|
none: false
|
|
115
108
|
requirements:
|
|
116
|
-
- - "
|
|
109
|
+
- - ">="
|
|
117
110
|
- !ruby/object:Gem::Version
|
|
118
|
-
hash: 25
|
|
119
111
|
segments:
|
|
120
|
-
-
|
|
121
|
-
|
|
122
|
-
- 1
|
|
123
|
-
version: 1.3.1
|
|
112
|
+
- 0
|
|
113
|
+
version: "0"
|
|
124
114
|
requirements: []
|
|
125
115
|
|
|
126
116
|
rubyforge_project:
|
|
127
117
|
rubygems_version: 1.3.7
|
|
128
118
|
signing_key:
|
|
129
119
|
specification_version: 3
|
|
130
|
-
summary:
|
|
120
|
+
summary: View Components for Rails.
|
|
131
121
|
test_files:
|
|
122
|
+
- test/active_helper_test.rb
|
|
132
123
|
- test/assertions_helper_test.rb
|
|
124
|
+
- test/rails/router_test.rb
|
|
125
|
+
- test/rails/view_test.rb
|
|
126
|
+
- test/rails/capture_test.rb
|
|
127
|
+
- test/rails/integration_test.rb
|
|
128
|
+
- test/rails/render_test.rb
|
|
129
|
+
- test/rails/cells_test.rb
|
|
130
|
+
- test/rails/caching_test.rb
|
|
131
|
+
- test/cell_generator_test.rb
|
|
133
132
|
- test/test_helper.rb
|
|
134
|
-
- test/
|
|
135
|
-
- test/
|
|
136
|
-
- test/app/cells/test_cell.rb
|
|
137
|
-
- test/app/helpers/helper_using_cell_helper.rb
|
|
138
|
-
- test/app/helpers/application_helper.rb
|
|
139
|
-
- test/dummy/app/controllers/application_controller.rb
|
|
140
|
-
- test/dummy/app/controllers/musician_controller.rb
|
|
141
|
-
- test/dummy/app/helpers/application_helper.rb
|
|
142
|
-
- test/dummy/config/environments/test.rb
|
|
143
|
-
- test/dummy/config/environments/production.rb
|
|
144
|
-
- test/dummy/config/environments/development.rb
|
|
145
|
-
- test/dummy/config/boot.rb
|
|
146
|
-
- test/dummy/config/environment.rb
|
|
147
|
-
- test/dummy/config/initializers/secret_token.rb
|
|
148
|
-
- test/dummy/config/initializers/backtrace_silencers.rb
|
|
133
|
+
- test/support/internal_assertions_helper.rb
|
|
134
|
+
- test/dummy/config/application.rb
|
|
149
135
|
- test/dummy/config/initializers/session_store.rb
|
|
150
136
|
- test/dummy/config/initializers/mime_types.rb
|
|
137
|
+
- test/dummy/config/initializers/secret_token.rb
|
|
151
138
|
- test/dummy/config/initializers/inflections.rb
|
|
152
|
-
- test/dummy/config/
|
|
139
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
|
153
140
|
- test/dummy/config/routes.rb
|
|
154
|
-
- test/dummy/
|
|
141
|
+
- test/dummy/config/boot.rb
|
|
142
|
+
- test/dummy/config/environment.rb
|
|
143
|
+
- test/dummy/config/environments/production.rb
|
|
144
|
+
- test/dummy/config/environments/test.rb
|
|
145
|
+
- test/dummy/config/environments/development.rb
|
|
155
146
|
- test/dummy/tmp/test/cells/blog_cell_test.rb
|
|
156
|
-
- test/
|
|
157
|
-
- test/
|
|
158
|
-
- test/
|
|
159
|
-
- test/
|
|
160
|
-
- test/rails/view_test.rb
|
|
161
|
-
- test/rails/caching_test.rb
|
|
162
|
-
- test/rails/cells_test.rb
|
|
163
|
-
- test/rails/integration_test.rb
|
|
164
|
-
- test/rails/router_test.rb
|
|
165
|
-
- test/rails/capture_test.rb
|
|
147
|
+
- test/dummy/tmp/app/cells/blog_cell.rb
|
|
148
|
+
- test/dummy/app/controllers/musician_controller.rb
|
|
149
|
+
- test/dummy/app/controllers/application_controller.rb
|
|
150
|
+
- test/dummy/app/helpers/application_helper.rb
|
|
166
151
|
- test/helper_test.rb
|
|
167
|
-
- test/
|
|
152
|
+
- test/cell_module_test.rb
|
|
153
|
+
- test/app/cells/bassist_cell.rb
|
|
154
|
+
- test/app/cells/test_cell.rb
|
|
155
|
+
- test/app/cells/bad_guitarist_cell.rb
|
|
156
|
+
- test/app/helpers/application_helper.rb
|
|
157
|
+
- test/app/helpers/helper_using_cell_helper.rb
|
data/lib/cell/base_methods.rb
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
module Cell
|
|
2
|
-
module BaseMethods
|
|
3
|
-
def self.included(base)
|
|
4
|
-
base.extend ClassMethods
|
|
5
|
-
|
|
6
|
-
### DISCUSS: move that to Rails?
|
|
7
|
-
base.class_attribute :default_template_format
|
|
8
|
-
base.default_template_format = :html
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
module ClassMethods
|
|
12
|
-
def render_cell_for(controller, name, state, opts={})
|
|
13
|
-
create_cell_for(controller, name, opts).render_state(state) # FIXME: don't let BaseMethods know about controller's API.
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# Creates a cell instance of the class <tt>name</tt>Cell, passing through
|
|
17
|
-
# <tt>opts</tt>.
|
|
18
|
-
def create_cell_for(controller, name, opts={})
|
|
19
|
-
#class_from_cell_name(name).new(controller, opts)
|
|
20
|
-
class_from_cell_name(name).new(controller, opts)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# Return the default view for the given state on this cell subclass.
|
|
24
|
-
# This is a file with the name of the state under a directory with the
|
|
25
|
-
# name of the cell followed by a template extension.
|
|
26
|
-
def view_for_state(state)
|
|
27
|
-
"#{cell_name}/#{state}"
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# Find a possible template for a cell's current state. It tries to find a
|
|
31
|
-
# template file with the name of the state under a subdirectory
|
|
32
|
-
# with the name of the cell under the <tt>app/cells</tt> directory.
|
|
33
|
-
# If this file cannot be found, it will try to call this method on
|
|
34
|
-
# the superclass. This way you only have to write a state template
|
|
35
|
-
# once when a more specific cell does not need to change anything in
|
|
36
|
-
# that view.
|
|
37
|
-
def find_class_view_for_state(state)
|
|
38
|
-
return [view_for_state(state)] unless superclass.respond_to?(:find_class_view_for_state)
|
|
39
|
-
|
|
40
|
-
superclass.find_class_view_for_state(state) << view_for_state(state)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# Get the name of this cell's class as an underscored string,
|
|
44
|
-
# with _cell removed.
|
|
45
|
-
#
|
|
46
|
-
# Example:
|
|
47
|
-
# UserCell.cell_name
|
|
48
|
-
# => "user"
|
|
49
|
-
def cell_name
|
|
50
|
-
name.underscore.sub(/_cell$/, '')
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def class_from_cell_name(cell_name)
|
|
54
|
-
"#{cell_name}_cell".classify.constantize
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
attr_accessor :controller
|
|
63
|
-
attr_reader :state_name
|
|
64
|
-
|
|
65
|
-
def initialize(options={})
|
|
66
|
-
#@controller = controller
|
|
67
|
-
@opts = options
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def cell_name
|
|
71
|
-
self.class.cell_name
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
# Invoke the state method and render the given state.
|
|
75
|
-
def render_state(state, controller=nil)
|
|
76
|
-
@cell = self
|
|
77
|
-
@state_name = state
|
|
78
|
-
|
|
79
|
-
dispatch_state(state)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
# Call the state method.
|
|
83
|
-
def dispatch_state(state)
|
|
84
|
-
send(state)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
# Find possible files that belong to the state. This first tries the cell's
|
|
88
|
-
# <tt>#view_for_state</tt> method and if that returns a true value, it
|
|
89
|
-
# will accept that value as a string and interpret it as a pathname for
|
|
90
|
-
# the view file. If it returns a falsy value, it will call the Cell's class
|
|
91
|
-
# method find_class_view_for_state to determine the file to check.
|
|
92
|
-
#
|
|
93
|
-
# You can override the ::Cell::Base#view_for_state method for a particular
|
|
94
|
-
# cell if you wish to make it decide dynamically what file to render.
|
|
95
|
-
def possible_paths_for_state(state)
|
|
96
|
-
self.class.find_class_view_for_state(state).reverse!
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
end
|
|
100
|
-
end
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
class CellsInstallGenerator < Rails::Generator::Base
|
|
4
|
-
|
|
5
|
-
def manifest
|
|
6
|
-
record do |m|
|
|
7
|
-
m.directory File.join('config', 'initializers')
|
|
8
|
-
m.template 'initializer.rb', File.join('config', 'initializers', 'cells.rb')
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
end
|
data/test/base_methods_test.rb
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
|
2
|
-
|
|
3
|
-
class BaseMethodsTest < ActiveSupport::TestCase
|
|
4
|
-
context "Cell::Base" do
|
|
5
|
-
|
|
6
|
-
should "provide AbstractBase.render_cell_for" do
|
|
7
|
-
assert_equal "Doo", Cell::Base.render_cell_for(@controller, :bassist, :play)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
should "provide possible_paths_for_state" do
|
|
11
|
-
assert_equal ["bad_guitarist/play", "bassist/play", "cell/rails/play"], cell(:bad_guitarist).possible_paths_for_state(:play)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
should "provide cell_name" do
|
|
15
|
-
assert_equal 'bassist', cell(:bassist).cell_name
|
|
16
|
-
assert_equal cell(:bassist).cell_name, BassistCell.cell_name
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
should "provide cell_name for modules, too" do
|
|
20
|
-
class SingerCell
|
|
21
|
-
include Cell::BaseMethods
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
assert_equal "base_methods_test/singer", BaseMethodsTest::SingerCell.cell_name
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
should "provide class_from_cell_name" do
|
|
29
|
-
assert_equal BassistCell, ::Cell::Base.class_from_cell_name('bassist')
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
should "provide AbstractBase.default_template_format" do
|
|
33
|
-
cell(:bassist).class.default_template_format = :js
|
|
34
|
-
|
|
35
|
-
assert_equal :html, ::Cell::Base.default_template_format
|
|
36
|
-
assert_equal :js, cell(:bassist).class.default_template_format
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
end
|
|
40
|
-
end
|