Commit f92f835b5c5fe168ea348f3cdc9617c79689a934
Committed by
Antonio Terceiro
1 parent
afb1b60d
Exists in
master
and in
23 other branches
Added language for blocks
Blocks will be displayed according to the browser locale: * "all": displayed in all languages * some language: displayed only in the selected language (ActionItem1774) Signed-off-by: Antonio Terceiro <terceiro@colivre.coop.br>
Showing
6 changed files
with
88 additions
and
8 deletions
Show diff stats
app/helpers/boxes_helper.rb
| ... | ... | @@ -65,7 +65,7 @@ module BoxesHelper |
| 65 | 65 | end |
| 66 | 66 | |
| 67 | 67 | def display_box_content(box, main_content) |
| 68 | - context = { :article => @page, :request_path => request.path } | |
| 68 | + context = { :article => @page, :request_path => request.path, :locale => locale } | |
| 69 | 69 | box_decorator.select_blocks(box.blocks, context).map { |item| display_block(item, main_content) }.join("\n") + box_decorator.block_target(box) |
| 70 | 70 | end |
| 71 | 71 | ... | ... |
app/models/block.rb
| ... | ... | @@ -19,15 +19,21 @@ class Block < ActiveRecord::Base |
| 19 | 19 | # may contain the following keys: |
| 20 | 20 | # |
| 21 | 21 | # * <tt>:article</tt>: the article being viewed currently |
| 22 | + # * <tt>:language</tt>: in which language the block will be displayed | |
| 22 | 23 | def visible?(context = nil) |
| 23 | 24 | if display == 'never' |
| 24 | 25 | return false |
| 25 | 26 | end |
| 26 | - if context && display == 'home_page_only' | |
| 27 | - if context[:article] | |
| 28 | - return context[:article] == owner.home_page | |
| 29 | - else | |
| 30 | - return context[:request_path] == '/' | |
| 27 | + if context | |
| 28 | + if language != 'all' && language != context[:locale] | |
| 29 | + return false | |
| 30 | + end | |
| 31 | + if display == 'home_page_only' | |
| 32 | + if context[:article] | |
| 33 | + return context[:article] == owner.home_page | |
| 34 | + else | |
| 35 | + return context[:request_path] == '/' | |
| 36 | + end | |
| 31 | 37 | end |
| 32 | 38 | end |
| 33 | 39 | true |
| ... | ... | @@ -41,6 +47,11 @@ class Block < ActiveRecord::Base |
| 41 | 47 | # homepage of its owner. |
| 42 | 48 | settings_items :display, :type => :string, :default => 'always' |
| 43 | 49 | |
| 50 | + # The block can be configured to be displayed in all languages or in just one language. It can assume any locale of the environment: | |
| 51 | + # | |
| 52 | + # * <tt>'all'</tt>: the block is always displayed | |
| 53 | + settings_items :language, :type => :string, :default => 'all' | |
| 54 | + | |
| 44 | 55 | # returns the description of the block, used when the user sees a list of |
| 45 | 56 | # blocks to choose one to include in the design. |
| 46 | 57 | # | ... | ... |
app/views/box_organizer/edit.rhtml
| ... | ... | @@ -18,6 +18,8 @@ |
| 18 | 18 | <%= label_tag('block_display_never', _("Don't display")) %> |
| 19 | 19 | </div> |
| 20 | 20 | |
| 21 | + <%= labelled_form_field(_('Show for:'), select(:block, :language, [ [ _('all languages'), 'all']] + Noosfero.locales.map {|key, value| [value, key]} )) %> | |
| 22 | + | |
| 21 | 23 | <% button_bar do %> |
| 22 | 24 | <%= submit_button(:save, _('Save')) %> |
| 23 | 25 | <%= lightbox_close_button(_('Cancel')) %> | ... | ... |
| ... | ... | @@ -0,0 +1,38 @@ |
| 1 | +Feature: edit language of block | |
| 2 | + As a profile owner | |
| 3 | + I want to configure in which language a block will be displayed | |
| 4 | + | |
| 5 | + Background: | |
| 6 | + Given the following users | |
| 7 | + | login | name | | |
| 8 | + | joaosilva | Jose Silva | | |
| 9 | + And the following blocks | |
| 10 | + | owner | type | | |
| 11 | + | joaosilva | ArticleBlock | | |
| 12 | + | joaosilva | LinkListBlock | | |
| 13 | + And I am logged in as "joaosilva" | |
| 14 | + | |
| 15 | + Scenario: display in all languages | |
| 16 | + Given I go to edit ArticleBlock of joaosilva | |
| 17 | + And I fill in "Custom title for this block" with "Block displayed" | |
| 18 | + And I select "all languages" | |
| 19 | + And I press "Save" | |
| 20 | + When I go to Jose Silva's homepage | |
| 21 | + Then I should see "Block displayed" | |
| 22 | + | |
| 23 | + Scenario: display in the selected language | |
| 24 | + Given I go to edit LinkListBlock of joaosilva | |
| 25 | + And I fill in "Custom title for this block" with "Block displayed" | |
| 26 | + And I select "Português" | |
| 27 | + And I press "Save" | |
| 28 | + And my browser prefers Portuguese | |
| 29 | + When I go to Jose Silva's homepage | |
| 30 | + Then I should see "Block displayed" | |
| 31 | + | |
| 32 | + Scenario: not display in a not selected language | |
| 33 | + Given I go to edit LinkListBlock of joaosilva | |
| 34 | + And I fill in "Custom title for this block" with "Block not displayed" | |
| 35 | + And I select "Português" | |
| 36 | + And I press "Save" | |
| 37 | + When I go to Jose Silva's homepage | |
| 38 | + Then I should not see "Block displayed" | ... | ... |
test/unit/block_test.rb
| ... | ... | @@ -110,4 +110,30 @@ class BlockTest < Test::Unit::TestCase |
| 110 | 110 | assert_equal 'always', block.display |
| 111 | 111 | end |
| 112 | 112 | |
| 113 | + should 'display block in all languages by default' do | |
| 114 | + profile = Profile.new | |
| 115 | + block = Block.new | |
| 116 | + block.stubs(:owner).returns(profile) | |
| 117 | + | |
| 118 | + assert_equal 'all', block.language | |
| 119 | + end | |
| 120 | + | |
| 121 | + should 'be able to be displayed in all languages' do | |
| 122 | + profile = Profile.new | |
| 123 | + block = Block.new(:language => 'all') | |
| 124 | + block.stubs(:owner).returns(profile) | |
| 125 | + | |
| 126 | + assert_equal true, block.visible?(:locale => 'pt') | |
| 127 | + assert_equal true, block.visible?(:locale => 'en') | |
| 128 | + end | |
| 129 | + | |
| 130 | + should 'be able to be displayed only in the selected language' do | |
| 131 | + profile = Profile.new | |
| 132 | + block = Block.new(:language => 'pt') | |
| 133 | + block.stubs(:owner).returns(profile) | |
| 134 | + | |
| 135 | + assert_equal true, block.visible?(:locale => 'pt') | |
| 136 | + assert_equal false, block.visible?(:locale => 'en') | |
| 137 | + end | |
| 138 | + | |
| 113 | 139 | end | ... | ... |
test/unit/boxes_helper_test.rb
| ... | ... | @@ -50,6 +50,7 @@ class BoxesHelperTest < Test::Unit::TestCase |
| 50 | 50 | expects(:display_block).with(b, '') |
| 51 | 51 | expects(:request).returns(request) |
| 52 | 52 | stubs(:block_target).returns('') |
| 53 | + expects(:locale).returns('en') | |
| 53 | 54 | with_box_decorator self do |
| 54 | 55 | display_box_content(box, '') |
| 55 | 56 | end |
| ... | ... | @@ -67,6 +68,7 @@ class BoxesHelperTest < Test::Unit::TestCase |
| 67 | 68 | expects(:display_block).with(b, '').never |
| 68 | 69 | expects(:request).returns(request) |
| 69 | 70 | stubs(:block_target).returns('') |
| 71 | + expects(:locale).returns('en') | |
| 70 | 72 | display_box_content(box, '') |
| 71 | 73 | end |
| 72 | 74 | |
| ... | ... | @@ -102,14 +104,15 @@ class BoxesHelperTest < Test::Unit::TestCase |
| 102 | 104 | assert block_css_classes(Block.new(:display => 'never')).split.any? { |item| item == 'invisible-block'} |
| 103 | 105 | end |
| 104 | 106 | |
| 105 | - should 'fill context with the article and request_path' do | |
| 107 | + should 'fill context with the article, request_path and locale' do | |
| 106 | 108 | request = mock() |
| 107 | 109 | box = mock() |
| 108 | 110 | |
| 109 | 111 | box.expects(:blocks).returns([]) |
| 110 | 112 | request.expects(:path).returns('/') |
| 111 | 113 | expects(:request).returns(request) |
| 112 | - box_decorator.expects(:select_blocks).with([], {:article => nil, :request_path => '/'}).returns([]) | |
| 114 | + expects(:locale).returns('en') | |
| 115 | + box_decorator.expects(:select_blocks).with([], {:article => nil, :request_path => '/', :locale => 'en'}).returns([]) | |
| 113 | 116 | |
| 114 | 117 | display_box_content(box, '') |
| 115 | 118 | end | ... | ... |