diff --git a/app/models/article_block.rb b/app/models/article_block.rb index 8c41a3a..0246086 100644 --- a/app/models/article_block.rb +++ b/app/models/article_block.rb @@ -36,8 +36,4 @@ class ArticleBlock < Block @article = obj end - def editable? - true - end - end diff --git a/app/models/block.rb b/app/models/block.rb index 90447bc..a4fc8ca 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -47,7 +47,7 @@ class Block < ActiveRecord::Base # Is this block editable? (Default to false) def editable? - false + true end # must always return false, except on MainBlock clas. @@ -63,4 +63,16 @@ class Block < ActiveRecord::Base self.class.name.underscore.gsub('_', '-') end + def default_title + '' + end + + def title + if self[:title].blank? + self.default_title + else + self[:title] + end + end + end diff --git a/app/models/communities_block.rb b/app/models/communities_block.rb index 872655e..1c719ba 100644 --- a/app/models/communities_block.rb +++ b/app/models/communities_block.rb @@ -4,7 +4,7 @@ class CommunitiesBlock < ProfileListBlock _('A block that displays your communities') end - def title + def default_title _('Communities') end diff --git a/app/models/enterprises_block.rb b/app/models/enterprises_block.rb index 898620d..dc62772 100644 --- a/app/models/enterprises_block.rb +++ b/app/models/enterprises_block.rb @@ -1,6 +1,6 @@ class EnterprisesBlock < ProfileListBlock - def title + def default_title _('Enterprises') end diff --git a/app/models/environment_statistics_block.rb b/app/models/environment_statistics_block.rb index c72e24b..033c1ab 100644 --- a/app/models/environment_statistics_block.rb +++ b/app/models/environment_statistics_block.rb @@ -4,6 +4,10 @@ class EnvironmentStatisticsBlock < Block _('Statistical overview of your environment.') end + def default_title + _('Statistics for %s') % owner.name + end + def content users = owner.people.count enterprises = owner.enterprises.count @@ -15,7 +19,7 @@ class EnvironmentStatisticsBlock < Block n_('One community', '%{num} communities', communities) % { :num => communities }, ] - block_title(_('Statistics for %s') % owner.name) + content_tag('ul', info.map {|item| content_tag('li', item) }.join("\n")) + block_title(title) + content_tag('ul', info.map {|item| content_tag('li', item) }.join("\n")) end end diff --git a/app/models/favorite_enterprises_block.rb b/app/models/favorite_enterprises_block.rb index ecc2e6c..fec5d63 100644 --- a/app/models/favorite_enterprises_block.rb +++ b/app/models/favorite_enterprises_block.rb @@ -1,6 +1,6 @@ class FavoriteEnterprisesBlock < ProfileListBlock - def title + def default_title _('Favorite Enterprises') end diff --git a/app/models/friends_block.rb b/app/models/friends_block.rb index 6d37394..ec2b5e0 100644 --- a/app/models/friends_block.rb +++ b/app/models/friends_block.rb @@ -4,7 +4,7 @@ class FriendsBlock < ProfileListBlock _('A block that displays your friends') end - def title + def default_title _('Friends') end diff --git a/app/models/main_block.rb b/app/models/main_block.rb index 2ef71cb..0dfb72e 100644 --- a/app/models/main_block.rb +++ b/app/models/main_block.rb @@ -12,4 +12,8 @@ class MainBlock < Block true end + def editable? + false + end + end diff --git a/app/models/members_block.rb b/app/models/members_block.rb index 634af52..0ea4af3 100644 --- a/app/models/members_block.rb +++ b/app/models/members_block.rb @@ -4,7 +4,7 @@ class MembersBlock < ProfileListBlock _('A block that displays members.') end - def title + def default_title _('Members') end diff --git a/app/models/people_block.rb b/app/models/people_block.rb index b2e37cf..0f57ecb 100644 --- a/app/models/people_block.rb +++ b/app/models/people_block.rb @@ -1,6 +1,6 @@ class PeopleBlock < ProfileListBlock - def title + def default_title _('People') end diff --git a/app/models/products_block.rb b/app/models/products_block.rb index bc6be5e..83f5f9f 100644 --- a/app/models/products_block.rb +++ b/app/models/products_block.rb @@ -4,8 +4,12 @@ class ProductsBlock < Block include ActionView::Helpers::UrlHelper include ActionController::UrlWriter + def default_title + _('Products') + end + def content - block_title(_('Products')) + + block_title(title) + content_tag( 'ul', products.map {|product| content_tag('li', link_to(product.name, product.url, :style => 'background-image:url(%s)' % ( product.image ? product.image.public_filename(:minor) : '/images/icons-app/product-default-pic-minor.png' )), :class => 'product' )} @@ -37,8 +41,4 @@ class ProductsBlock < Block end end - def editable? - true - end - end diff --git a/app/models/profile_info_block.rb b/app/models/profile_info_block.rb index 5c5a429..ddfa776 100644 --- a/app/models/profile_info_block.rb +++ b/app/models/profile_info_block.rb @@ -15,4 +15,8 @@ class ProfileInfoBlock < Block end end + def editable? + false + end + end diff --git a/app/models/profile_list_block.rb b/app/models/profile_list_block.rb index d4c4c63..4704429 100644 --- a/app/models/profile_list_block.rb +++ b/app/models/profile_list_block.rb @@ -51,7 +51,7 @@ class ProfileListBlock < Block end # the title of the block. Probably will be overriden in subclasses. - def title + def default_title _('People and Groups') end diff --git a/app/models/recent_documents_block.rb b/app/models/recent_documents_block.rb index 652c480..c22e784 100644 --- a/app/models/recent_documents_block.rb +++ b/app/models/recent_documents_block.rb @@ -4,13 +4,17 @@ class RecentDocumentsBlock < Block _('List of recent content') end + def default_title + _('Recent content') + end + settings_items :limit include ActionController::UrlWriter def content docs = self.limit.nil? ? owner.recent_documents : owner.recent_documents(self.limit) - block_title(_('Recent content')) + + block_title(title) + content_tag('ul', docs.map {|item| content_tag('li', link_to(item.title, item.url))}.join("\n")) end diff --git a/app/models/tags_block.rb b/app/models/tags_block.rb index 12e055e..47e186c 100644 --- a/app/models/tags_block.rb +++ b/app/models/tags_block.rb @@ -8,6 +8,10 @@ class TagsBlock < Block _('Block listing content count by tag') end + def default_title + _('tags') + end + def help _('The tag is created when you add some one to your article.

Try to add some tags to some articles and see your tag cloud to grow.') @@ -17,7 +21,7 @@ class TagsBlock < Block tags = owner.tags return '' if tags.empty? - block_title( _('tags') ) + + block_title(title) + "\n

\n"+ tag_cloud( owner.tags, :id, owner.generate_url(:controller => 'profile', :action => 'tag'), diff --git a/app/views/box_organizer/_block.rhtml b/app/views/box_organizer/_block.rhtml new file mode 100644 index 0000000..c341a40 --- /dev/null +++ b/app/views/box_organizer/_block.rhtml @@ -0,0 +1 @@ + diff --git a/app/views/box_organizer/edit.rhtml b/app/views/box_organizer/edit.rhtml index 7c2d6d7..c7500f3 100644 --- a/app/views/box_organizer/edit.rhtml +++ b/app/views/box_organizer/edit.rhtml @@ -2,6 +2,8 @@ <% form_tag(:action => 'save', :id => @block.id) do %> + <%= labelled_form_field(_('Custom title for this block: '), text_field(:block, :title)) %> + <%= render :partial => partial_for_class(@block.class) %> <% button_bar do %> diff --git a/test/unit/article_block_test.rb b/test/unit/article_block_test.rb index ce2d3d7..e494b1f 100644 --- a/test/unit/article_block_test.rb +++ b/test/unit/article_block_test.rb @@ -52,8 +52,4 @@ class ArticleBlockTest < Test::Unit::TestCase assert_nil block.article_id end - should 'be editable' do - assert ArticleBlock.new.editable? - end - end diff --git a/test/unit/block_test.rb b/test/unit/block_test.rb index 5fd67d2..ef2dab4 100644 --- a/test/unit/block_test.rb +++ b/test/unit/block_test.rb @@ -32,8 +32,20 @@ class BlockTest < Test::Unit::TestCase assert_nil Block.new.footer end - should 'not be editable by default' do - assert !Block.new.editable? + should 'provide an empty default title' do + assert_equal '', Block.new.default_title end + should 'be editable by default' do + assert Block.new.editable? + end + + should 'have default titles' do + b = Block.new + b.expects(:default_title).returns('my title') + assert_equal 'my title', b.title + end + + + end diff --git a/test/unit/communities_block_test.rb b/test/unit/communities_block_test.rb index c3d4b29..b965180 100644 --- a/test/unit/communities_block_test.rb +++ b/test/unit/communities_block_test.rb @@ -6,8 +6,8 @@ class CommunitiesBlockTest < Test::Unit::TestCase assert_kind_of ProfileListBlock, CommunitiesBlock.new end - should 'declare its title' do - assert_not_equal ProfileListBlock.new.title, CommunitiesBlock.new.title + should 'declare its default title' do + assert_not_equal ProfileListBlock.new.default_title, CommunitiesBlock.new.default_title end should 'describe itself' do diff --git a/test/unit/enterprises_block_test.rb b/test/unit/enterprises_block_test.rb index a163b5f..dc7ed53 100644 --- a/test/unit/enterprises_block_test.rb +++ b/test/unit/enterprises_block_test.rb @@ -6,8 +6,8 @@ class EnterprisesBlockTest < Test::Unit::TestCase assert_kind_of ProfileListBlock, EnterprisesBlock.new end - should 'declare its title' do - assert_not_equal ProfileListBlock.new.title, EnterprisesBlock.new.title + should 'declare its default title' do + assert_not_equal ProfileListBlock.new.default_title, EnterprisesBlock.new.default_title end should 'describe itself' do diff --git a/test/unit/environment_statistics_block_test.rb b/test/unit/environment_statistics_block_test.rb index 3047c2a..c748eae 100644 --- a/test/unit/environment_statistics_block_test.rb +++ b/test/unit/environment_statistics_block_test.rb @@ -10,6 +10,15 @@ class EnvironmentStatisticsBlockTest < Test::Unit::TestCase assert_not_equal Block.description, EnvironmentStatisticsBlock.description end + should 'provide a default title' do + owner = mock + owner.expects(:name).returns('my environment') + + block = EnvironmentStatisticsBlock.new + block.expects(:owner).returns(owner) + assert_equal 'Statistics for my environment', block.title + end + should 'generate statistics' do env = Environment.create!(:name => "My test environment") user1 = create_user('testuser1', :environment_id => env.id) diff --git a/test/unit/favorite_enterprises_block_test.rb b/test/unit/favorite_enterprises_block_test.rb index 2fa3678..5bd31ef 100644 --- a/test/unit/favorite_enterprises_block_test.rb +++ b/test/unit/favorite_enterprises_block_test.rb @@ -6,8 +6,8 @@ class FavoriteEnterprisesBlockTest < ActiveSupport::TestCase assert_kind_of ProfileListBlock, FavoriteEnterprisesBlock.new end - should 'declare its title' do - assert_not_equal ProfileListBlock.new.title, FavoriteEnterprisesBlock.new.title + should 'declare its default title' do + assert_not_equal ProfileListBlock.new.default_title, FavoriteEnterprisesBlock.new.default_title end should 'describe itself' do diff --git a/test/unit/friends_block_test.rb b/test/unit/friends_block_test.rb index 3ee70d5..8cd11a9 100644 --- a/test/unit/friends_block_test.rb +++ b/test/unit/friends_block_test.rb @@ -6,8 +6,8 @@ class FriendsBlockTest < ActiveSupport::TestCase assert_not_equal ProfileListBlock.description, FriendsBlock.description end - should 'declare its title' do - assert_not_equal ProfileListBlock.new.title, FriendsBlock.new.title + should 'declare its default title' do + assert_not_equal ProfileListBlock.new.default_title, FriendsBlock.new.default_title end should 'use its own finder' do diff --git a/test/unit/main_block_test.rb b/test/unit/main_block_test.rb index 2bca388..c700d09 100644 --- a/test/unit/main_block_test.rb +++ b/test/unit/main_block_test.rb @@ -11,4 +11,8 @@ class MainBlockTest < Test::Unit::TestCase ok("MainBlock must not have a content") { MainBlock.new.content.blank? } end + should 'not be editable' do + assert !MainBlock.new.editable? + end + end diff --git a/test/unit/members_block_test.rb b/test/unit/members_block_test.rb index 5a34eb6..0b7c792 100644 --- a/test/unit/members_block_test.rb +++ b/test/unit/members_block_test.rb @@ -10,6 +10,10 @@ class MembersBlockTest < Test::Unit::TestCase assert_not_equal ProfileListBlock.description, MembersBlock.description end + should 'provide a default title' do + assert_not_equal ProfileListBlock.new.default_title, MembersBlock.new.default_title + end + should 'link to "all members" page' do profile = create_user('mytestuser').person block = MembersBlock.new diff --git a/test/unit/people_block_test.rb b/test/unit/people_block_test.rb index f331c6f..5109ae7 100644 --- a/test/unit/people_block_test.rb +++ b/test/unit/people_block_test.rb @@ -6,8 +6,8 @@ class PeopleBlockTest < ActiveSupport::TestCase assert_kind_of ProfileListBlock, PeopleBlock.new end - should 'declare its title' do - assert_not_equal ProfileListBlock.new.title, PeopleBlock.new.title + should 'declare its default title' do + assert_not_equal ProfileListBlock.new.default_title, PeopleBlock.new.default_title end should 'describe itself' do diff --git a/test/unit/products_block_test.rb b/test/unit/products_block_test.rb index 6737657..5f68b7a 100644 --- a/test/unit/products_block_test.rb +++ b/test/unit/products_block_test.rb @@ -11,6 +11,10 @@ class ProductsBlockTest < ActiveSupport::TestCase assert_kind_of Block, block end + should 'provide default title' do + assert_not_equal Block.new.default_title, ProductsBlock.new.default_title + end + should "list owner products" do enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise') @@ -99,8 +103,4 @@ class ProductsBlockTest < ActiveSupport::TestCase assert_equal [1, 2], block.product_ids end - should 'be editable' do - assert ProductsBlock.new.editable? - end - end diff --git a/test/unit/profile_info_block_test.rb b/test/unit/profile_info_block_test.rb index c70f18e..aabb6db 100644 --- a/test/unit/profile_info_block_test.rb +++ b/test/unit/profile_info_block_test.rb @@ -20,5 +20,9 @@ class ProfileInfoBlockTest < Test::Unit::TestCase self.expects(:render).with(:file => 'blocks/profile_info', :locals => { :block => block}) instance_eval(& block.content) end + + should 'not be editable' do + assert !ProfileInfoBlock.new.editable? + end end diff --git a/test/unit/profile_list_block_test.rb b/test/unit/profile_list_block_test.rb index 09f6bfc..000a749 100644 --- a/test/unit/profile_list_block_test.rb +++ b/test/unit/profile_list_block_test.rb @@ -6,6 +6,10 @@ class ProfileListBlockTest < Test::Unit::TestCase assert_not_equal Block.description, ProfileListBlock.description end + should 'provide a default title' do + assert_not_equal Block.new.default_title, ProfileListBlock.new.default_title + end + should 'accept a limit of people to be displayed (and default to 6)' do block = ProfileListBlock.new assert_equal 6, block.limit diff --git a/test/unit/recent_documents_block_test.rb b/test/unit/recent_documents_block_test.rb index ede23d9..e12971f 100644 --- a/test/unit/recent_documents_block_test.rb +++ b/test/unit/recent_documents_block_test.rb @@ -18,6 +18,10 @@ class RecentDocumentsBlockTest < Test::Unit::TestCase assert_not_equal Block.description, RecentDocumentsBlock.description end + should 'provide a default title' do + assert_not_equal Block.new.default_title, RecentDocumentsBlock.new.default_title + end + should 'output list with links to recent documents' do output = block.content diff --git a/test/unit/tags_block_test.rb b/test/unit/tags_block_test.rb index a1c8f08..075df8e 100644 --- a/test/unit/tags_block_test.rb +++ b/test/unit/tags_block_test.rb @@ -17,6 +17,10 @@ class TagsBlockTest < Test::Unit::TestCase assert_not_equal Block.description, TagsBlock.description end + should 'provide a default title' do + assert_not_equal Block.new.default_title, TagsBlock.new.default_title + end + should 'generate links to tags' do assert_match /profile\/testinguser\/tag\/first-tag/, block.content assert_match /profile\/testinguser\/tag\/second-tag/, block.content -- libgit2 0.21.2