cells 3.5.5 → 3.5.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ h2. 3.5.6
2
+
3
+ h3. Changes
4
+ * Added a generator for slim. Use it with `-e slim` when generating.
5
+
6
+
1
7
  h2. 3.5.5
2
8
 
3
9
  h3. Bugfixes
@@ -6,6 +12,7 @@ h3. Bugfixes
6
12
  h3. Changes
7
13
  * Gem dependencies changed, we now require @actionpack@ and @railties@ >= 3.0.0 instead of @rails@.
8
14
 
15
+
9
16
  h2. 3.5.4
10
17
 
11
18
  h3. Bugfixes
@@ -29,7 +29,7 @@ Rails 2.3:
29
29
 
30
30
  Creating a cell is nothing more than
31
31
 
32
- $ rails generate cell ShoppingCart display -t haml
32
+ $ rails generate cell ShoppingCart display -e haml
33
33
  create app/cells/
34
34
  create app/cells/shopping_cart
35
35
  create app/cells/shopping_cart_cell.rb
@@ -40,7 +40,7 @@ That looks very familiar.
40
40
 
41
41
  == Render the cell
42
42
 
43
- Now, render your cart. Why not put it in <tt>layouts/application.html.erb</tt> for now?
43
+ Now, render your cart. Why not put it in <tt>layouts/application.html.erb</tt> for now?
44
44
 
45
45
  <div id="header">
46
46
  <%= render_cell :shopping_cart, :display, :user => @current_user %>
@@ -51,11 +51,11 @@ Feels like rendering a controller action. For good encapsulation we pass the cur
51
51
 
52
52
  Time to improve our cell code. Let's start with <tt>app/cells/shopping_cart_cell.rb</tt>:
53
53
 
54
- class ShoppingCartCell < Cell::Rails
54
+ class ShoppingCartCell < Cell::Rails
55
55
  def display(args)
56
56
  user = args[:user]
57
57
  @items = user.items_in_cart
58
-
58
+
59
59
  render # renders display.html.haml
60
60
  end
61
61
  end
@@ -68,8 +68,8 @@ Is that a controller? Hell, yeah. We even got a +#render+ method as we know it f
68
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
- You have #{@items.size} items in your shopping cart.
72
-
71
+ You have #{@items.size} items in your shopping cart.
72
+
73
73
  === ERB? Haml? Builder?
74
74
 
75
75
  Yes, Cells support all template types that are supported by Rails itself. Remember- it's a controller!
@@ -78,7 +78,7 @@ Yes, Cells support all template types that are supported by Rails itself. Rememb
78
78
 
79
79
  Yes, Cells have helpers just like controllers. If you need some specific helper, do
80
80
 
81
- class ShoppingCartCell < Cell::Rails
81
+ class ShoppingCartCell < Cell::Rails
82
82
  helper MyExtraHelper
83
83
 
84
84
  and it will be around in your cart views.
@@ -107,7 +107,7 @@ Let +render_cell+ take care of creating the right cell. Just configure your supe
107
107
  build do
108
108
  UnauthorizedUserCell unless logged_in?
109
109
  end
110
-
110
+
111
111
  A call to
112
112
 
113
113
  render_cell(:login, :box)
@@ -119,14 +119,14 @@ will render the configured +UnauthorizedUserCell+ instead of the original +Login
119
119
 
120
120
  Cells do strict view caching. No cluttered fragment caching. Add
121
121
 
122
- class ShoppingCartCell < Cell::Rails
122
+ class ShoppingCartCell < Cell::Rails
123
123
  cache :display, :expires_in => 10.minutes
124
124
 
125
125
  and your cart will be re-rendered after 10 minutes.
126
126
 
127
127
  You can expand the state's cache key - why not use a versioner block to do just this?
128
128
 
129
- class ShoppingCartCell < Cell::Rails
129
+ class ShoppingCartCell < Cell::Rails
130
130
  cache :display do |cell, options|
131
131
  options[:items].md5
132
132
  end
@@ -181,7 +181,7 @@ In order to copy the cells rake tasks to your app, run
181
181
  Cells can do more.
182
182
 
183
183
  <b>No Limits</b>:: Have as many cells in your page as you need - no limitation to your +render_cell+ calls.
184
- <b>Cell Nesting</b>:: Have complex cell hierarchies as you can call +render_cell+ within cells, too.
184
+ <b>Cell Nesting</b>:: Have complex cell hierarchies as you can call +render_cell+ within cells, too.
185
185
 
186
186
  Go for it, you'll love it!
187
187
 
@@ -24,4 +24,5 @@ Gem::Specification.new do |s|
24
24
 
25
25
  s.add_development_dependency "shoulda"
26
26
  s.add_development_dependency "haml"
27
+ s.add_development_dependency "slim"
27
28
  end
@@ -1,3 +1,3 @@
1
1
  module Cells
2
- VERSION = '3.5.5'
2
+ VERSION = '3.5.6'
3
3
  end
@@ -0,0 +1,18 @@
1
+ module Cells
2
+ module Generators
3
+ class ViewGenerator < Base
4
+ def create_views
5
+ for state in actions do
6
+ @state = state
7
+ @path = File.join(base_path, "#{state}.html.#{handler}") #base_path defined in Cells::Generators::Base.
8
+ template "view.#{handler}", @path
9
+ end
10
+ end
11
+
12
+ private
13
+ def handler
14
+ raise "Please implement #handler in your view generator and return something like `:erb`."
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,16 +1,14 @@
1
- require 'generators/cells/base'
1
+ require 'generators/cells/view_generator'
2
2
 
3
3
  module Erb
4
4
  module Generators
5
- class CellGenerator < ::Cells::Generators::Base
5
+ class CellGenerator < ::Cells::Generators::ViewGenerator
6
+
6
7
  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(base_path, "#{state}.html.erb") #base_path defined in Cells::Generators::Base.
12
- template "view.erb", @path
13
- end
8
+
9
+ private
10
+ def handler
11
+ :erb
14
12
  end
15
13
  end
16
14
  end
@@ -1,16 +1,14 @@
1
- require 'generators/cells/base'
1
+ require 'generators/cells/view_generator'
2
2
 
3
3
  module Haml
4
4
  module Generators
5
- class CellGenerator < ::Cells::Generators::Base
5
+ class CellGenerator < ::Cells::Generators::ViewGenerator
6
+
6
7
  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(base_path, "#{state}.html.haml") #base_path defined in Cells::Generators::Base.
12
- template "view.haml", @path
13
- end
8
+
9
+ private
10
+ def handler
11
+ :haml
14
12
  end
15
13
  end
16
14
  end
@@ -0,0 +1,17 @@
1
+ require 'generators/cells/view_generator'
2
+
3
+ module Slim
4
+ module Generators
5
+ class CellGenerator < ::Cells::Generators::ViewGenerator
6
+
7
+ source_root File.expand_path('../../templates', __FILE__)
8
+
9
+ private
10
+ def handler
11
+ :slim
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+
@@ -0,0 +1,4 @@
1
+ h1
2
+ <%= class_name %>#<%= @state %>
3
+ p
4
+ Find me in <%= @path %>
@@ -0,0 +1 @@
1
+ Find me at <%= link_to "vd.com", root_url %>
@@ -0,0 +1,8 @@
1
+ class TrumpeterCell < Cell::Rails
2
+ include ActionController::UrlFor
3
+
4
+ def promote
5
+ render
6
+ end
7
+
8
+ end
@@ -21,6 +21,10 @@ class CellGeneratorTest < Rails::Generators::TestCase
21
21
  assert_no_file "app/cells/blog/post.html.haml"
22
22
  assert_no_file "app/cells/blog/post.html.haml"
23
23
  assert_no_file "app/cells/blog/latest.html.haml"
24
+
25
+ assert_no_file "app/cells/blog/post.html.slim"
26
+ assert_no_file "app/cells/blog/post.html.slim"
27
+ assert_no_file "app/cells/blog/latest.html.slim"
24
28
  end
25
29
 
26
30
  should "work with namespaces" do
@@ -38,6 +42,33 @@ class CellGeneratorTest < Rails::Generators::TestCase
38
42
  assert_file "app/cells/blog/post/latest.html.haml", %r(app/cells/blog/post/latest\.html\.haml)
39
43
  end
40
44
 
45
+ should "work with namespaces and slim" do
46
+ run_generator %w(Blog::Post latest -e slim)
47
+
48
+ assert_file "app/cells/blog/post_cell.rb", /class Blog::PostCell < Cell::Rails/
49
+ assert_file "app/cells/blog/post/latest.html.slim", %r(app/cells/blog/post/latest\.html\.slim)
50
+ end
51
+
52
+ should "create slim assets with -e slim" do
53
+ run_generator %w(Blog post latest -e slim)
54
+
55
+ assert_file "app/cells/blog_cell.rb", /class BlogCell < Cell::Rails/
56
+ assert_file "app/cells/blog_cell.rb", /def post/
57
+ assert_file "app/cells/blog_cell.rb", /def latest/
58
+ assert_file "app/cells/blog/post.html.slim", %r(app/cells/blog/post\.html\.slim)
59
+ assert_file "app/cells/blog/post.html.slim", %r(p)
60
+ assert_file "app/cells/blog/latest.html.slim", %r(app/cells/blog/latest\.html\.slim)
61
+
62
+
63
+ assert_no_file "app/cells/blog/post.html.erb"
64
+ assert_no_file "app/cells/blog/post.html.erb"
65
+ assert_no_file "app/cells/blog/latest.html.erb"
66
+
67
+ assert_no_file "app/cells/blog/post.html.haml"
68
+ assert_no_file "app/cells/blog/post.html.haml"
69
+ assert_no_file "app/cells/blog/latest.html.haml"
70
+ end
71
+
41
72
  should "create haml assets with -e haml" do
42
73
  run_generator %w(Blog post latest -e haml)
43
74
 
@@ -52,6 +83,10 @@ class CellGeneratorTest < Rails::Generators::TestCase
52
83
  assert_no_file "app/cells/blog/post.html.erb"
53
84
  assert_no_file "app/cells/blog/post.html.erb"
54
85
  assert_no_file "app/cells/blog/latest.html.erb"
86
+
87
+ assert_no_file "app/cells/blog/post.html.slim"
88
+ assert_no_file "app/cells/blog/post.html.slim"
89
+ assert_no_file "app/cells/blog/latest.html.slim"
55
90
  end
56
91
 
57
92
  should "create test_unit assets with -t test_unit" do
@@ -2,31 +2,35 @@ class MusicianController < ActionController::Base
2
2
  def index
3
3
  render :text => render_cell(:bassist, :promote)
4
4
  end
5
-
5
+
6
+ def promote
7
+ render :text => render_cell(:trumpeter, :promote)
8
+ end
9
+
6
10
  def promotion
7
11
  render :text => render_cell(:bassist, :provoke)
8
12
  end
9
-
13
+
10
14
  def featured
11
15
  end
12
-
16
+
13
17
  def featured_with_block
14
18
  end
15
-
19
+
16
20
  def skills
17
21
  render :text => render_cell(:bassist, :listen)
18
22
  end
19
-
23
+
20
24
  def hamlet
21
25
  end
22
-
26
+
23
27
  attr_reader :flag
24
28
  def promotion_with_block
25
29
  html = render_cell(:bassist, :play) do |cell|
26
30
  @flag = cell.class
27
31
  end
28
-
29
- render :text => html
32
+
33
+ render :text => html
30
34
  end
31
-
35
+
32
36
  end
@@ -13,7 +13,4 @@ Dummy::Application.configure do
13
13
  config.consider_all_requests_local = true
14
14
  config.action_view.debug_rjs = true
15
15
  config.action_controller.perform_caching = false
16
-
17
- # Don't care if the mailer can't send
18
- config.action_mailer.raise_delivery_errors = false
19
16
  end
@@ -1,3 +1,4 @@
1
1
  Dummy::Application.routes.draw do |map|
2
2
  match ':controller(/:action(/:id(.:format)))'
3
+ root :to => 'musician#index'
3
4
  end
@@ -7,25 +7,27 @@ module ApplicationTests
7
7
  BassistCell.class_eval do
8
8
  def promote; render; end
9
9
  end
10
-
11
- #assert ::Cell::Rails.view_context_class._routes, "Cells::Railtie initializer wasn't invoked."
12
- #assert ! ::OmgController.new.respond_to?( :render_cell)
13
-
10
+
14
11
  get "index"
15
12
  assert_response :success
16
13
  assert_equal "Find me at <a href=\"/musician\">vd.com</a>", @response.body
17
14
  end
18
-
15
+
16
+ should "allow cells to use *_url helpers when mixing in AC::UrlFor" do
17
+ get "promote"
18
+ assert_response :success
19
+ assert_equal "Find me at <a href=\"http://test.host/\">vd.com</a>\n", @response.body
20
+ end
21
+
19
22
  should "allow cells to use #config" do
20
-
21
23
  BassistCell.class_eval do
22
24
  def provoke; render; end
23
25
  end
24
-
26
+
25
27
  get "promotion"
26
28
  assert_response :success
27
29
  assert_equal "That's me, naked <img alt=\"Me\" src=\"/images/me.png\" />", @response.body
28
- end
30
+ end
29
31
  end
30
32
  end
31
33
  end
@@ -40,6 +40,7 @@ class Cell::Rails
40
40
  end
41
41
 
42
42
  require File.join(test_app_dir, 'cells', 'bassist_cell')
43
+ require File.join(test_app_dir, 'cells', 'trumpeter_cell')
43
44
  require File.join(test_app_dir, 'cells', 'bad_guitarist_cell')
44
45
 
45
46
  require "haml"
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 3
7
7
  - 5
8
- - 5
9
- version: 3.5.5
8
+ - 6
9
+ version: 3.5.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nick Sutterer
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-03-08 00:00:00 +01:00
17
+ date: 2011-03-24 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -73,6 +73,19 @@ dependencies:
73
73
  version: "0"
74
74
  type: :development
75
75
  version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: slim
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ type: :development
88
+ version_requirements: *id005
76
89
  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.
77
90
  email:
78
91
  - apotonick@gmail.com
@@ -103,13 +116,16 @@ files:
103
116
  - lib/generators/USAGE
104
117
  - lib/generators/cells/base.rb
105
118
  - lib/generators/cells/cell_generator.rb
119
+ - lib/generators/cells/view_generator.rb
106
120
  - lib/generators/erb/cell_generator.rb
107
121
  - lib/generators/haml/cell_generator.rb
108
122
  - lib/generators/rails/cell_generator.rb
123
+ - lib/generators/slim/cell_generator.rb
109
124
  - lib/generators/templates/cell.rb
110
125
  - lib/generators/templates/cell_test.rb
111
126
  - lib/generators/templates/view.erb
112
127
  - lib/generators/templates/view.haml
128
+ - lib/generators/templates/view.slim
113
129
  - lib/generators/test_unit/cell_generator.rb
114
130
  - test/active_helper_test.rb
115
131
  - test/app/cells/bad_guitarist/_dii.html.erb
@@ -132,6 +148,8 @@ files:
132
148
  - test/app/cells/layouts/metal.html.erb
133
149
  - test/app/cells/producer/capture.html.erb
134
150
  - test/app/cells/producer/content_for.html.erb
151
+ - test/app/cells/trumpeter/promote.html.erb
152
+ - test/app/cells/trumpeter_cell.rb
135
153
  - test/cell_generator_test.rb
136
154
  - test/cell_module_test.rb
137
155
  - test/cells_module_test.rb