Commit f4a1a6b08f0833747a916687e89677e63b04a55a

Authored by AntonioTerceiro
1 parent 6cc31ce6

ActionItem154: added support for nil as "no footer". Changed Block class to retu…

…rn nil (no footer) instead of an empty string.


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1346 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/helpers/boxes_helper.rb
... ... @@ -61,6 +61,8 @@ module BoxesHelper
61 61 end
62 62 when Proc
63 63 self.instance_eval(&content)
  64 + when NilClass
  65 + ''
64 66 else
65 67 raise "Unsupported content for block (#{content.class})"
66 68 end
... ...
app/models/block.rb
... ... @@ -25,11 +25,21 @@ class Block < ActiveRecord::Base
25 25 # * <tt>Proc</tt>: the Proc is evaluated in the scope of BoxesHelper. The
26 26 # block can then use <tt>render</tt>, <tt>link_to</tt>, etc.
27 27 #
  28 + # The method can also return <tt>nil</tt>, which means "no footer".
  29 + #
28 30 # See BoxesHelper#extract_block_content for implementation details.
29 31 def content
30 32 "This is block number %d" % self.id
31 33 end
32 34  
  35 + # A footer to be appended to the end of the block. Returns <tt>nil</tt>.
  36 + #
  37 + # Override in your subclasses. You can return the same types supported by
  38 + # #content.
  39 + def footer
  40 + nil
  41 + end
  42 +
33 43 # must return a Hash with URL options poiting to the action that edits
34 44 # properties of the block
35 45 def editor
... ... @@ -49,12 +59,4 @@ class Block &lt; ActiveRecord::Base
49 59 self.class.name.underscore.gsub('_', '-')
50 60 end
51 61  
52   - # A footer to be appended to the end of the block. Returns an empty string.
53   - #
54   - # Override in your subclasses. You can return the same types supported by
55   - # #content.
56   - def footer
57   - ''
58   - end
59   -
60 62 end
... ...
test/unit/block_test.rb
... ... @@ -28,8 +28,8 @@ class BlockTest &lt; Test::Unit::TestCase
28 28 assert_equal 'something-block', block.css_class_name
29 29 end
30 30  
31   - should 'provide an empty footer by default' do
32   - assert_equal '', Block.new.footer
  31 + should 'provide no footer by default' do
  32 + assert_nil Block.new.footer
33 33 end
34 34  
35 35 end
... ...