Commit f92f835b5c5fe168ea348f3cdc9617c79689a934
Committed by
Antonio Terceiro
1 parent
afb1b60d
Exists in
master
and in
29 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,7 +65,7 @@ module BoxesHelper | ||
65 | end | 65 | end |
66 | 66 | ||
67 | def display_box_content(box, main_content) | 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 | box_decorator.select_blocks(box.blocks, context).map { |item| display_block(item, main_content) }.join("\n") + box_decorator.block_target(box) | 69 | box_decorator.select_blocks(box.blocks, context).map { |item| display_block(item, main_content) }.join("\n") + box_decorator.block_target(box) |
70 | end | 70 | end |
71 | 71 |
app/models/block.rb
@@ -19,15 +19,21 @@ class Block < ActiveRecord::Base | @@ -19,15 +19,21 @@ class Block < ActiveRecord::Base | ||
19 | # may contain the following keys: | 19 | # may contain the following keys: |
20 | # | 20 | # |
21 | # * <tt>:article</tt>: the article being viewed currently | 21 | # * <tt>:article</tt>: the article being viewed currently |
22 | + # * <tt>:language</tt>: in which language the block will be displayed | ||
22 | def visible?(context = nil) | 23 | def visible?(context = nil) |
23 | if display == 'never' | 24 | if display == 'never' |
24 | return false | 25 | return false |
25 | end | 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 | end | 37 | end |
32 | end | 38 | end |
33 | true | 39 | true |
@@ -41,6 +47,11 @@ class Block < ActiveRecord::Base | @@ -41,6 +47,11 @@ class Block < ActiveRecord::Base | ||
41 | # homepage of its owner. | 47 | # homepage of its owner. |
42 | settings_items :display, :type => :string, :default => 'always' | 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 | # returns the description of the block, used when the user sees a list of | 55 | # returns the description of the block, used when the user sees a list of |
45 | # blocks to choose one to include in the design. | 56 | # blocks to choose one to include in the design. |
46 | # | 57 | # |
app/views/box_organizer/edit.rhtml
@@ -18,6 +18,8 @@ | @@ -18,6 +18,8 @@ | ||
18 | <%= label_tag('block_display_never', _("Don't display")) %> | 18 | <%= label_tag('block_display_never', _("Don't display")) %> |
19 | </div> | 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 | <% button_bar do %> | 23 | <% button_bar do %> |
22 | <%= submit_button(:save, _('Save')) %> | 24 | <%= submit_button(:save, _('Save')) %> |
23 | <%= lightbox_close_button(_('Cancel')) %> | 25 | <%= lightbox_close_button(_('Cancel')) %> |
@@ -0,0 +1,38 @@ | @@ -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,4 +110,30 @@ class BlockTest < Test::Unit::TestCase | ||
110 | assert_equal 'always', block.display | 110 | assert_equal 'always', block.display |
111 | end | 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 | end | 139 | end |
test/unit/boxes_helper_test.rb
@@ -50,6 +50,7 @@ class BoxesHelperTest < Test::Unit::TestCase | @@ -50,6 +50,7 @@ class BoxesHelperTest < Test::Unit::TestCase | ||
50 | expects(:display_block).with(b, '') | 50 | expects(:display_block).with(b, '') |
51 | expects(:request).returns(request) | 51 | expects(:request).returns(request) |
52 | stubs(:block_target).returns('') | 52 | stubs(:block_target).returns('') |
53 | + expects(:locale).returns('en') | ||
53 | with_box_decorator self do | 54 | with_box_decorator self do |
54 | display_box_content(box, '') | 55 | display_box_content(box, '') |
55 | end | 56 | end |
@@ -67,6 +68,7 @@ class BoxesHelperTest < Test::Unit::TestCase | @@ -67,6 +68,7 @@ class BoxesHelperTest < Test::Unit::TestCase | ||
67 | expects(:display_block).with(b, '').never | 68 | expects(:display_block).with(b, '').never |
68 | expects(:request).returns(request) | 69 | expects(:request).returns(request) |
69 | stubs(:block_target).returns('') | 70 | stubs(:block_target).returns('') |
71 | + expects(:locale).returns('en') | ||
70 | display_box_content(box, '') | 72 | display_box_content(box, '') |
71 | end | 73 | end |
72 | 74 | ||
@@ -102,14 +104,15 @@ class BoxesHelperTest < Test::Unit::TestCase | @@ -102,14 +104,15 @@ class BoxesHelperTest < Test::Unit::TestCase | ||
102 | assert block_css_classes(Block.new(:display => 'never')).split.any? { |item| item == 'invisible-block'} | 104 | assert block_css_classes(Block.new(:display => 'never')).split.any? { |item| item == 'invisible-block'} |
103 | end | 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 | request = mock() | 108 | request = mock() |
107 | box = mock() | 109 | box = mock() |
108 | 110 | ||
109 | box.expects(:blocks).returns([]) | 111 | box.expects(:blocks).returns([]) |
110 | request.expects(:path).returns('/') | 112 | request.expects(:path).returns('/') |
111 | expects(:request).returns(request) | 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 | display_box_content(box, '') | 117 | display_box_content(box, '') |
115 | end | 118 | end |