cells 3.5.4 → 3.5.5
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/CHANGES.textile +9 -1
- data/README.rdoc +5 -5
- data/cells.gemspec +2 -1
- data/lib/cell/rails.rb +9 -18
- data/lib/cells.rb +1 -1
- data/lib/cells/version.rb +1 -1
- data/lib/generators/cells/base.rb +5 -0
- data/lib/generators/cells/cell_generator.rb +3 -10
- data/lib/generators/erb/cell_generator.rb +1 -1
- data/lib/generators/haml/cell_generator.rb +1 -2
- data/lib/generators/rails/cell_generator.rb +1 -1
- data/test/cell_generator_test.rb +47 -36
- metadata +23 -8
data/CHANGES.textile
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
-
h2. 3.5.
|
1
|
+
h2. 3.5.5
|
2
|
+
|
3
|
+
h3. Bugfixes
|
4
|
+
* The generator now places views of namespaced cells into the correct directory. E.g. `rails g Blog::Post display` puts views to `app/cells/blog/post/display.html.erb`.
|
5
|
+
|
6
|
+
h3. Changes
|
7
|
+
* Gem dependencies changed, we now require @actionpack@ and @railties@ >= 3.0.0 instead of @rails@.
|
8
|
+
|
9
|
+
h2. 3.5.4
|
2
10
|
|
3
11
|
h3. Bugfixes
|
4
12
|
* state-args work even if your state method receives optional arguments or default values, like @def show(user, age=18)@.
|
data/README.rdoc
CHANGED
@@ -45,7 +45,7 @@ Now, render your cart. Why not put it in <tt>layouts/application.html.erb</tt> f
|
|
45
45
|
<div id="header">
|
46
46
|
<%= render_cell :shopping_cart, :display, :user => @current_user %>
|
47
47
|
|
48
|
-
Feels like rendering a controller action.
|
48
|
+
Feels like rendering a controller action. For good encapsulation we pass the current +user+ from outside into the cell - a dependency injection.
|
49
49
|
|
50
50
|
== Code
|
51
51
|
|
@@ -60,12 +60,12 @@ Time to improve our cell code. Let's start with <tt>app/cells/shopping_cart_cell
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
Is that a controller? Hell, yeah. We even got a
|
63
|
+
Is that a controller? Hell, yeah. We even got a +#render+ method as we know it from the good ol' +ActionController+.
|
64
64
|
|
65
65
|
|
66
66
|
== Views
|
67
67
|
|
68
|
-
Since a plain call to
|
68
|
+
Since a plain call to +#render+ will start rendering <tt>app/cells/shopping_cart/display.html.haml</tt> we should put some meaningful markup there.
|
69
69
|
|
70
70
|
#cart
|
71
71
|
You have #{@items.size} items in your shopping cart.
|
@@ -131,9 +131,9 @@ You can expand the state's cache key - why not use a versioner block to do just
|
|
131
131
|
options[:items].md5
|
132
132
|
end
|
133
133
|
|
134
|
-
The return value is appended to the state key: <tt>"cells/shopping_cart/display/0ecb1360644ce665a4ef"</tt>.
|
134
|
+
The block's return value is appended to the state key: <tt>"cells/shopping_cart/display/0ecb1360644ce665a4ef"</tt>.
|
135
135
|
|
136
|
-
API
|
136
|
+
Check the {API to learn more}[http://rdoc.info/gems/cells/Cell/Caching/ClassMethods#cache-instance_method].
|
137
137
|
|
138
138
|
== Testing
|
139
139
|
|
data/cells.gemspec
CHANGED
@@ -19,7 +19,8 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
-
s.add_dependency "
|
22
|
+
s.add_dependency "actionpack", "~> 3.0.0"
|
23
|
+
s.add_dependency "railties", "~> 3.0.0"
|
23
24
|
|
24
25
|
s.add_development_dependency "shoulda"
|
25
26
|
s.add_development_dependency "haml"
|
data/lib/cell/rails.rb
CHANGED
@@ -157,35 +157,26 @@ module Cell
|
|
157
157
|
|
158
158
|
raise MissingTemplate.new(exception.message, possible_paths)
|
159
159
|
end
|
160
|
-
|
160
|
+
|
161
161
|
# Renders the view belonging to the given state. Will raise ActionView::MissingTemplate
|
162
162
|
# if it can't find a view.
|
163
163
|
def render_view_for(state, *args)
|
164
164
|
opts = args.first.is_a?(::Hash) ? args.shift : {}
|
165
165
|
|
166
166
|
return "" if opts[:nothing]
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
elsif opts[:
|
171
|
-
opts
|
172
|
-
|
173
|
-
opts = defaultize_render_options_for(opts, state)
|
174
|
-
template = find_family_view_for_state(opts[:view])
|
175
|
-
opts[:template] = template
|
167
|
+
|
168
|
+
if opts[:state]
|
169
|
+
opts[:text] = render_state(opts.delete(:state), *args)
|
170
|
+
elsif (opts.keys & [:text, :inline, :file]).blank?
|
171
|
+
opts = defaultize_render_options_for(opts, state)
|
172
|
+
opts[:template] = find_family_view_for_state(opts.delete(:view))
|
176
173
|
end
|
177
|
-
|
178
|
-
opts = sanitize_render_options(opts)
|
174
|
+
|
179
175
|
render_to_string(opts).html_safe # ActionView::Template::Text doesn't do that for us.
|
180
176
|
end
|
181
|
-
|
182
|
-
# Defaultize the passed options from #render.
|
177
|
+
|
183
178
|
def defaultize_render_options_for(opts, state)
|
184
179
|
opts.reverse_merge!(:view => state)
|
185
180
|
end
|
186
|
-
|
187
|
-
def sanitize_render_options(opts)
|
188
|
-
opts.except!(:view, :state)
|
189
|
-
end
|
190
181
|
end
|
191
182
|
end
|
data/lib/cells.rb
CHANGED
@@ -47,7 +47,7 @@
|
|
47
47
|
#
|
48
48
|
# == View inheritance
|
49
49
|
#
|
50
|
-
# Unlike controllers, Cells can form a class hierarchy. Even
|
50
|
+
# Unlike controllers, Cells can form a class hierarchy. Even views are inherited, which is pretty useful
|
51
51
|
# when overriding only small parts of the view.
|
52
52
|
#
|
53
53
|
# So if you'd need a special "Order!" button with sparkling stars on christmas, your cell would go like this.
|
data/lib/cells/version.rb
CHANGED
@@ -1,17 +1,10 @@
|
|
1
|
-
require 'generators/
|
1
|
+
require 'generators/rails/cell_generator'
|
2
2
|
|
3
3
|
module Cells
|
4
4
|
module Generators
|
5
|
-
class CellGenerator < ::
|
5
|
+
class CellGenerator < ::Rails::Generators::CellGenerator
|
6
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
|
-
|
7
|
+
|
15
8
|
def say_deprecated
|
16
9
|
say "====> This generator is now DEPRECATED. <====", :red
|
17
10
|
say "Please use:"
|
@@ -8,7 +8,7 @@ module Erb
|
|
8
8
|
def create_views
|
9
9
|
for state in actions do
|
10
10
|
@state = state
|
11
|
-
@path = File.join(
|
11
|
+
@path = File.join(base_path, "#{state}.html.erb") #base_path defined in Cells::Generators::Base.
|
12
12
|
template "view.erb", @path
|
13
13
|
end
|
14
14
|
end
|
@@ -8,8 +8,7 @@ module Haml
|
|
8
8
|
def create_views
|
9
9
|
for state in actions do
|
10
10
|
@state = state
|
11
|
-
@path = File.join(
|
12
|
-
|
11
|
+
@path = File.join(base_path, "#{state}.html.haml") #base_path defined in Cells::Generators::Base.
|
13
12
|
template "view.haml", @path
|
14
13
|
end
|
15
14
|
end
|
data/test/cell_generator_test.rb
CHANGED
@@ -1,58 +1,69 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'generators/
|
2
|
+
require 'generators/rails/cell_generator'
|
3
3
|
|
4
4
|
class CellGeneratorTest < Rails::Generators::TestCase
|
5
5
|
destination File.join(Rails.root, "tmp")
|
6
6
|
setup :prepare_destination
|
7
|
-
tests ::
|
7
|
+
tests ::Rails::Generators::CellGenerator
|
8
8
|
|
9
|
-
context "
|
10
|
-
|
9
|
+
context "CellGenerator" do
|
10
|
+
should "create the standard assets" do
|
11
|
+
run_generator %w(Blog post latest)
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
assert_file "app/cells/blog_cell.rb", /class BlogCell < Cell::Rails/
|
14
|
+
assert_file "app/cells/blog_cell.rb", /def post/
|
15
|
+
assert_file "app/cells/blog_cell.rb", /def latest/
|
16
|
+
assert_file "app/cells/blog/post.html.erb", %r(app/cells/blog/post\.html\.erb)
|
17
|
+
assert_file "app/cells/blog/post.html.erb", %r(<p>)
|
18
|
+
assert_file "app/cells/blog/latest.html.erb", %r(app/cells/blog/latest\.html\.erb)
|
14
19
|
|
15
|
-
assert_file "app/cells/blog_cell.rb", /class BlogCell < Cell::Rails/
|
16
|
-
assert_file "app/cells/blog_cell.rb", /def post/
|
17
|
-
assert_file "app/cells/blog_cell.rb", /def latest/
|
18
|
-
assert_file "app/cells/blog/post.html.erb", %r(app/cells/blog/post\.html\.erb)
|
19
|
-
assert_file "app/cells/blog/post.html.erb", %r(<p>)
|
20
|
-
assert_file "app/cells/blog/latest.html.erb", %r(app/cells/blog/latest\.html\.erb)
|
21
20
|
|
21
|
+
assert_no_file "app/cells/blog/post.html.haml"
|
22
|
+
assert_no_file "app/cells/blog/post.html.haml"
|
23
|
+
assert_no_file "app/cells/blog/latest.html.haml"
|
24
|
+
end
|
25
|
+
|
26
|
+
should "work with namespaces" do
|
27
|
+
run_generator %w(Blog::Post latest)
|
22
28
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
29
|
+
assert_file "app/cells/blog/post_cell.rb", /class Blog::PostCell < Cell::Rails/
|
30
|
+
assert_file "app/cells/blog/post_cell.rb", /def latest/
|
31
|
+
assert_file "app/cells/blog/post/latest.html.erb", %r(app/cells/blog/post/latest\.html\.erb)
|
32
|
+
end
|
33
|
+
|
34
|
+
should "work with namespaces and haml" do
|
35
|
+
run_generator %w(Blog::Post latest -e haml)
|
27
36
|
|
28
|
-
|
29
|
-
|
37
|
+
assert_file "app/cells/blog/post_cell.rb", /class Blog::PostCell < Cell::Rails/
|
38
|
+
assert_file "app/cells/blog/post/latest.html.haml", %r(app/cells/blog/post/latest\.html\.haml)
|
39
|
+
end
|
30
40
|
|
31
|
-
|
32
|
-
|
33
|
-
assert_file "app/cells/blog_cell.rb", /def latest/
|
34
|
-
assert_file "app/cells/blog/post.html.haml", %r(app/cells/blog/post\.html\.haml)
|
35
|
-
assert_file "app/cells/blog/post.html.haml", %r(%p)
|
36
|
-
assert_file "app/cells/blog/latest.html.haml", %r(app/cells/blog/latest\.html\.haml)
|
41
|
+
should "create haml assets with -e haml" do
|
42
|
+
run_generator %w(Blog post latest -e haml)
|
37
43
|
|
44
|
+
assert_file "app/cells/blog_cell.rb", /class BlogCell < Cell::Rails/
|
45
|
+
assert_file "app/cells/blog_cell.rb", /def post/
|
46
|
+
assert_file "app/cells/blog_cell.rb", /def latest/
|
47
|
+
assert_file "app/cells/blog/post.html.haml", %r(app/cells/blog/post\.html\.haml)
|
48
|
+
assert_file "app/cells/blog/post.html.haml", %r(%p)
|
49
|
+
assert_file "app/cells/blog/latest.html.haml", %r(app/cells/blog/latest\.html\.haml)
|
38
50
|
|
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"
|
42
|
-
end
|
43
51
|
|
44
|
-
|
45
|
-
|
52
|
+
assert_no_file "app/cells/blog/post.html.erb"
|
53
|
+
assert_no_file "app/cells/blog/post.html.erb"
|
54
|
+
assert_no_file "app/cells/blog/latest.html.erb"
|
55
|
+
end
|
46
56
|
|
47
|
-
|
48
|
-
|
57
|
+
should "create test_unit assets with -t test_unit" do
|
58
|
+
run_generator %w(Blog post latest -t test_unit)
|
49
59
|
|
50
|
-
|
51
|
-
|
60
|
+
assert_file "test/cells/blog_cell_test.rb"
|
61
|
+
end
|
52
62
|
|
53
|
-
|
54
|
-
|
63
|
+
should "create test_unit assets with -t rspec" do
|
64
|
+
run_generator %w(Blog post latest -t rspec)
|
55
65
|
|
66
|
+
assert_no_file "test/cells/blog_cell_test.rb"
|
56
67
|
end
|
57
68
|
end
|
58
69
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 3
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 3.5.
|
8
|
+
- 5
|
9
|
+
version: 3.5.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Nick Sutterer
|
@@ -14,11 +14,11 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-03-08 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
21
|
+
name: actionpack
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
@@ -33,9 +33,24 @@ dependencies:
|
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
36
|
+
name: railties
|
37
37
|
prerelease: false
|
38
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 3
|
45
|
+
- 0
|
46
|
+
- 0
|
47
|
+
version: 3.0.0
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: shoulda
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
39
54
|
none: false
|
40
55
|
requirements:
|
41
56
|
- - ">="
|
@@ -44,11 +59,11 @@ dependencies:
|
|
44
59
|
- 0
|
45
60
|
version: "0"
|
46
61
|
type: :development
|
47
|
-
version_requirements: *
|
62
|
+
version_requirements: *id003
|
48
63
|
- !ruby/object:Gem::Dependency
|
49
64
|
name: haml
|
50
65
|
prerelease: false
|
51
|
-
requirement: &
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
67
|
none: false
|
53
68
|
requirements:
|
54
69
|
- - ">="
|
@@ -57,7 +72,7 @@ dependencies:
|
|
57
72
|
- 0
|
58
73
|
version: "0"
|
59
74
|
type: :development
|
60
|
-
version_requirements: *
|
75
|
+
version_requirements: *id004
|
61
76
|
description: Cells are view components for Rails. They are lightweight controllers, can be rendered in views and thus provide an elegant and fast way for encapsulation and component-orientation.
|
62
77
|
email:
|
63
78
|
- apotonick@gmail.com
|