cells 3.5.2 → 3.5.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.textile CHANGED
@@ -1,3 +1,14 @@
1
+ h2. 3.5.3
2
+
3
+ h3. Bugfixes
4
+ * state-args work even if your state method receives optional arguments or default values, like @def show(user, age=18)@.
5
+
6
+ h3. Changes
7
+
8
+ * Cell::Base.view_paths is now setup in an initializer. If you do scary stuff with view_paths this might lead to scary problems.
9
+ * Cells::DEFAULT_VIEW_PATHS is now Cell::Base::DEFAULT_VIEW_PATHS. Note that Cells will set its view_paths to DEFAULT_VIEW_PATHS at initialization time. If you want to alter the view_paths, use Base.append_view_path and friends in a separate initializer.
10
+
11
+
1
12
  h2. 3.5.2
2
13
 
3
14
  h3. Bugfixes
data/lib/cell.rb CHANGED
@@ -1,9 +1,19 @@
1
1
  module Cell
2
- autoload :Caching, 'cell/caching'
2
+ autoload :Caching, 'cell/caching'
3
3
 
4
4
  extend ActiveSupport::Concern
5
-
5
+
6
+ DEFAULT_VIEW_PATHS = [
7
+ File.join('app', 'cells'),
8
+ File.join('app', 'cells', 'layouts')
9
+ ]
10
+
6
11
  module ClassMethods
12
+ # Called in Railtie at initialization time.
13
+ def setup_view_paths!
14
+ self.view_paths = self::DEFAULT_VIEW_PATHS
15
+ end
16
+
7
17
  def render_cell_for(controller, name, state, *args)
8
18
  cell = create_cell_for(controller, name, *args) # DISCUSS: we always save options.
9
19
  yield cell if block_given?
@@ -73,9 +83,8 @@ module Cell
73
83
  superclass.find_class_view_for_state(state) << view_for_state(state)
74
84
  end
75
85
 
76
- # The cell name, underscored with +_cell+ removed.
77
- def cell_name
78
- name.underscore.sub(/_cell$/, '')
86
+ def cell_name # TODO: remove in 3.6.
87
+ controller_path
79
88
  end
80
89
 
81
90
  # The cell class constant for +cell_name+.
@@ -91,7 +100,7 @@ module Cell
91
100
  end
92
101
 
93
102
  def state_accepts_args?(state)
94
- method(state).arity > 0
103
+ method(state).arity != 0
95
104
  end
96
105
  end
97
106
  end
data/lib/cell/rails.rb CHANGED
@@ -60,7 +60,6 @@ module Cell
60
60
  @opts = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :options)
61
61
  end
62
62
 
63
-
64
63
  def self.view_context_class
65
64
  controller = self
66
65
 
data/lib/cells.rb CHANGED
@@ -60,17 +60,12 @@
60
60
  # this is pretty DRY and object-oriented, isn't it?
61
61
 
62
62
  require 'cell/rails'
63
+ require 'cells/railtie'
63
64
  require 'cells/rails'
64
65
  require 'cell/test_case' if Rails.env == "test"
65
66
  require 'cells/rails_compat' # fixes a bug in Rails <3.0.4. # TODO: remove me as soon as we support 3.1, only.
66
67
 
67
68
  module Cells
68
- # Default view paths for Cells.
69
- DEFAULT_VIEW_PATHS = [
70
- File.join('app', 'cells'),
71
- File.join('app', 'cells', 'layouts')
72
- ]
73
-
74
69
  # Setup your special needs for Cells here. Use this to add new view paths.
75
70
  #
76
71
  # Example:
@@ -85,20 +80,3 @@ module Cells
85
80
  end
86
81
 
87
82
  Cell::Base = Cell::Rails
88
-
89
- Cell::Base.view_paths = Cells::DEFAULT_VIEW_PATHS if Cell::Base.view_paths.blank?
90
-
91
-
92
- require "rails/railtie"
93
-
94
- class Cells::Railtie < Rails::Railtie
95
- initializer "cells.attach_router" do |app|
96
- Cell::Rails.class_eval do
97
- include app.routes.url_helpers
98
- end
99
- end
100
-
101
- rake_tasks do
102
- load "cells/cells.rake"
103
- end
104
- end
@@ -0,0 +1,19 @@
1
+ require "rails/railtie"
2
+
3
+ module Cells
4
+ class Railtie < Rails::Railtie
5
+ initializer "cells.attach_router" do |app|
6
+ Cell::Rails.class_eval do
7
+ include app.routes.url_helpers
8
+ end
9
+ end
10
+
11
+ initializer "cells.setup_view_paths" do |app|
12
+ Cell::Base.setup_view_paths!
13
+ end
14
+
15
+ rake_tasks do
16
+ load "cells/cells.rake"
17
+ end
18
+ end
19
+ end
data/lib/cells/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cells
2
- VERSION = '3.5.2'
2
+ VERSION = '3.5.4'
3
3
  end
@@ -170,6 +170,12 @@ class CellModuleTest < ActiveSupport::TestCase
170
170
  def listen(what, where) end
171
171
  end.state_accepts_args?(:listen))
172
172
  end
173
+
174
+ should "be true for multiple arg with defaults" do
175
+ assert(cell(:bassist) do
176
+ def listen(what, where="") end
177
+ end.state_accepts_args?(:listen))
178
+ end
173
179
  end
174
180
  end
175
181
  end
@@ -34,9 +34,30 @@ class RailsCellsTest < ActiveSupport::TestCase
34
34
  end
35
35
  assert_equal "D", cell(:bassist).render_state(:listen, :note => "D")
36
36
  end
37
+
38
+ should "accept state-args with default parameters" do
39
+ BassistCell.class_eval do
40
+ def listen(first, second="D")
41
+ render :text => first+second
42
+ end
43
+ end
44
+ assert_equal "AD", cell(:bassist).render_state(:listen, "A")
45
+ end
37
46
  end
38
47
 
48
+
39
49
  context "A rails cell" do
50
+ should "respond to DEFAULT_VIEW_PATHS" do
51
+ assert_equal ["app/cells", "app/cells/layouts"], Cell::Base::DEFAULT_VIEW_PATHS
52
+ end
53
+
54
+ should "respond to .setup_view_paths!" do
55
+ swap( Cell::Base, :view_paths => []) do
56
+ Cell::Base.setup_view_paths!
57
+ assert_equal ActionView::PathSet.new(Cell::Rails::DEFAULT_VIEW_PATHS), Cell::Base.view_paths
58
+ end
59
+ end
60
+
40
61
  should "respond to view_paths" do
41
62
  assert_kind_of ActionView::PathSet, Cell::Rails.view_paths, "must be a PathSet for proper template caching/reloading (see issue#2)"
42
63
  end
@@ -11,7 +11,7 @@ class RailsIntegrationTest < ActionController::TestCase
11
11
 
12
12
  should "respond to #render_cell with arbitrary options" do
13
13
  BassistCell.class_eval do
14
- def enjoy(what, where)
14
+ def enjoy(what, where="the bar")
15
15
  render :text => "I like #{what} in #{where}."
16
16
  end
17
17
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 3
7
7
  - 5
8
- - 2
9
- version: 3.5.2
8
+ - 4
9
+ version: 3.5.4
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-02-11 00:00:00 +01:00
17
+ date: 2011-02-20 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -76,16 +76,14 @@ files:
76
76
  - about.yml
77
77
  - cells.gemspec
78
78
  - lib/cell.rb
79
- - lib/cell/active_helper.rb
80
79
  - lib/cell/caching.rb
81
80
  - lib/cell/rails.rb
82
81
  - lib/cell/test_case.rb
83
82
  - lib/cells.rb
84
83
  - lib/cells/cells.rake
85
- - lib/cells/helpers.rb
86
- - lib/cells/helpers/capture_helper.rb
87
84
  - lib/cells/rails.rb
88
85
  - lib/cells/rails_compat.rb
86
+ - lib/cells/railtie.rb
89
87
  - lib/cells/version.rb
90
88
  - lib/generators/USAGE
91
89
  - lib/generators/cells/base.rb
@@ -1,32 +0,0 @@
1
- module Cell::ActiveHelper
2
-
3
- def self.included(base)
4
- base.extend ClassMethods
5
-
6
- base.class_inheritable_array :active_helpers
7
- base.active_helpers = []
8
- end
9
-
10
- module ClassMethods
11
- # The passed helpers will be imported in the view and thus be available in
12
- # your template.
13
- #
14
- # Example:
15
- # class BassistCell < Cell::Base
16
- # active_helper SlappingHelper
17
- #
18
- # The helper file usually resides in +app/active_helpers/+, baby.
19
- def active_helper(*classes)
20
- active_helpers.push(*classes).uniq!
21
- end
22
- end
23
-
24
- def import_active_helpers_into(view)
25
- return if self.class.active_helpers.blank?
26
-
27
- # We simply assume if somebody's using #active_helper, it is already
28
- # required.
29
- view.extend ::ActiveHelper
30
- view.use *self.class.active_helpers
31
- end
32
- end
data/lib/cells/helpers.rb DELETED
@@ -1,7 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Cells
4
- module Helpers
5
- autoload :CaptureHelper, 'cells/helpers/capture_helper'
6
- end
7
- end
@@ -1,51 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # Sorry for the interface violations, but it looks as if there are
4
- # no interfaces in rails at all.
5
- module Cells
6
- module Helpers
7
- module CaptureHelper
8
- # Executes #capture on the global ActionView and sets <tt>name</tt> as the
9
- # instance variable name.
10
- #
11
- # Example:
12
- #
13
- # <p>
14
- # <% global_capture :greeting do
15
- # <h1>Hi, Nick!</h1>
16
- # <% end %>
17
- #
18
- # The captured markup can be accessed in your global action view or in your layout.
19
- #
20
- # <%= @greeting %>
21
- def global_capture(name, &block)
22
- global_view = controller.parent_controller.view_context
23
- content = capture(&block)
24
- global_view.send(:instance_variable_set, :"@#{name}", content)
25
- end
26
-
27
-
28
- # Executes #content_for on the global ActionView.
29
- #
30
- # Example:
31
- #
32
- # <p>
33
- # <% global_content_for :greetings do
34
- # <h1>Hi, Michal!</h1>
35
- # <% end %>
36
- #
37
- # As in global_capture, the markup can be accessed in your global action view or in your layout.
38
- #
39
- # <%= yield :greetings %>
40
- def global_content_for(name, content = nil, &block)
41
- # OMG. that SUCKS.
42
- global_view = controller.parent_controller.view_context
43
- ivar = :"@content_for_#{name}"
44
- content = capture(&block) if block_given?
45
- old_content = global_view.send(:'instance_variable_get', ivar)
46
- global_view.send(:'instance_variable_set', ivar, "#{old_content}#{content}")
47
- nil
48
- end
49
- end
50
- end
51
- end