From 0f613d07d9bb7b0e0d6da5ef06ed5e1a16da6eb2 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Wed, 30 Jan 2008 20:30:50 +0000 Subject: [PATCH] ActionItem154: refactoring: moving CSS class calculus to Block class --- app/helpers/boxes_helper.rb | 2 +- app/models/block.rb | 9 +++++++++ test/unit/block_test.rb | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/helpers/boxes_helper.rb b/app/helpers/boxes_helper.rb index 10faa0c..4408a5d 100644 --- a/app/helpers/boxes_helper.rb +++ b/app/helpers/boxes_helper.rb @@ -53,7 +53,7 @@ module BoxesHelper end end - classes = ['block', block.class.name.underscore.gsub('_', '-') ].uniq.join(' ') + classes = ['block', block.css_class_name ].uniq.join(' ') 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) end diff --git a/app/models/block.rb b/app/models/block.rb index 77b108e..92ac6ae 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -27,14 +27,19 @@ class Block < ActiveRecord::Base _('A dummy block.') end + # TODO: must have some way to have access to request information (mainly the + # current user) def content "This is block number %d" % self.id end + # must return a Hash with URL options poiting to the action that edits + # properties of the block def editor nil end + # must always return false, except on MainBlock clas. def main? false end @@ -43,4 +48,8 @@ class Block < ActiveRecord::Base box ? box.owner : nil end + def css_class_name + self.class.name.underscore.gsub('_', '-') + end + end diff --git a/test/unit/block_test.rb b/test/unit/block_test.rb index b727258..7d1dd52 100644 --- a/test/unit/block_test.rb +++ b/test/unit/block_test.rb @@ -51,4 +51,10 @@ class BlockTest < Test::Unit::TestCase assert_equal({ :limit => 10}, block.settings) end + should 'generate CSS class name' do + block = Block.new + block.class.expects(:name).returns('SomethingBlock') + assert_equal 'something-block', block.css_class_name + end + end -- libgit2 0.21.2