Commit c0a1a0bd authored by Arthur Del Esposte's avatar Arthur Del Esposte Committed by Daniela Soares Feitosa

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
parent 1e450b5b
......@@ -2,11 +2,12 @@ class ContextContentPlugin::ContextContentBlock < Block
settings_items :show_name, :type => :boolean, :default => true
settings_items :show_image, :type => :boolean, :default => true
settings_items :use_parent_title, :type => :boolean, :default => false
settings_items :show_parent_content, :type => :boolean, :default => true
settings_items :types, :type => Array, :default => ['UploadedFile']
settings_items :limit, :type => :integer, :default => 6
attr_accessible :show_image, :show_name, :show_parent_content, :types
attr_accessible :show_image, :show_name, :use_parent_title, :show_parent_content, :types
alias :profile :owner
......@@ -65,6 +66,11 @@ class ContextContentPlugin::ContextContentBlock < Block
end
end
def parent_title(contents)
return nil if contents.blank?
contents.first.parent.name
end
def footer
block = self
proc do
......@@ -82,9 +88,9 @@ class ContextContentPlugin::ContextContentBlock < Block
block = self
proc do
contents = block.contents(@page)
parent_title = block.parent_title(contents)
if !contents.blank?
block_title(block.title) + content_tag('div',
render(:file => 'blocks/context_content', :locals => {:block => block, :contents => contents}), :class => 'contents', :id => "context_content_#{block.id}")
render(:file => 'blocks/context_content', :locals => {:block => block, :contents => contents, :parent_title => parent_title})
else
''
end
......
......@@ -4,12 +4,13 @@ class ContentViewerControllerTest < ActionController::TestCase
def setup
@profile = fast_create(Community)
@page = fast_create(Folder, :profile_id => @profile.id)
@page = fast_create(Folder, :profile_id => @profile.id, :name => "New Folder")
box = Box.create!(:owner => @profile)
@block = ContextContentPlugin::ContextContentBlock.new(:box_id => box.id)
@block.types = ['TinyMceArticle']
@block.limit = 1
@block.title = "New Context Block"
@block.save!
end
......@@ -27,6 +28,24 @@ class ContentViewerControllerTest < ActionController::TestCase
assert_match /article1/, @response.body
end
should 'display context content block title if it is not configured to use_parent_title' do
@block.use_parent_title = false
@block.save
article = fast_create(TinyMceArticle, :parent_id => @page.id, :profile_id => @profile.id, :name => 'article1')
get :view_page, @page.url
assert_tag 'h3', :attributes => {:class => 'block-title'}, :content => @block.title
assert_no_tag 'h3', :attributes => {:class => 'block-title'}, :content => @page.name
end
should 'display context content with folder title if it is configured to use_parent_title' do
@block.use_parent_title = true
@block.save
article = fast_create(TinyMceArticle, :parent_id => @page.id, :profile_id => @profile.id, :name => 'article1')
get :view_page, @page.url
assert_tag 'h3', :attributes => {:class => 'block-title'}, :content => @page.name
assert_no_tag 'h3', :attributes => {:class => 'block-title'}, :content => @block.title
end
should 'display context content block with pagination' do
article1 = fast_create(TinyMceArticle, :parent_id => @page.id, :profile_id => @profile.id)
article2 = fast_create(TinyMceArticle, :parent_id => @page.id, :profile_id => @profile.id)
......
......@@ -27,6 +27,7 @@ class ProfileDesignControllerTest < ActionController::TestCase
assert_tag :tag => 'input', :attributes => { :id => 'block_title' }
assert_tag :tag => 'input', :attributes => { :id => 'block_show_image' }
assert_tag :tag => 'input', :attributes => { :id => 'block_show_name' }
assert_tag :tag => 'input', :attributes => { :id => 'block_use_parent_title' }
assert_tag :tag => 'input', :attributes => { :id => 'block_show_parent_content' }
assert_tag :tag => 'input', :attributes => { :name => 'block[types][]' }
end
......
......@@ -27,9 +27,7 @@ class ContextContentBlockTest < ActiveSupport::TestCase
should 'render context content block view' do
@page = fast_create(Folder)
article = fast_create(TinyMceArticle, :parent_id => @page.id)
expects(:block_title).with(@block.title).returns('').once
expects(:content_tag).returns('').once
expects(:render).with(:file => 'blocks/context_content', :locals => {:block => @block, :contents => [article]})
expects(:render).with(:file => 'blocks/context_content', :locals => {:block => @block, :contents => [article], :parent_title => @page.name})
instance_eval(&@block.content)
end
......@@ -39,6 +37,16 @@ class ContextContentBlockTest < ActiveSupport::TestCase
assert_equal [article], @block.contents(folder)
end
should 'return parent name of the contents' do
folder = fast_create(Folder, :name => " New Folder")
article = fast_create(TinyMceArticle, :parent_id => folder.id)
assert_equal folder.name, @block.parent_title([article])
end
should 'return no parent name if there is no content' do
assert_nil @block.parent_title([])
end
should 'limit number of children to display' do
@block.limit = 2
folder = fast_create(Folder)
......
<% contents.each do |content| %>
<% content = FilePresenter.for(content) %>
<span class="item">
<a href="<%= url_for(content.view_url) %>">
<div class="image">
<%= instance_eval(&block.content_image(content)) if block.show_image %>
</div>
<% if block.show_name %>
<div class="name"><%= content.name %></div>
<% end %>
</a>
</span>
<% if block.use_parent_title %>
<%= block_title(parent_title) %>
<% else %>
<%= block_title(block.title) %>
<% end %>
<div class='contents' id='<%="context_content_#{block.id}"%>'>
<% contents.each do |content| %>
<% content = FilePresenter.for(content) %>
<span class="item">
<a href="<%= url_for(content.view_url) %>">
<div class="image">
<%= instance_eval(&block.content_image(content)) if block.show_image %>
</div>
<% if block.show_name %>
<div class="name"><%= content.name %></div>
<% end %>
</a>
</span>
<% end %>
</div>
\ No newline at end of file
......@@ -2,7 +2,8 @@
<%= labelled_form_field c_('Limit of items'), text_field(:block, :limit, :size => 3) %>
<%= labelled_form_field check_box(:block, :show_name) + _('Show content name'), '' %>
<%= labelled_form_field check_box(:block, :show_image) + _('Show content image'), '' %>
<%= labelled_form_field check_box(:block, :show_parent_content) + _('Show parent content when children is empty'), '' %>
<%= labelled_form_field check_box(:block, :use_parent_title) + _('Use the name of the source folder as block title'), '' %>
<%= labelled_form_field check_box(:block, :show_parent_content) + _('Show block on all existing pages in the source folder'), '' %>
<br/>
<%= label :block, :types, _('Display content types:'), :class => 'formlabel' %>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment