Commit f4a1a6b08f0833747a916687e89677e63b04a55a
1 parent
6cc31ce6
Exists in
master
and in
29 other branches
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
Showing
3 changed files
with
14 additions
and
10 deletions
Show diff stats
app/helpers/boxes_helper.rb
| @@ -61,6 +61,8 @@ module BoxesHelper | @@ -61,6 +61,8 @@ module BoxesHelper | ||
| 61 | end | 61 | end |
| 62 | when Proc | 62 | when Proc |
| 63 | self.instance_eval(&content) | 63 | self.instance_eval(&content) |
| 64 | + when NilClass | ||
| 65 | + '' | ||
| 64 | else | 66 | else |
| 65 | raise "Unsupported content for block (#{content.class})" | 67 | raise "Unsupported content for block (#{content.class})" |
| 66 | end | 68 | end |
app/models/block.rb
| @@ -25,11 +25,21 @@ class Block < ActiveRecord::Base | @@ -25,11 +25,21 @@ class Block < ActiveRecord::Base | ||
| 25 | # * <tt>Proc</tt>: the Proc is evaluated in the scope of BoxesHelper. The | 25 | # * <tt>Proc</tt>: the Proc is evaluated in the scope of BoxesHelper. The |
| 26 | # block can then use <tt>render</tt>, <tt>link_to</tt>, etc. | 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 | # See BoxesHelper#extract_block_content for implementation details. | 30 | # See BoxesHelper#extract_block_content for implementation details. |
| 29 | def content | 31 | def content |
| 30 | "This is block number %d" % self.id | 32 | "This is block number %d" % self.id |
| 31 | end | 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 | # must return a Hash with URL options poiting to the action that edits | 43 | # must return a Hash with URL options poiting to the action that edits |
| 34 | # properties of the block | 44 | # properties of the block |
| 35 | def editor | 45 | def editor |
| @@ -49,12 +59,4 @@ class Block < ActiveRecord::Base | @@ -49,12 +59,4 @@ class Block < ActiveRecord::Base | ||
| 49 | self.class.name.underscore.gsub('_', '-') | 59 | self.class.name.underscore.gsub('_', '-') |
| 50 | end | 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 | end | 62 | end |
test/unit/block_test.rb
| @@ -28,8 +28,8 @@ class BlockTest < Test::Unit::TestCase | @@ -28,8 +28,8 @@ class BlockTest < Test::Unit::TestCase | ||
| 28 | assert_equal 'something-block', block.css_class_name | 28 | assert_equal 'something-block', block.css_class_name |
| 29 | end | 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 | end | 33 | end |
| 34 | 34 | ||
| 35 | end | 35 | end |