Commit 0f613d07d9bb7b0e0d6da5ef06ed5e1a16da6eb2

Authored by AntonioTerceiro
1 parent e19ef823

ActionItem154: refactoring: moving CSS class calculus to Block class


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1284 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/helpers/boxes_helper.rb
... ... @@ -53,7 +53,7 @@ module BoxesHelper
53 53 end
54 54 end
55 55  
56   - classes = ['block', block.class.name.underscore.gsub('_', '-') ].uniq.join(' ')
  56 + classes = ['block', block.css_class_name ].uniq.join(' ')
57 57  
58 58 box_decorator.block_target(block.box, block) + content_tag('div', result + box_decorator.block_edit_buttons(block), :class => classes, :id => "block-#{block.id}") + box_decorator.block_handle(block)
59 59 end
... ...
app/models/block.rb
... ... @@ -27,14 +27,19 @@ class Block < ActiveRecord::Base
27 27 _('A dummy block.')
28 28 end
29 29  
  30 + # TODO: must have some way to have access to request information (mainly the
  31 + # current user)
30 32 def content
31 33 "This is block number %d" % self.id
32 34 end
33 35  
  36 + # must return a Hash with URL options poiting to the action that edits
  37 + # properties of the block
34 38 def editor
35 39 nil
36 40 end
37 41  
  42 + # must always return false, except on MainBlock clas.
38 43 def main?
39 44 false
40 45 end
... ... @@ -43,4 +48,8 @@ class Block < ActiveRecord::Base
43 48 box ? box.owner : nil
44 49 end
45 50  
  51 + def css_class_name
  52 + self.class.name.underscore.gsub('_', '-')
  53 + end
  54 +
46 55 end
... ...
test/unit/block_test.rb
... ... @@ -51,4 +51,10 @@ class BlockTest < Test::Unit::TestCase
51 51 assert_equal({ :limit => 10}, block.settings)
52 52 end
53 53  
  54 + should 'generate CSS class name' do
  55 + block = Block.new
  56 + block.class.expects(:name).returns('SomethingBlock')
  57 + assert_equal 'something-block', block.css_class_name
  58 + end
  59 +
54 60 end
... ...