Commit c0a1a0bdb8d2c8d024767d59a604a7ae6f6a9396
Committed by
Daniela Feitosa
1 parent
1e450b5b
Exists in
staging
and in
37 other branches
Add option to context_content to use parent folder name instead of block title
Also: Improve ContextContent plugin's view text See merge request !713
Showing
6 changed files
with
63 additions
and
20 deletions
Show diff stats
plugins/context_content/lib/context_content_plugin/context_content_block.rb
@@ -2,11 +2,12 @@ class ContextContentPlugin::ContextContentBlock < Block | @@ -2,11 +2,12 @@ class ContextContentPlugin::ContextContentBlock < Block | ||
2 | 2 | ||
3 | settings_items :show_name, :type => :boolean, :default => true | 3 | settings_items :show_name, :type => :boolean, :default => true |
4 | settings_items :show_image, :type => :boolean, :default => true | 4 | settings_items :show_image, :type => :boolean, :default => true |
5 | + settings_items :use_parent_title, :type => :boolean, :default => false | ||
5 | settings_items :show_parent_content, :type => :boolean, :default => true | 6 | settings_items :show_parent_content, :type => :boolean, :default => true |
6 | settings_items :types, :type => Array, :default => ['UploadedFile'] | 7 | settings_items :types, :type => Array, :default => ['UploadedFile'] |
7 | settings_items :limit, :type => :integer, :default => 6 | 8 | settings_items :limit, :type => :integer, :default => 6 |
8 | 9 | ||
9 | - attr_accessible :show_image, :show_name, :show_parent_content, :types | 10 | + attr_accessible :show_image, :show_name, :use_parent_title, :show_parent_content, :types |
10 | 11 | ||
11 | alias :profile :owner | 12 | alias :profile :owner |
12 | 13 | ||
@@ -65,6 +66,11 @@ class ContextContentPlugin::ContextContentBlock < Block | @@ -65,6 +66,11 @@ class ContextContentPlugin::ContextContentBlock < Block | ||
65 | end | 66 | end |
66 | end | 67 | end |
67 | 68 | ||
69 | + def parent_title(contents) | ||
70 | + return nil if contents.blank? | ||
71 | + contents.first.parent.name | ||
72 | + end | ||
73 | + | ||
68 | def footer | 74 | def footer |
69 | block = self | 75 | block = self |
70 | proc do | 76 | proc do |
@@ -82,9 +88,9 @@ class ContextContentPlugin::ContextContentBlock < Block | @@ -82,9 +88,9 @@ class ContextContentPlugin::ContextContentBlock < Block | ||
82 | block = self | 88 | block = self |
83 | proc do | 89 | proc do |
84 | contents = block.contents(@page) | 90 | contents = block.contents(@page) |
91 | + parent_title = block.parent_title(contents) | ||
85 | if !contents.blank? | 92 | if !contents.blank? |
86 | - block_title(block.title) + content_tag('div', | ||
87 | - render(:file => 'blocks/context_content', :locals => {:block => block, :contents => contents}), :class => 'contents', :id => "context_content_#{block.id}") | 93 | + render(:file => 'blocks/context_content', :locals => {:block => block, :contents => contents, :parent_title => parent_title}) |
88 | else | 94 | else |
89 | '' | 95 | '' |
90 | end | 96 | end |
plugins/context_content/test/functional/content_viewer_controller_test.rb
@@ -4,12 +4,13 @@ class ContentViewerControllerTest < ActionController::TestCase | @@ -4,12 +4,13 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | @profile = fast_create(Community) | 6 | @profile = fast_create(Community) |
7 | - @page = fast_create(Folder, :profile_id => @profile.id) | 7 | + @page = fast_create(Folder, :profile_id => @profile.id, :name => "New Folder") |
8 | 8 | ||
9 | box = Box.create!(:owner => @profile) | 9 | box = Box.create!(:owner => @profile) |
10 | @block = ContextContentPlugin::ContextContentBlock.new(:box_id => box.id) | 10 | @block = ContextContentPlugin::ContextContentBlock.new(:box_id => box.id) |
11 | @block.types = ['TinyMceArticle'] | 11 | @block.types = ['TinyMceArticle'] |
12 | @block.limit = 1 | 12 | @block.limit = 1 |
13 | + @block.title = "New Context Block" | ||
13 | @block.save! | 14 | @block.save! |
14 | end | 15 | end |
15 | 16 | ||
@@ -27,6 +28,24 @@ class ContentViewerControllerTest < ActionController::TestCase | @@ -27,6 +28,24 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
27 | assert_match /article1/, @response.body | 28 | assert_match /article1/, @response.body |
28 | end | 29 | end |
29 | 30 | ||
31 | + should 'display context content block title if it is not configured to use_parent_title' do | ||
32 | + @block.use_parent_title = false | ||
33 | + @block.save | ||
34 | + article = fast_create(TinyMceArticle, :parent_id => @page.id, :profile_id => @profile.id, :name => 'article1') | ||
35 | + get :view_page, @page.url | ||
36 | + assert_tag 'h3', :attributes => {:class => 'block-title'}, :content => @block.title | ||
37 | + assert_no_tag 'h3', :attributes => {:class => 'block-title'}, :content => @page.name | ||
38 | + end | ||
39 | + | ||
40 | + should 'display context content with folder title if it is configured to use_parent_title' do | ||
41 | + @block.use_parent_title = true | ||
42 | + @block.save | ||
43 | + article = fast_create(TinyMceArticle, :parent_id => @page.id, :profile_id => @profile.id, :name => 'article1') | ||
44 | + get :view_page, @page.url | ||
45 | + assert_tag 'h3', :attributes => {:class => 'block-title'}, :content => @page.name | ||
46 | + assert_no_tag 'h3', :attributes => {:class => 'block-title'}, :content => @block.title | ||
47 | + end | ||
48 | + | ||
30 | should 'display context content block with pagination' do | 49 | should 'display context content block with pagination' do |
31 | article1 = fast_create(TinyMceArticle, :parent_id => @page.id, :profile_id => @profile.id) | 50 | article1 = fast_create(TinyMceArticle, :parent_id => @page.id, :profile_id => @profile.id) |
32 | article2 = fast_create(TinyMceArticle, :parent_id => @page.id, :profile_id => @profile.id) | 51 | article2 = fast_create(TinyMceArticle, :parent_id => @page.id, :profile_id => @profile.id) |
plugins/context_content/test/functional/profile_design_controller_test.rb
@@ -27,6 +27,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -27,6 +27,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
27 | assert_tag :tag => 'input', :attributes => { :id => 'block_title' } | 27 | assert_tag :tag => 'input', :attributes => { :id => 'block_title' } |
28 | assert_tag :tag => 'input', :attributes => { :id => 'block_show_image' } | 28 | assert_tag :tag => 'input', :attributes => { :id => 'block_show_image' } |
29 | assert_tag :tag => 'input', :attributes => { :id => 'block_show_name' } | 29 | assert_tag :tag => 'input', :attributes => { :id => 'block_show_name' } |
30 | + assert_tag :tag => 'input', :attributes => { :id => 'block_use_parent_title' } | ||
30 | assert_tag :tag => 'input', :attributes => { :id => 'block_show_parent_content' } | 31 | assert_tag :tag => 'input', :attributes => { :id => 'block_show_parent_content' } |
31 | assert_tag :tag => 'input', :attributes => { :name => 'block[types][]' } | 32 | assert_tag :tag => 'input', :attributes => { :name => 'block[types][]' } |
32 | end | 33 | end |
plugins/context_content/test/unit/context_content_block_test.rb
@@ -27,9 +27,7 @@ class ContextContentBlockTest < ActiveSupport::TestCase | @@ -27,9 +27,7 @@ class ContextContentBlockTest < ActiveSupport::TestCase | ||
27 | should 'render context content block view' do | 27 | should 'render context content block view' do |
28 | @page = fast_create(Folder) | 28 | @page = fast_create(Folder) |
29 | article = fast_create(TinyMceArticle, :parent_id => @page.id) | 29 | article = fast_create(TinyMceArticle, :parent_id => @page.id) |
30 | - expects(:block_title).with(@block.title).returns('').once | ||
31 | - expects(:content_tag).returns('').once | ||
32 | - expects(:render).with(:file => 'blocks/context_content', :locals => {:block => @block, :contents => [article]}) | 30 | + expects(:render).with(:file => 'blocks/context_content', :locals => {:block => @block, :contents => [article], :parent_title => @page.name}) |
33 | instance_eval(&@block.content) | 31 | instance_eval(&@block.content) |
34 | end | 32 | end |
35 | 33 | ||
@@ -39,6 +37,16 @@ class ContextContentBlockTest < ActiveSupport::TestCase | @@ -39,6 +37,16 @@ class ContextContentBlockTest < ActiveSupport::TestCase | ||
39 | assert_equal [article], @block.contents(folder) | 37 | assert_equal [article], @block.contents(folder) |
40 | end | 38 | end |
41 | 39 | ||
40 | + should 'return parent name of the contents' do | ||
41 | + folder = fast_create(Folder, :name => " New Folder") | ||
42 | + article = fast_create(TinyMceArticle, :parent_id => folder.id) | ||
43 | + assert_equal folder.name, @block.parent_title([article]) | ||
44 | + end | ||
45 | + | ||
46 | + should 'return no parent name if there is no content' do | ||
47 | + assert_nil @block.parent_title([]) | ||
48 | + end | ||
49 | + | ||
42 | should 'limit number of children to display' do | 50 | should 'limit number of children to display' do |
43 | @block.limit = 2 | 51 | @block.limit = 2 |
44 | folder = fast_create(Folder) | 52 | folder = fast_create(Folder) |
plugins/context_content/views/blocks/context_content.html.erb
1 | -<% contents.each do |content| %> | ||
2 | - <% content = FilePresenter.for(content) %> | ||
3 | - <span class="item"> | ||
4 | - <a href="<%= url_for(content.view_url) %>"> | ||
5 | - <div class="image"> | ||
6 | - <%= instance_eval(&block.content_image(content)) if block.show_image %> | ||
7 | - </div> | ||
8 | - <% if block.show_name %> | ||
9 | - <div class="name"><%= content.name %></div> | ||
10 | - <% end %> | ||
11 | - </a> | ||
12 | - </span> | 1 | +<% if block.use_parent_title %> |
2 | + <%= block_title(parent_title) %> | ||
3 | +<% else %> | ||
4 | + <%= block_title(block.title) %> | ||
13 | <% end %> | 5 | <% end %> |
6 | + | ||
7 | +<div class='contents' id='<%="context_content_#{block.id}"%>'> | ||
8 | + <% contents.each do |content| %> | ||
9 | + <% content = FilePresenter.for(content) %> | ||
10 | + <span class="item"> | ||
11 | + <a href="<%= url_for(content.view_url) %>"> | ||
12 | + <div class="image"> | ||
13 | + <%= instance_eval(&block.content_image(content)) if block.show_image %> | ||
14 | + </div> | ||
15 | + <% if block.show_name %> | ||
16 | + <div class="name"><%= content.name %></div> | ||
17 | + <% end %> | ||
18 | + </a> | ||
19 | + </span> | ||
20 | + <% end %> | ||
21 | +</div> | ||
14 | \ No newline at end of file | 22 | \ No newline at end of file |
plugins/context_content/views/box_organizer/context_content_plugin/_context_content_block.html.erb
@@ -2,7 +2,8 @@ | @@ -2,7 +2,8 @@ | ||
2 | <%= labelled_form_field c_('Limit of items'), text_field(:block, :limit, :size => 3) %> | 2 | <%= labelled_form_field c_('Limit of items'), text_field(:block, :limit, :size => 3) %> |
3 | <%= labelled_form_field check_box(:block, :show_name) + _('Show content name'), '' %> | 3 | <%= labelled_form_field check_box(:block, :show_name) + _('Show content name'), '' %> |
4 | <%= labelled_form_field check_box(:block, :show_image) + _('Show content image'), '' %> | 4 | <%= labelled_form_field check_box(:block, :show_image) + _('Show content image'), '' %> |
5 | - <%= labelled_form_field check_box(:block, :show_parent_content) + _('Show parent content when children is empty'), '' %> | 5 | + <%= labelled_form_field check_box(:block, :use_parent_title) + _('Use the name of the source folder as block title'), '' %> |
6 | + <%= labelled_form_field check_box(:block, :show_parent_content) + _('Show block on all existing pages in the source folder'), '' %> | ||
6 | 7 | ||
7 | <br/> | 8 | <br/> |
8 | <%= label :block, :types, _('Display content types:'), :class => 'formlabel' %> | 9 | <%= label :block, :types, _('Display content types:'), :class => 'formlabel' %> |