diff --git a/plugins/context_content/lib/context_content_plugin/context_content_block.rb b/plugins/context_content/lib/context_content_plugin/context_content_block.rb
index 9df6ead..22f1aed 100644
--- a/plugins/context_content/lib/context_content_plugin/context_content_block.rb
+++ b/plugins/context_content/lib/context_content_plugin/context_content_block.rb
@@ -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
diff --git a/plugins/context_content/test/functional/content_viewer_controller_test.rb b/plugins/context_content/test/functional/content_viewer_controller_test.rb
index 6be97fb..cf86475 100644
--- a/plugins/context_content/test/functional/content_viewer_controller_test.rb
+++ b/plugins/context_content/test/functional/content_viewer_controller_test.rb
@@ -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)
diff --git a/plugins/context_content/test/functional/profile_design_controller_test.rb b/plugins/context_content/test/functional/profile_design_controller_test.rb
index 5c30ab9..edc3d56 100644
--- a/plugins/context_content/test/functional/profile_design_controller_test.rb
+++ b/plugins/context_content/test/functional/profile_design_controller_test.rb
@@ -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
diff --git a/plugins/context_content/test/unit/context_content_block_test.rb b/plugins/context_content/test/unit/context_content_block_test.rb
index b28c38b..5d7736a 100644
--- a/plugins/context_content/test/unit/context_content_block_test.rb
+++ b/plugins/context_content/test/unit/context_content_block_test.rb
@@ -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)
diff --git a/plugins/context_content/views/blocks/context_content.html.erb b/plugins/context_content/views/blocks/context_content.html.erb
index b68224a..c15a36e 100644
--- a/plugins/context_content/views/blocks/context_content.html.erb
+++ b/plugins/context_content/views/blocks/context_content.html.erb
@@ -1,13 +1,21 @@
-<% contents.each do |content| %>
- <% content = FilePresenter.for(content) %>
-
-
-