cells 3.5.0.beta1 → 3.5.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.textile +10 -3
- data/README.rdoc +5 -7
- data/lib/cell.rb +9 -7
- data/lib/cell/active_helper.rb +6 -6
- data/lib/cell/caching.rb +6 -6
- data/lib/cell/rails.rb +49 -31
- data/lib/cell/test_case.rb +11 -11
- data/lib/cells.rb +3 -4
- data/lib/cells/helpers.rb +1 -1
- data/lib/cells/rails.rb +1 -3
- data/lib/cells/rails_compat.rb +12 -0
- data/lib/cells/version.rb +1 -1
- data/lib/generators/USAGE +30 -0
- data/lib/generators/cells/base.rb +14 -0
- data/lib/generators/cells/cell_generator.rb +14 -37
- data/lib/generators/erb/cell_generator.rb +17 -0
- data/lib/generators/haml/cell_generator.rb +20 -0
- data/lib/generators/rails/cell_generator.rb +16 -0
- data/lib/generators/{cells/templates → templates}/cell.rb +0 -0
- data/lib/generators/{cells/templates → templates}/cell_test.rb +0 -0
- data/lib/generators/{cells/templates → templates}/view.erb +1 -1
- data/lib/generators/{cells/templates → templates}/view.haml +0 -0
- data/lib/generators/test_unit/cell_generator.rb +14 -0
- data/test/cell_generator_test.rb +25 -20
- data/test/cell_module_test.rb +17 -0
- data/test/rails/cells_test.rb +24 -4
- data/test/rails/render_test.rb +18 -0
- metadata +14 -8
- data/lib/generators/cells/USAGE +0 -18
data/CHANGES.textile
CHANGED
@@ -1,9 +1,16 @@
|
|
1
1
|
h2. 3.5.0
|
2
2
|
|
3
3
|
h3. Changes
|
4
|
-
* Deprecated @opts, use #options now.
|
5
|
-
*
|
6
|
-
|
4
|
+
* Deprecated @opts, use #options now.
|
5
|
+
* Added state-args. State methods can now receive the options as method arguments. This should be the prefered way of parameter exchange with the outer world.
|
6
|
+
* #params, #request, and #config is now delegated to @parent_controller.
|
7
|
+
* The generator now is invoked as @rails g cell ...@
|
8
|
+
* The `--haml` option is no longer available.
|
9
|
+
* The `-t` option now is compatible with the rest of rails generators, now it is used as alias for `--test-framework`. Use the `-e` option as an alias of `--template-engine`
|
10
|
+
Thanks to Jorge Calás Lozano <calas@qvitta.net> for patching this in the most reasonable manner i could imagine.
|
11
|
+
* Privatized @#find_family_view_for_state@, @#render_view_for@, and all *ize methods in Cell::Rails.
|
12
|
+
* New signature: @#render_view_for(state, *args)@
|
13
|
+
|
7
14
|
h2. 3.4.4
|
8
15
|
|
9
16
|
h3. Changes
|
data/README.rdoc
CHANGED
@@ -29,7 +29,7 @@ Rails 2.3:
|
|
29
29
|
|
30
30
|
Creating a cell is nothing more than
|
31
31
|
|
32
|
-
$ rails generate
|
32
|
+
$ rails generate cell ShoppingCart display
|
33
33
|
create app/cells/
|
34
34
|
create app/cells/shopping_cart
|
35
35
|
create app/cells/shopping_cart_cell.rb
|
@@ -52,8 +52,8 @@ Feels like rendering a controller action. As additional encapsulation we pass th
|
|
52
52
|
Time to improve our cell code. Let's start with <tt>app/cells/shopping_cart_cell.rb</tt>:
|
53
53
|
|
54
54
|
class ShoppingCartCell < Cell::Rails
|
55
|
-
def display
|
56
|
-
user =
|
55
|
+
def display(args)
|
56
|
+
user = args[:user]
|
57
57
|
@items = user.items_in_cart
|
58
58
|
|
59
59
|
render # renders display.html.erb
|
@@ -93,13 +93,12 @@ The distinction between partials and views is making things more complex, so why
|
|
93
93
|
%p
|
94
94
|
= render :view => 'items'
|
95
95
|
|
96
|
-
|
97
96
|
== View Inheritance
|
98
97
|
|
99
98
|
This is where OOP comes back to your view.
|
100
99
|
|
101
100
|
* <b>Inherit code</b> into your cells by deriving more abstract cells.
|
102
|
-
* <b>Inherit views</b> from
|
101
|
+
* <b>Inherit views</b> from parent cells.
|
103
102
|
|
104
103
|
=== Builders
|
105
104
|
|
@@ -180,7 +179,6 @@ In order to copy the cells rake tasks to your app, run
|
|
180
179
|
Cells can do more.
|
181
180
|
|
182
181
|
<b>No Limits</b>:: Have as many cells in your page as you need - no limitation to your +render_cell+ calls.
|
183
|
-
<b>View Inheritance</b>:: Inherit view files dynamically from parent cells.
|
184
182
|
<b>Cell Nesting</b>:: Have complex cell hierarchies as you can call +render_cell+ within cells, too.
|
185
183
|
|
186
184
|
Go for it, you'll love it!
|
@@ -188,7 +186,7 @@ Go for it, you'll love it!
|
|
188
186
|
|
189
187
|
== LICENSE
|
190
188
|
|
191
|
-
Copyright (c) 2007-
|
189
|
+
Copyright (c) 2007-2011, Nick Sutterer
|
192
190
|
|
193
191
|
Copyright (c) 2007-2008, Solide ICT by Peter Bex and Bob Leers
|
194
192
|
|
data/lib/cell.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
module Cell
|
2
2
|
autoload :Caching, 'cell/caching'
|
3
|
-
|
3
|
+
|
4
4
|
extend ActiveSupport::Concern
|
5
|
-
|
5
|
+
|
6
6
|
module ClassMethods
|
7
7
|
def render_cell_for(controller, name, state, opts={})
|
8
|
-
cell = create_cell_for(controller, name, opts)
|
8
|
+
cell = create_cell_for(controller, name, opts) # DISCUSS: we always save options.
|
9
9
|
yield cell if block_given?
|
10
|
-
|
10
|
+
|
11
|
+
return cell.render_state(state, opts) if cell.method(state).arity == 1
|
12
|
+
cell.render_state(state) # backward-compat.
|
11
13
|
end
|
12
14
|
|
13
15
|
# Creates a cell instance. Note that this method calls builders which were attached to the
|
@@ -57,7 +59,7 @@ module Cell
|
|
57
59
|
def builders
|
58
60
|
@builders ||= []
|
59
61
|
end
|
60
|
-
|
62
|
+
|
61
63
|
# Return the default view path for +state+. Override this if you cell has a differing naming style.
|
62
64
|
def view_for_state(state)
|
63
65
|
"#{cell_name}/#{state}"
|
@@ -75,13 +77,13 @@ module Cell
|
|
75
77
|
def cell_name
|
76
78
|
name.underscore.sub(/_cell$/, '')
|
77
79
|
end
|
78
|
-
|
80
|
+
|
79
81
|
# The cell class constant for +cell_name+.
|
80
82
|
def class_from_cell_name(cell_name)
|
81
83
|
"#{cell_name}_cell".classify.constantize
|
82
84
|
end
|
83
85
|
end
|
84
|
-
|
86
|
+
|
85
87
|
module InstanceMethods
|
86
88
|
# Computes all possible paths for +state+ by traversing up the inheritance chain.
|
87
89
|
def possible_paths_for_state(state)
|
data/lib/cell/active_helper.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Cell::ActiveHelper
|
2
|
-
|
2
|
+
|
3
3
|
def self.included(base)
|
4
4
|
base.extend ClassMethods
|
5
|
-
|
5
|
+
|
6
6
|
base.class_inheritable_array :active_helpers
|
7
7
|
base.active_helpers = []
|
8
8
|
end
|
9
|
-
|
10
|
-
module ClassMethods
|
9
|
+
|
10
|
+
module ClassMethods
|
11
11
|
# The passed helpers will be imported in the view and thus be available in
|
12
12
|
# your template.
|
13
13
|
#
|
@@ -20,10 +20,10 @@ module Cell::ActiveHelper
|
|
20
20
|
active_helpers.push(*classes).uniq!
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def import_active_helpers_into(view)
|
25
25
|
return if self.class.active_helpers.blank?
|
26
|
-
|
26
|
+
|
27
27
|
# We simply assume if somebody's using #active_helper, it is already
|
28
28
|
# required.
|
29
29
|
view.extend ::ActiveHelper
|
data/lib/cell/caching.rb
CHANGED
@@ -4,7 +4,7 @@ require 'active_support/cache'
|
|
4
4
|
module Cell
|
5
5
|
module Caching
|
6
6
|
extend ActiveSupport::Concern
|
7
|
-
|
7
|
+
|
8
8
|
module ClassMethods
|
9
9
|
# Activate caching for the state <tt>state</tt>. If no other options are passed
|
10
10
|
# the view will be cached forever.
|
@@ -85,20 +85,20 @@ module Cell
|
|
85
85
|
def expire_cache_key(key, opts=nil)
|
86
86
|
cache_store.delete(key, opts)
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
def cache_configured?
|
90
90
|
::ActionController::Base.cache_configured?
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
-
def render_state(state)
|
95
|
-
return super(state) unless state_cached?(state)
|
94
|
+
def render_state(state, *args)
|
95
|
+
return super(state, *args) unless state_cached?(state)
|
96
96
|
|
97
97
|
key = cache_key(state, call_version_proc_for_state(state))
|
98
98
|
options = self.class.cache_options[state]
|
99
|
-
|
99
|
+
|
100
100
|
self.class.cache_store.fetch(key, options) do
|
101
|
-
super(state)
|
101
|
+
super(state, *args)
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
data/lib/cell/rails.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'abstract_controller'
|
2
|
+
require 'cell'
|
2
3
|
|
3
4
|
module Cell
|
4
5
|
class Rails < AbstractController::Base
|
@@ -6,37 +7,36 @@ module Cell
|
|
6
7
|
include AbstractController
|
7
8
|
include Rendering, Layouts, Helpers, Callbacks, Translation, Logger
|
8
9
|
include ActionController::RequestForgeryProtection
|
9
|
-
|
10
|
-
|
10
|
+
|
11
|
+
|
11
12
|
class View < ActionView::Base
|
12
13
|
def render(options = {}, locals = {}, &block)
|
13
14
|
if options[:state] or options[:view]
|
14
15
|
return @_controller.render(options, &block)
|
15
16
|
end
|
16
|
-
|
17
|
+
|
17
18
|
super
|
18
19
|
end
|
19
20
|
end
|
20
|
-
|
21
|
-
|
21
|
+
|
22
|
+
|
22
23
|
class MissingTemplate < ActionView::ActionViewError
|
23
24
|
def initialize(message, possible_paths)
|
24
25
|
super(message + " and possible paths #{possible_paths}")
|
25
26
|
end
|
26
27
|
end
|
27
|
-
|
28
|
-
|
28
|
+
|
29
|
+
|
29
30
|
module Rendering
|
30
31
|
# Invoke the state method for +state+ which usually renders something nice.
|
31
|
-
def render_state(state)
|
32
|
-
process(state)
|
32
|
+
def render_state(state, *args)
|
33
|
+
process(state, *args)
|
33
34
|
end
|
34
35
|
end
|
35
|
-
|
36
|
-
|
36
|
+
|
37
|
+
|
37
38
|
module Metal
|
38
|
-
|
39
|
-
delegate :session, :params, :to => :parent_controller
|
39
|
+
delegate :session, :params, :request, :config, :to => :parent_controller
|
40
40
|
end
|
41
41
|
|
42
42
|
|
@@ -48,27 +48,26 @@ module Cell
|
|
48
48
|
attr_accessor :options
|
49
49
|
|
50
50
|
abstract!
|
51
|
-
|
52
|
-
|
51
|
+
|
52
|
+
|
53
53
|
def initialize(parent_controller, options={})
|
54
54
|
@parent_controller = parent_controller
|
55
|
-
@_request = parent_controller.request # DISCUSS: delegate?
|
56
|
-
@_config = parent_controller.config.dup # FIXME: delegate!
|
57
55
|
@options = options
|
58
56
|
@opts = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :options)
|
59
57
|
end
|
60
|
-
|
58
|
+
|
61
59
|
def self.view_context_class
|
62
60
|
controller = self
|
63
|
-
|
61
|
+
|
64
62
|
View.class_eval do
|
65
63
|
include controller._helpers
|
66
64
|
include controller._routes.url_helpers
|
67
65
|
end
|
68
|
-
|
66
|
+
|
67
|
+
|
69
68
|
@view_context_class ||= View
|
70
69
|
end
|
71
|
-
|
70
|
+
|
72
71
|
def self.controller_path
|
73
72
|
@controller_path ||= name.sub(/Cell$/, '').underscore unless anonymous?
|
74
73
|
end
|
@@ -84,7 +83,7 @@ module Cell
|
|
84
83
|
# +:inline+:: Renders an inline template as state view. See ActionView::Base#render for details.
|
85
84
|
# +:file+:: Specifies the name of the file template to render.
|
86
85
|
# +:nothing+:: Doesn't invoke the rendering process.
|
87
|
-
# +:state+:: Instantly invokes another rendering cycle for the passed state and returns.
|
86
|
+
# +:state+:: Instantly invokes another rendering cycle for the passed state and returns. You may pass arbitrary state-args to the called state.
|
88
87
|
#
|
89
88
|
# Example:
|
90
89
|
# class MusicianCell < ::Cell::Base
|
@@ -118,15 +117,32 @@ module Cell
|
|
118
117
|
# of the page.
|
119
118
|
#
|
120
119
|
# Just use <tt>:view</tt> and enjoy.
|
121
|
-
|
122
|
-
|
120
|
+
#
|
121
|
+
# === Using states instead of helpers
|
122
|
+
#
|
123
|
+
# Sometimes it's useful to not only render a view but also invoke the associated state. This is
|
124
|
+
# especially helpful when replacing helpers. Do that with <tt>render :state</tt>.
|
125
|
+
#
|
126
|
+
# def show_cheap_item(item)
|
127
|
+
# render if item.price <= 1
|
128
|
+
# end
|
129
|
+
#
|
130
|
+
# A view could use this state in place of an odd helper.
|
131
|
+
#
|
132
|
+
# - @items.each do |item|
|
133
|
+
# = render({:state => :show_cheap_item}, item)
|
134
|
+
#
|
135
|
+
# This calls the state method which in turn will render its view - if the item isn't too expensive.
|
136
|
+
def render(*args)
|
137
|
+
render_view_for(self.action_name, *args)
|
123
138
|
end
|
124
139
|
|
140
|
+
private
|
125
141
|
# Climbs up the inheritance chain, looking for a view for the current +state+.
|
126
142
|
def find_family_view_for_state(state)
|
127
143
|
exception = nil
|
128
144
|
possible_paths = possible_paths_for_state(state)
|
129
|
-
|
145
|
+
|
130
146
|
possible_paths.each do |template_path|
|
131
147
|
begin
|
132
148
|
template = find_template(template_path)
|
@@ -134,19 +150,21 @@ module Cell
|
|
134
150
|
rescue ::ActionView::MissingTemplate => exception
|
135
151
|
end
|
136
152
|
end
|
137
|
-
|
153
|
+
|
138
154
|
raise MissingTemplate.new(exception.message, possible_paths)
|
139
155
|
end
|
140
|
-
|
156
|
+
|
141
157
|
# Renders the view belonging to the given state. Will raise ActionView::MissingTemplate
|
142
158
|
# if it can't find a view.
|
143
|
-
def render_view_for(
|
144
|
-
|
159
|
+
def render_view_for(state, *args)
|
160
|
+
opts = args.first.is_a?(::Hash) ? args.shift : {}
|
145
161
|
|
162
|
+
return "" if opts[:nothing]
|
163
|
+
|
146
164
|
rails_options = [:text, :inline, :file]
|
147
165
|
if (opts.keys & rails_options).present?
|
148
166
|
elsif opts[:state]
|
149
|
-
opts[:text] = render_state(opts[:state])
|
167
|
+
opts[:text] = render_state(opts[:state], *args)
|
150
168
|
else
|
151
169
|
opts = defaultize_render_options_for(opts, state)
|
152
170
|
template = find_family_view_for_state(opts[:view])
|
@@ -161,7 +179,7 @@ module Cell
|
|
161
179
|
def defaultize_render_options_for(opts, state)
|
162
180
|
opts.reverse_merge!(:view => state)
|
163
181
|
end
|
164
|
-
|
182
|
+
|
165
183
|
def sanitize_render_options(opts)
|
166
184
|
opts.except!(:view, :state)
|
167
185
|
end
|
data/lib/cell/test_case.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Cell
|
2
2
|
# Test your cells.
|
3
3
|
#
|
4
|
-
# This class is roughly equal to ActionController::TestCase, exposing the same semantics. It will try
|
4
|
+
# This class is roughly equal to ActionController::TestCase, exposing the same semantics. It will try
|
5
5
|
# to infer the tested cell name from the test name if you use declarative testing. You can also set it
|
6
6
|
# with TestCase.tests.
|
7
7
|
#
|
@@ -12,7 +12,7 @@ module Cell
|
|
12
12
|
#
|
13
13
|
# it "should be rendered nicely" do
|
14
14
|
# invoke :order_button, :items => @fixture_items
|
15
|
-
#
|
15
|
+
#
|
16
16
|
# assert_select "button", "Order now!"
|
17
17
|
# end
|
18
18
|
#
|
@@ -35,8 +35,8 @@ module Cell
|
|
35
35
|
#
|
36
36
|
# +invoke+:: Renders the passed +state+ with your tested cell. You may pass options like in #render_cell.
|
37
37
|
# +render_cell+:: As in your views. Will return the rendered view.
|
38
|
-
# +assert_selector+:: Like #assert_select except that the last argument is the html markup you wanna test.
|
39
|
-
# +cell+:: Gives you a cell instance for unit testing and stuff.
|
38
|
+
# +assert_selector+:: Like #assert_select except that the last argument is the html markup you wanna test.
|
39
|
+
# +cell+:: Gives you a cell instance for unit testing and stuff.
|
40
40
|
class TestCase < ActiveSupport::TestCase
|
41
41
|
module AssertSelect
|
42
42
|
# Invokes assert_select for the last argument, the +content+ string.
|
@@ -48,7 +48,7 @@ module Cell
|
|
48
48
|
def assert_selector(*args, &block)
|
49
49
|
rails_assert_select(HTML::Document.new(args.pop).root, *args, &block)
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
# Invokes assert_select on the markup set by the last #invoke.
|
53
53
|
#
|
54
54
|
# Example:
|
@@ -58,7 +58,7 @@ module Cell
|
|
58
58
|
super(HTML::Document.new(last_invoke).root, *args, &block)
|
59
59
|
end
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
module TestMethods
|
63
63
|
def setup
|
64
64
|
@controller = Class.new(ActionController::Base).new
|
@@ -68,7 +68,7 @@ module Cell
|
|
68
68
|
@controller.response = @response
|
69
69
|
@controller.params = {}
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
# Use this for functional tests of your application cells.
|
73
73
|
#
|
74
74
|
# Example:
|
@@ -78,7 +78,7 @@ module Cell
|
|
78
78
|
def render_cell(*args)
|
79
79
|
@controller.render_cell(*args)
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
# Builds an instance of <tt>name</tt>Cell for unit testing.
|
83
83
|
# Passes the optional block to <tt>cell.instance_eval</tt>.
|
84
84
|
#
|
@@ -111,18 +111,18 @@ module Cell
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
include TestMethods
|
116
116
|
include ActionDispatch::Assertions::SelectorAssertions # imports "their" #assert_select.
|
117
117
|
alias_method :rails_assert_select, :assert_select # i hate that.
|
118
118
|
include AssertSelect
|
119
|
-
|
119
|
+
|
120
120
|
extend ActionController::TestCase::Behavior::ClassMethods
|
121
121
|
class_attribute :_controller_class
|
122
122
|
|
123
123
|
|
124
124
|
attr_reader :last_invoke
|
125
|
-
|
125
|
+
|
126
126
|
def invoke(state, *args)
|
127
127
|
@last_invoke = self.class.controller_class.new(@controller, *args).render_state(state)
|
128
128
|
end
|
data/lib/cells.rb
CHANGED
@@ -58,12 +58,11 @@
|
|
58
58
|
# Beside your new class you'd provide a star-sprangled button view in +xmas_cart/order_button.haml+.
|
59
59
|
# When rendering the +cart+ state, the states as well as the "missing" views are inherited from ancesting cells,
|
60
60
|
# this is pretty DRY and object-oriented, isn't it?
|
61
|
-
require 'action_controller'
|
62
61
|
|
63
|
-
require 'cell'
|
64
|
-
require 'cells/rails'
|
65
62
|
require 'cell/rails'
|
66
|
-
require '
|
63
|
+
require 'cells/rails'
|
64
|
+
require 'cell/test_case' if Rails.env == "test"
|
65
|
+
require 'cells/rails_compat' # fixes a bug in Rails <3.0.4. # TODO: remove me as soon as we support 3.1, only.
|
67
66
|
|
68
67
|
module Cells
|
69
68
|
# Default view paths for Cells.
|
data/lib/cells/helpers.rb
CHANGED
data/lib/cells/rails.rb
CHANGED
@@ -41,8 +41,7 @@ module Cells
|
|
41
41
|
::Cell::Base.expire_cache_key(key, opts)
|
42
42
|
end
|
43
43
|
end
|
44
|
-
|
45
|
-
|
44
|
+
|
46
45
|
module ActionView
|
47
46
|
# See Cells::Rails::ActionController#render_cell.
|
48
47
|
def render_cell(name, state, opts = {}, &block)
|
@@ -53,7 +52,6 @@ module Cells
|
|
53
52
|
end
|
54
53
|
end
|
55
54
|
|
56
|
-
|
57
55
|
# Add extended ActionController behaviour.
|
58
56
|
ActionController::Base.class_eval do
|
59
57
|
include ::Cells::Rails::ActionController
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# TODO: remove me when Cells supports 3.1, only.
|
2
|
+
if Rails::VERSION::MINOR == 0 and Rails::VERSION::TINY <= 3
|
3
|
+
module AbstractController
|
4
|
+
module Callbacks
|
5
|
+
def process_action(method_name, *args) # Fixed in 3.0.4.
|
6
|
+
run_callbacks(:process_action, method_name) do
|
7
|
+
super
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/cells/version.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
Description:
|
2
|
+
Stubs out a new cell and its views. Pass the cell name, either
|
3
|
+
CamelCased or under_scored, and a list of views as arguments.
|
4
|
+
|
5
|
+
This generates a cell class in app/cells and view templates in
|
6
|
+
app/cells/cell_name/ directory.
|
7
|
+
|
8
|
+
Examples:
|
9
|
+
|
10
|
+
rails g cell ShoppingCart index
|
11
|
+
|
12
|
+
This will create these cell assets:
|
13
|
+
Cell:
|
14
|
+
app/cells/shopping_cart_cell.rb
|
15
|
+
Views:
|
16
|
+
app/cells/shopping_cart/index.html.erb
|
17
|
+
Test:
|
18
|
+
test/cells/shopping_cart_cell_test.rb
|
19
|
+
|
20
|
+
|
21
|
+
rails g cell main_menu display sort -e haml -t rspec
|
22
|
+
|
23
|
+
This will create these cell assets:
|
24
|
+
Cell:
|
25
|
+
app/cells/main_menu_cell.rb
|
26
|
+
Views:
|
27
|
+
app/cells/main_menu/display.html.haml
|
28
|
+
app/cells/main_menu/sort.html.haml
|
29
|
+
Spec:
|
30
|
+
spec/cells/main_menu_cell_spec.rb
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/named_base'
|
3
|
+
|
4
|
+
module Cells
|
5
|
+
module Generators
|
6
|
+
class Base < ::Rails::Generators::NamedBase
|
7
|
+
class_option :template_engine
|
8
|
+
class_option :test_framework
|
9
|
+
|
10
|
+
argument :actions, :type => :array, :default => [], :banner => "action action"
|
11
|
+
check_class_collision :suffix => "Cell"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,45 +1,22 @@
|
|
1
|
-
require '
|
2
|
-
require 'rails/generators/named_base'
|
1
|
+
require 'generators/cells/base'
|
3
2
|
|
4
3
|
module Cells
|
5
4
|
module Generators
|
6
|
-
class CellGenerator < ::
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
11
|
-
|
12
|
-
class_option :view_engine, :type => :string, :aliases => "-t", :desc => "Template engine for the views. Available options are 'erb' and 'haml'.", :default => "erb"
|
13
|
-
class_option :haml, :type => :boolean, :default => false
|
14
|
-
|
15
|
-
|
5
|
+
class CellGenerator < ::Cells::Generators::Base
|
6
|
+
source_root File.expand_path('../../templates', __FILE__)
|
7
|
+
|
16
8
|
def create_cell_file
|
17
9
|
template 'cell.rb', File.join('app/cells', class_path, "#{file_name}_cell.rb")
|
18
10
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
def create_test
|
29
|
-
@states = actions
|
30
|
-
template 'cell_test.rb', File.join('test/cells/', "#{file_name}_cell_test.rb")
|
31
|
-
end
|
32
|
-
|
33
|
-
protected
|
34
|
-
|
35
|
-
def create_views_for(engine)
|
36
|
-
for state in actions do
|
37
|
-
@state = state
|
38
|
-
@path = File.join('app/cells', file_name, "#{state}.html.#{engine}")
|
39
|
-
|
40
|
-
template "view.#{engine}", @path
|
41
|
-
end
|
11
|
+
|
12
|
+
hook_for(:template_engine)
|
13
|
+
hook_for(:test_framework)
|
14
|
+
|
15
|
+
def say_deprecated
|
16
|
+
say "====> This generator is now DEPRECATED. <====", :red
|
17
|
+
say "Please use:"
|
18
|
+
say " rails g cell #{class_name} #{actions.join(' ')}"
|
42
19
|
end
|
43
|
-
end
|
20
|
+
end
|
44
21
|
end
|
45
|
-
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'generators/cells/base'
|
2
|
+
|
3
|
+
module Erb
|
4
|
+
module Generators
|
5
|
+
class CellGenerator < ::Cells::Generators::Base
|
6
|
+
source_root File.expand_path('../../templates', __FILE__)
|
7
|
+
|
8
|
+
def create_views
|
9
|
+
for state in actions do
|
10
|
+
@state = state
|
11
|
+
@path = File.join('app/cells', file_name, "#{state}.html.erb")
|
12
|
+
template "view.erb", @path
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'generators/cells/base'
|
2
|
+
|
3
|
+
module Haml
|
4
|
+
module Generators
|
5
|
+
class CellGenerator < ::Cells::Generators::Base
|
6
|
+
source_root File.expand_path('../../templates', __FILE__)
|
7
|
+
|
8
|
+
def create_views
|
9
|
+
for state in actions do
|
10
|
+
@state = state
|
11
|
+
@path = File.join('app/cells', file_name, "#{state}.html.haml")
|
12
|
+
|
13
|
+
template "view.haml", @path
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'generators/cells/base'
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Generators
|
5
|
+
class CellGenerator < ::Cells::Generators::Base
|
6
|
+
source_root File.expand_path('../../templates', __FILE__)
|
7
|
+
|
8
|
+
def create_cell_file
|
9
|
+
template 'cell.rb', File.join('app/cells', class_path, "#{file_name}_cell.rb")
|
10
|
+
end
|
11
|
+
|
12
|
+
hook_for(:template_engine)
|
13
|
+
hook_for(:test_framework)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'generators/cells/base'
|
2
|
+
|
3
|
+
module TestUnit
|
4
|
+
module Generators
|
5
|
+
class CellGenerator < ::Cells::Generators::Base
|
6
|
+
source_root File.expand_path('../../templates', __FILE__)
|
7
|
+
|
8
|
+
def create_test
|
9
|
+
@states = actions
|
10
|
+
template 'cell_test.rb', File.join('test/cells/', "#{file_name}_cell_test.rb")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/test/cell_generator_test.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
|
3
2
|
require 'generators/cells/cell_generator'
|
4
3
|
|
5
4
|
class CellGeneratorTest < Rails::Generators::TestCase
|
6
5
|
destination File.join(Rails.root, "tmp")
|
7
6
|
setup :prepare_destination
|
8
7
|
tests ::Cells::Generators::CellGenerator
|
9
|
-
|
8
|
+
|
10
9
|
context "Running script/generate cell" do
|
11
10
|
context "Blog post latest" do
|
11
|
+
|
12
12
|
should "create the standard assets" do
|
13
|
-
|
14
13
|
run_generator %w(Blog post latest)
|
15
|
-
|
14
|
+
|
16
15
|
assert_file "app/cells/blog_cell.rb", /class BlogCell < Cell::Rails/
|
17
16
|
assert_file "app/cells/blog_cell.rb", /def post/
|
18
17
|
assert_file "app/cells/blog_cell.rb", /def latest/
|
@@ -20,12 +19,15 @@ class CellGeneratorTest < Rails::Generators::TestCase
|
|
20
19
|
assert_file "app/cells/blog/post.html.erb", %r(<p>)
|
21
20
|
assert_file "app/cells/blog/latest.html.erb", %r(app/cells/blog/latest\.html\.erb)
|
22
21
|
|
23
|
-
|
22
|
+
|
23
|
+
assert_no_file "app/cells/blog/post.html.haml"
|
24
|
+
assert_no_file "app/cells/blog/post.html.haml"
|
25
|
+
assert_no_file "app/cells/blog/latest.html.haml"
|
24
26
|
end
|
25
|
-
|
26
|
-
should "create haml assets with
|
27
|
-
run_generator %w(Blog post latest
|
28
|
-
|
27
|
+
|
28
|
+
should "create haml assets with -e haml" do
|
29
|
+
run_generator %w(Blog post latest -e haml)
|
30
|
+
|
29
31
|
assert_file "app/cells/blog_cell.rb", /class BlogCell < Cell::Rails/
|
30
32
|
assert_file "app/cells/blog_cell.rb", /def post/
|
31
33
|
assert_file "app/cells/blog_cell.rb", /def latest/
|
@@ -33,21 +35,24 @@ class CellGeneratorTest < Rails::Generators::TestCase
|
|
33
35
|
assert_file "app/cells/blog/post.html.haml", %r(%p)
|
34
36
|
assert_file "app/cells/blog/latest.html.haml", %r(app/cells/blog/latest\.html\.haml)
|
35
37
|
|
36
|
-
|
38
|
+
|
39
|
+
assert_no_file "app/cells/blog/post.html.erb"
|
40
|
+
assert_no_file "app/cells/blog/post.html.erb"
|
41
|
+
assert_no_file "app/cells/blog/latest.html.erb"
|
37
42
|
end
|
38
|
-
|
39
|
-
should "create
|
40
|
-
run_generator %w(Blog post latest -t
|
41
|
-
|
42
|
-
assert_file "app/cells/blog_cell.rb", /class BlogCell < Cell::Rails/
|
43
|
-
assert_file "app/cells/blog_cell.rb", /def post/
|
44
|
-
assert_file "app/cells/blog_cell.rb", /def latest/
|
45
|
-
assert_file "app/cells/blog/post.html.haml", %r(app/cells/blog/post\.html\.haml)
|
46
|
-
assert_file "app/cells/blog/post.html.haml", %r(%p)
|
47
|
-
assert_file "app/cells/blog/latest.html.haml", %r(app/cells/blog/latest\.html\.haml)
|
43
|
+
|
44
|
+
should "create test_unit assets with -t test_unit" do
|
45
|
+
run_generator %w(Blog post latest -t test_unit)
|
48
46
|
|
49
47
|
assert_file "test/cells/blog_cell_test.rb"
|
50
48
|
end
|
49
|
+
|
50
|
+
should "create test_unit assets with -t rspec" do
|
51
|
+
run_generator %w(Blog post latest -t rspec)
|
52
|
+
|
53
|
+
assert_no_file "test/cells/blog_cell_test.rb"
|
54
|
+
end
|
55
|
+
|
51
56
|
end
|
52
57
|
end
|
53
58
|
end
|
data/test/cell_module_test.rb
CHANGED
@@ -16,6 +16,7 @@ class CellModuleTest < ActiveSupport::TestCase
|
|
16
16
|
|
17
17
|
context "Cell::Base" do
|
18
18
|
|
19
|
+
# FUNCTIONAL:
|
19
20
|
context "render_cell_for" do
|
20
21
|
should "render the actual cell" do
|
21
22
|
assert_equal "Doo", Cell::Base.render_cell_for(@controller, :bassist, :play)
|
@@ -32,7 +33,23 @@ class CellModuleTest < ActiveSupport::TestCase
|
|
32
33
|
assert flag
|
33
34
|
end
|
34
35
|
|
36
|
+
should "make options available in #options if not receiving state-args" do
|
37
|
+
BassistCell.class_eval do
|
38
|
+
def listen
|
39
|
+
render :text => options[:note]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
assert_equal "C-minor", Cell::Base.render_cell_for(@controller, :bassist, :listen, :note => "C-minor")
|
43
|
+
end
|
35
44
|
|
45
|
+
should "pass options as state-args and still set #options otherwise" do
|
46
|
+
BassistCell.class_eval do
|
47
|
+
def listen(args)
|
48
|
+
render :text => args[:note] + options[:note].to_s
|
49
|
+
end
|
50
|
+
end
|
51
|
+
assert_equal "C-minorC-minor", Cell::Base.render_cell_for(@controller, :bassist, :listen, :note => "C-minor")
|
52
|
+
end
|
36
53
|
end
|
37
54
|
|
38
55
|
context "create_cell_for" do
|
data/test/rails/cells_test.rb
CHANGED
@@ -16,6 +16,26 @@ class RailsCellsTest < ActiveSupport::TestCase
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
context "#render_state" do
|
20
|
+
should "work without args" do
|
21
|
+
BassistCell.class_eval do
|
22
|
+
def listen
|
23
|
+
render :text => options[:note]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
assert_equal "D", cell(:bassist, :note => "D").render_state(:listen)
|
27
|
+
end
|
28
|
+
|
29
|
+
should "accept state-args" do
|
30
|
+
BassistCell.class_eval do
|
31
|
+
def listen(args)
|
32
|
+
render :text => args[:note]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
assert_equal "D", cell(:bassist).render_state(:listen, :note => "D")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
19
39
|
context "A rails cell" do
|
20
40
|
should "respond to view_paths" do
|
21
41
|
assert_kind_of ActionView::PathSet, Cell::Rails.view_paths, "must be a PathSet for proper template caching/reloading (see issue#2)"
|
@@ -52,13 +72,13 @@ class RailsCellsTest < ActiveSupport::TestCase
|
|
52
72
|
|
53
73
|
context "invoking defaultize_render_options_for" do
|
54
74
|
should "set default values" do
|
55
|
-
options = cell(:bassist).defaultize_render_options_for
|
75
|
+
options = cell(:bassist).send(:defaultize_render_options_for, {}, :play)
|
56
76
|
|
57
77
|
assert_equal :play, options[:view]
|
58
78
|
end
|
59
79
|
|
60
80
|
should "allow overriding defaults" do
|
61
|
-
assert cell(:bassist).defaultize_render_options_for
|
81
|
+
assert cell(:bassist).send(:defaultize_render_options_for, {:view => :slap}, :play)[:view] == :slap
|
62
82
|
end
|
63
83
|
end
|
64
84
|
|
@@ -72,11 +92,11 @@ class RailsCellsTest < ActiveSupport::TestCase
|
|
72
92
|
end
|
73
93
|
|
74
94
|
should "return play.html.erb" do
|
75
|
-
assert_equal "bassist/play", cell(:bassist).
|
95
|
+
assert_equal "bassist/play", cell(:bassist).send(:find_family_view_for_state, :play).virtual_path
|
76
96
|
end
|
77
97
|
|
78
98
|
should "find inherited play.html.erb" do
|
79
|
-
assert_equal "bassist/play", cell(:bad_guitarist).
|
99
|
+
assert_equal "bassist/play", cell(:bad_guitarist).send(:find_family_view_for_state, :play).virtual_path
|
80
100
|
end
|
81
101
|
|
82
102
|
should_eventually "find the EN-version if i18n instructs" do
|
data/test/rails/render_test.rb
CHANGED
@@ -49,6 +49,24 @@ class RailsRenderTest < ActiveSupport::TestCase
|
|
49
49
|
assert_equal "Snooore", render_cell(:bassist, :sleep)
|
50
50
|
end
|
51
51
|
|
52
|
+
should "accept the :state option with state-args" do
|
53
|
+
BassistCell.class_eval do
|
54
|
+
def listen(band, song)
|
55
|
+
render :text => "Listening to #{band}: #{song}"
|
56
|
+
end
|
57
|
+
def groove; render({:state => :listen}, "Thin Lizzy", "Southbound"); end
|
58
|
+
end
|
59
|
+
assert_equal "Listening to Thin Lizzy: Southbound", render_cell(:bassist, :groove)
|
60
|
+
|
61
|
+
BassistCell.class_eval do
|
62
|
+
def listen(args)
|
63
|
+
render :text => "Listening to #{args[:band]}"
|
64
|
+
end
|
65
|
+
def groove; render({:state => :listen}, :band => "Belvedere"); end
|
66
|
+
end
|
67
|
+
assert_equal "Listening to Belvedere", render_cell(:bassist, :groove)
|
68
|
+
end
|
69
|
+
|
52
70
|
should "accept the :state option" do
|
53
71
|
BassistCell.class_eval do
|
54
72
|
def play; render; end
|
metadata
CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 3
|
7
7
|
- 5
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 3.5.0.
|
9
|
+
- beta2
|
10
|
+
version: 3.5.0.beta2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nick Sutterer
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-02-04 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -85,13 +85,19 @@ files:
|
|
85
85
|
- lib/cells/helpers.rb
|
86
86
|
- lib/cells/helpers/capture_helper.rb
|
87
87
|
- lib/cells/rails.rb
|
88
|
+
- lib/cells/rails_compat.rb
|
88
89
|
- lib/cells/version.rb
|
89
|
-
- lib/generators/
|
90
|
+
- lib/generators/USAGE
|
91
|
+
- lib/generators/cells/base.rb
|
90
92
|
- lib/generators/cells/cell_generator.rb
|
91
|
-
- lib/generators/
|
92
|
-
- lib/generators/
|
93
|
-
- lib/generators/
|
94
|
-
- lib/generators/
|
93
|
+
- lib/generators/erb/cell_generator.rb
|
94
|
+
- lib/generators/haml/cell_generator.rb
|
95
|
+
- lib/generators/rails/cell_generator.rb
|
96
|
+
- lib/generators/templates/cell.rb
|
97
|
+
- lib/generators/templates/cell_test.rb
|
98
|
+
- lib/generators/templates/view.erb
|
99
|
+
- lib/generators/templates/view.haml
|
100
|
+
- lib/generators/test_unit/cell_generator.rb
|
95
101
|
- test/active_helper_test.rb
|
96
102
|
- test/app/cells/bad_guitarist/_dii.html.erb
|
97
103
|
- test/app/cells/bad_guitarist_cell.rb
|
data/lib/generators/cells/USAGE
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
Description:
|
2
|
-
Stubs out a new cell and its views. Pass the cell name, either
|
3
|
-
CamelCased or under_scored, and a list of views as arguments.
|
4
|
-
|
5
|
-
This generates a cell class in app/cells and view templates in
|
6
|
-
app/cells/cell_name.
|
7
|
-
|
8
|
-
Examples:
|
9
|
-
|
10
|
-
rails g cells:cell ShoppingCart index --haml
|
11
|
-
|
12
|
-
This will create these cell assets:
|
13
|
-
Cell:
|
14
|
-
app/cells/shopping_cart_cell.rb
|
15
|
-
Views:
|
16
|
-
app/cells/shopping_cart/index.html.haml
|
17
|
-
Test:
|
18
|
-
test/cells/shopping_cart_cell_test
|