cells 3.3.1 → 3.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ Helpers
@@ -323,19 +323,30 @@ module Cells
323
323
  # between both terms. A cell view is both, a view and a kind of partial as it represents only a small
324
324
  # part of the page.
325
325
  # Just use <tt>:view</tt> and enjoy.
326
- def render(opts={})
327
- render_view_for(opts, @state_name) ### FIXME: i don't like the magic access to @state_name here. ugly!
326
+ def render(opts={}, &block)
327
+ render_view_for(opts, @state_name, &block)
328
328
  end
329
329
 
330
330
  # Render the view belonging to the given state. Will raise ActionView::MissingTemplate
331
331
  # if it can not find one of the requested view template. Note that this behaviour was
332
332
  # introduced in cells 2.3 and replaces the former warning message.
333
- def render_view_for(opts, state)
333
+ def render_view_for(opts, state, &block)
334
334
  return '' if opts[:nothing]
335
335
 
336
336
  action_view = setup_action_view
337
337
 
338
338
  ### 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
+
339
350
  if opts[:text]
340
351
  elsif opts[:inline]
341
352
  elsif opts[:file]
@@ -453,8 +464,7 @@ module Cells
453
464
 
454
465
  ### TODO: allow log levels.
455
466
  def log(message)
456
- return unless @controller.logger
457
- @controller.logger.debug(message)
467
+ @controller.logger and @controller.logger.debug(message)
458
468
  end
459
469
  end
460
470
  end
@@ -18,11 +18,11 @@ module Cells
18
18
  ### so that we can overwrite the helper and cleanly reuse the internal method? using the same
19
19
  ### method both internally and externally sucks ass.
20
20
  def render(options = {}, local_assigns = {}, &block)
21
- ### TODO: delegate dynamically:
22
21
  ### TODO: we have to find out if this is a call to the cells #render method, or to the rails
23
22
  ### method (e.g. when rendering a layout). what a shit.
24
- if view = options[:view]
25
- return cell.render_view_for(options, view)
23
+ if (options.keys & [:view, :state]).present? ### TODO: is there something like has_keys?
24
+ # that's better: simply delegate render back to the cell/controller.
25
+ return cell.render(options)
26
26
  end
27
27
 
28
28
  # rails compatibility we should get rid of:
@@ -30,7 +30,6 @@ module Cells
30
30
  # adds the cell name to the partial name.
31
31
  options[:partial] = expand_view_path(partial_path)
32
32
  end
33
- #throw Exception.new
34
33
 
35
34
  super(options, local_assigns, &block)
36
35
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Cells
4
- VERSION = '3.3.1'.freeze
4
+ VERSION = '3.3.2'
5
5
  end
@@ -0,0 +1,3 @@
1
+ class BassistCell < Cell::Base
2
+
3
+ end
@@ -0,0 +1,63 @@
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
@@ -283,4 +283,20 @@ class RenderTest < ActiveSupport::TestCase
283
283
  end
284
284
  assert_equal "Metal:A/another_state/a,b", render_cell(:a, :existing_view)
285
285
  end
286
+
287
+ context "render :state within a view" do
288
+ should "return the state content" do
289
+ assert_equal( "\nDoo\n\nDoo\n\nDoo\n\nDoo\n",
290
+ bassist_mock do
291
+ def jam
292
+ @chords = %w(d a c g)
293
+ render
294
+ end
295
+ def play
296
+ render
297
+ end
298
+ end.render_state(:jam)
299
+ )
300
+ end
301
+ end
286
302
  end
@@ -60,5 +60,11 @@ module Cells
60
60
  cell.instance_eval(&block) if block_given?
61
61
  cell
62
62
  end
63
+
64
+ def bassist_mock(options={}, &block)
65
+ cell = BassistCell.new(@controller, options)
66
+ cell.instance_eval(&block) if block_given?
67
+ cell
68
+ end
63
69
  end
64
70
  end
@@ -74,3 +74,5 @@ ActiveSupport::TestCase.class_eval do
74
74
  include Cells::AssertionsHelper
75
75
  include Cells::InternalAssertionsHelper
76
76
  end
77
+
78
+ require File.join(File.dirname(__FILE__), *%w[app cells bassist_cell])
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cells
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ prerelease: false
5
+ segments:
6
+ - 3
7
+ - 3
8
+ - 2
9
+ version: 3.3.2
5
10
  platform: ruby
6
11
  authors:
7
12
  - Nick Sutterer
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-03-27 00:00:00 +01:00
17
+ date: 2010-04-12 00:00:00 +02:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -21,10 +26,12 @@ extensions: []
21
26
 
22
27
  extra_rdoc_files:
23
28
  - README.rdoc
29
+ - README.textile
24
30
  files:
25
31
  - CHANGES
26
32
  - MIT-LICENSE
27
33
  - README.rdoc
34
+ - README.textile
28
35
  - Rakefile
29
36
  - lib/cell.rb
30
37
  - lib/cells.rb
@@ -62,22 +69,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
69
  requirements:
63
70
  - - ">="
64
71
  - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
65
74
  version: "0"
66
- version:
67
75
  required_rubygems_version: !ruby/object:Gem::Requirement
68
76
  requirements:
69
77
  - - ">="
70
78
  - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
71
81
  version: "0"
72
- version:
73
82
  requirements: []
74
83
 
75
84
  rubyforge_project:
76
- rubygems_version: 1.3.5
85
+ rubygems_version: 1.3.6
77
86
  signing_key:
78
87
  specification_version: 3
79
88
  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.
80
89
  test_files:
90
+ - test/erector_test.rb
81
91
  - test/rails_test.rb
82
92
  - test/capture_helper_test.rb
83
93
  - test/assertions_helper_test.rb
@@ -90,6 +100,7 @@ test_files:
90
100
  - test/helper_test.rb
91
101
  - test/caching_test.rb
92
102
  - test/app/controllers/cells_test_controller.rb
103
+ - test/app/cells/bassist_cell.rb
93
104
  - test/app/cells/really_module/nested_cell.rb
94
105
  - test/app/cells/cells_test_one_cell.rb
95
106
  - test/app/cells/cells_test_two_cell.rb