cells 3.3.2 → 3.3.3

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.
@@ -52,7 +52,7 @@ module Cells
52
52
 
53
53
  # Cells setup/configuration helper for initializer.
54
54
  #
55
- # == Usage/Exmaples:
55
+ # == Usage/Examples:
56
56
  #
57
57
  # Cells.setup do |config|
58
58
  # config.cell_view_paths << Rails.root.join('lib', 'cells')
@@ -5,6 +5,7 @@ module Cells
5
5
  autoload :Base, 'cells/cell/base'
6
6
  autoload :View, 'cells/cell/view'
7
7
  autoload :Caching, 'cells/cell/caching'
8
+ autoload :ActiveHelper, 'cells/cell/active_helper'
8
9
  end
9
10
  end
10
11
 
@@ -0,0 +1,32 @@
1
+ module Cells::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
@@ -140,6 +140,7 @@ module Cells
140
140
  class Base
141
141
  include ::ActionController::Helpers
142
142
  include ::ActionController::RequestForgeryProtection
143
+ include ActiveHelper
143
144
 
144
145
  class_inheritable_array :view_paths, :instance_writer => false
145
146
  write_inheritable_attribute(:view_paths, ActionView::PathSet.new) # Force use of a PathSet in this attribute, self.view_paths = ActionView::PathSet.new would still yield in an array
@@ -323,30 +324,19 @@ module Cells
323
324
  # between both terms. A cell view is both, a view and a kind of partial as it represents only a small
324
325
  # part of the page.
325
326
  # Just use <tt>:view</tt> and enjoy.
326
- def render(opts={}, &block)
327
- render_view_for(opts, @state_name, &block)
327
+ def render(opts={})
328
+ render_view_for(opts, @state_name) ### FIXME: i don't like the magic access to @state_name here. ugly!
328
329
  end
329
330
 
330
331
  # Render the view belonging to the given state. Will raise ActionView::MissingTemplate
331
332
  # if it can not find one of the requested view template. Note that this behaviour was
332
333
  # introduced in cells 2.3 and replaces the former warning message.
333
- def render_view_for(opts, state, &block)
334
+ def render_view_for(opts, state)
334
335
  return '' if opts[:nothing]
335
336
 
336
337
  action_view = setup_action_view
337
338
 
338
339
  ### TODO: dispatch dynamically:
339
- if opts[:erector]
340
- require 'erector'
341
- #puts self.class.master_helper_module.instance_methods
342
- #extend self.class.master_helper_module
343
- #return Erector.inline(assigns_for_view, &block).to_s(:helpers => action_view, :parent => action_view)
344
- #include_helpers_in_class(action_view.class)
345
- action_view.output_buffer=""
346
- return Erector.inline(assigns_for_view, &block).to_s(:parent => action_view)
347
- end
348
-
349
-
350
340
  if opts[:text]
351
341
  elsif opts[:inline]
352
342
  elsif opts[:file]
@@ -378,6 +368,8 @@ module Cells
378
368
  def prepare_action_view_for(action_view, opts)
379
369
  # make helpers available:
380
370
  include_helpers_in_class(action_view.class)
371
+
372
+ import_active_helpers_into(action_view) # in Cells::Cell::ActiveHelper.
381
373
 
382
374
  action_view.assigns = assigns_for_view # make instance vars available.
383
375
  action_view.template_format = opts[:template_format]
@@ -464,7 +456,8 @@ module Cells
464
456
 
465
457
  ### TODO: allow log levels.
466
458
  def log(message)
467
- @controller.logger and @controller.logger.debug(message)
459
+ return unless @controller.logger
460
+ @controller.logger.debug(message)
468
461
  end
469
462
  end
470
463
  end
@@ -3,7 +3,7 @@
3
3
  # To improve performance rendered state views can be cached using Rails' caching
4
4
  # mechanism.
5
5
  # If this it configured (e.g. using our fast friend memcached) all you have to do is to
6
- # tell Cells which state you want to cache. You can further attach a proc to expire the
6
+ # tell Cells which state to cache. You can further attach a proc to expire the
7
7
  # cached view.
8
8
  #
9
9
  # As always I stole a lot of code, this time from Lance Ivy <cainlevy@gmail.com> and
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Cells
4
- VERSION = '3.3.2'
4
+ VERSION = '3.3.3'
5
5
  end
@@ -0,0 +1,59 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ ### DISCUSS: how can we limit that test to systems where ActiveHelper's around?
4
+
5
+ class ActiveHelperTest < ActiveSupport::TestCase
6
+ context "The Cell::Base class" do
7
+ setup do
8
+ require 'active_helper'
9
+ class FingeringHelper < ActiveHelper::Base
10
+ provides :finger
11
+ end
12
+
13
+ class SlappingHelper < ActiveHelper::Base
14
+ provides :slap
15
+ end
16
+ end
17
+
18
+ should "respond to active_helper" do
19
+ assert_respond_to Cell::Base, :active_helper
20
+ end
21
+
22
+ should "store helper constants from active_helper" do
23
+ @cell = Class.new(BassistCell)
24
+ @cell.active_helper SlappingHelper
25
+ assert_equal [SlappingHelper], @cell.active_helpers
26
+ end
27
+
28
+ should "inherit helper constants from active_helper" do
29
+ @base_cell = Class.new(BassistCell)
30
+ @base_cell.active_helper SlappingHelper
31
+ @cell = Class.new(@base_cell)
32
+ @cell.active_helper FingeringHelper
33
+ assert_equal [SlappingHelper, FingeringHelper], @cell.active_helpers
34
+ end
35
+
36
+
37
+ context "An Cell::View::Base instance" do
38
+ should_eventually "respond to use" do
39
+ # we didn't extend the view at this point.
40
+ @view = bassist_mock.setup_action_view
41
+ assert_respond_to @view, :use
42
+ end
43
+
44
+ end
45
+
46
+ context "The view rendered by the cell" do
47
+ should "respond to used helper methods" do
48
+ @cell = bassist_mock
49
+ @cell.class.active_helper SlappingHelper
50
+
51
+ @view = @cell.setup_action_view
52
+ @cell.prepare_action_view_for(@view, {})
53
+
54
+ assert_respond_to @view, :slap # from the SlappingHelper
55
+ end
56
+ end
57
+ end
58
+
59
+ end
metadata CHANGED
@@ -1,12 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cells
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 3
7
- - 3
8
- - 2
9
- version: 3.3.2
4
+ version: 3.3.3
10
5
  platform: ruby
11
6
  authors:
12
7
  - Nick Sutterer
@@ -14,7 +9,7 @@ autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
11
 
17
- date: 2010-04-12 00:00:00 +02:00
12
+ date: 2010-04-17 00:00:00 +02:00
18
13
  default_executable:
19
14
  dependencies: []
20
15
 
@@ -26,17 +21,16 @@ extensions: []
26
21
 
27
22
  extra_rdoc_files:
28
23
  - README.rdoc
29
- - README.textile
30
24
  files:
31
25
  - CHANGES
32
26
  - MIT-LICENSE
33
27
  - README.rdoc
34
- - README.textile
35
28
  - Rakefile
36
29
  - lib/cell.rb
37
30
  - lib/cells.rb
38
31
  - lib/cells/assertions_helper.rb
39
32
  - lib/cells/cell.rb
33
+ - lib/cells/cell/active_helper.rb
40
34
  - lib/cells/cell/base.rb
41
35
  - lib/cells/cell/caching.rb
42
36
  - lib/cells/cell/view.rb
@@ -69,26 +63,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
63
  requirements:
70
64
  - - ">="
71
65
  - !ruby/object:Gem::Version
72
- segments:
73
- - 0
74
66
  version: "0"
67
+ version:
75
68
  required_rubygems_version: !ruby/object:Gem::Requirement
76
69
  requirements:
77
70
  - - ">="
78
71
  - !ruby/object:Gem::Version
79
- segments:
80
- - 0
81
72
  version: "0"
73
+ version:
82
74
  requirements: []
83
75
 
84
76
  rubyforge_project:
85
- rubygems_version: 1.3.6
77
+ rubygems_version: 1.3.5
86
78
  signing_key:
87
79
  specification_version: 3
88
80
  summary: Cells are lightweight controllers for Rails and can be rendered in controllers and views, providing an elegant and fast way for encapsulation and component-orientation.
89
81
  test_files:
90
- - test/erector_test.rb
91
82
  - test/rails_test.rb
83
+ - test/active_helper_test.rb
92
84
  - test/capture_helper_test.rb
93
85
  - test/assertions_helper_test.rb
94
86
  - test/cell_generator_test.rb
@@ -1 +0,0 @@
1
- Helpers
@@ -1,63 +0,0 @@
1
- # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), 'test_helper')
3
-
4
- class ErectorTest < ActionController::TestCase
5
- context "#render with :erector" do
6
- setup do
7
- @cell = cell_mock
8
- end
9
-
10
- should "render the erector widget when called with block" do
11
- @cell.instance_eval do
12
- def jam
13
- @key = "A"
14
- render :erector => true do
15
- h1 do
16
- text "Rock it in "
17
- b @key
18
- end
19
- end
20
- end
21
- end
22
-
23
- assert_equal "<h1>Rock it in <b>A</b></h1>", @cell.render_state(:jam)
24
- end
25
-
26
- should "have access to cell helpers" do
27
- @cell.instance_eval do
28
- #self.class.helper ActionView::Helpers::UrlHelper
29
-
30
- def jam
31
- @key = "A"
32
- render :erector => true do
33
- #url_for("Rock it", "/rock/it")
34
- h1 do link_to("Rock it in #{@key}", :url => "/rock/it") end
35
- #text raw link_to("Rock it")
36
- #h "test"
37
- end
38
- end
39
- end
40
-
41
- #erector_in_cell = Erector::Widget.new
42
- class Erector::InlineWidget
43
- def link_to(*args)
44
- text! "what-ever!"
45
- end
46
- end
47
-
48
- assert_equal "<h1><a href=\"Rock it in A\" url=\"/rock/it\">Rock it in A</a></h1>", @cell.render_state(:jam)
49
- end
50
-
51
- should "cry for beer!" do
52
- require 'erector'
53
- obj = Object.new
54
- obj.instance_eval do
55
- def beer; "beer!"; end
56
- end
57
-
58
-
59
-
60
- assert_equal "<p>Cry for beer!</p>", Erector.inline() { p "Cry for #{text beer} #{b 'yo'}" }.to_s(:parent => obj)
61
- end
62
- end
63
- end