diff --git a/plugins/breadcrumbs/lib/breadcrumbs_block.rb b/plugins/breadcrumbs/lib/breadcrumbs_block.rb deleted file mode 100644 index ec4b731..0000000 --- a/plugins/breadcrumbs/lib/breadcrumbs_block.rb +++ /dev/null @@ -1,60 +0,0 @@ -class BreadcrumbsBlock < Block - - settings_items :show_cms_action, :type => :boolean, :default => true - settings_items :show_profile, :type => :boolean, :default => true - - def self.description - _('Breadcrumbs') - end - - def help - _('This block displays breadcrumb trail.') - end - - def page_trail(page, params={}) - links = [] - if page - links = page.ancestors.reverse.map { |p| { :name => p.title, :url => p.url } } - links << { :name => page.title, :url => page.url } - elsif params[:controller] == 'cms' - id = params[:id] || params[:parent_id] - links = page_trail(Article.find(id)) if id - links << { :name => cms_action(params[:action]), :url => params } if show_cms_action - end - links - end - - def trail(page, profile=nil, params={}) - links = page_trail(page, params) - if profile && !links.empty? && show_profile - [ {:name => profile.name, :url => profile.url} ] + links - else - links - end - end - - def content(args={}) - block = self - lambda do - trail = block.trail(@page, @profile, params) - if !trail.empty? - trail.map { |t| link_to(t[:name], t[:url], :class => 'item') }.join(content_tag('span', ' > ', :class => 'separator')) - else - '' - end - end - end - - def cacheable? - false - end - - protected - - CMS_ACTIONS = {:edit => _('Edit'), :upload_files => _('Upload Files'), :new => _('New')} - - def cms_action(action) - CMS_ACTIONS[action.to_sym] || action - end - -end diff --git a/plugins/breadcrumbs/lib/breadcrumbs_plugin.rb b/plugins/breadcrumbs/lib/breadcrumbs_plugin.rb index 40fd097..b62412b 100644 --- a/plugins/breadcrumbs/lib/breadcrumbs_plugin.rb +++ b/plugins/breadcrumbs/lib/breadcrumbs_plugin.rb @@ -7,9 +7,9 @@ class BreadcrumbsPlugin < Noosfero::Plugin def self.plugin_description _("A plugin that add a block to display breadcrumbs.") end - + def self.extra_blocks - { BreadcrumbsBlock => {:type => [Community, Person, Enterprise] } } + { BreadcrumbsPlugin::ContentBreadcrumbsBlock => {:type => [Community, Person, Enterprise] } } end end diff --git a/plugins/breadcrumbs/lib/breadcrumbs_plugin/content_breadcrumbs_block.rb b/plugins/breadcrumbs/lib/breadcrumbs_plugin/content_breadcrumbs_block.rb new file mode 100644 index 0000000..f8d2595 --- /dev/null +++ b/plugins/breadcrumbs/lib/breadcrumbs_plugin/content_breadcrumbs_block.rb @@ -0,0 +1,60 @@ +class BreadcrumbsPlugin::ContentBreadcrumbsBlock < Block + + settings_items :show_cms_action, :type => :boolean, :default => true + settings_items :show_profile, :type => :boolean, :default => true + + def self.description + _('Content Breadcrumbs') + end + + def help + _('This block displays breadcrumb trail.') + end + + def page_trail(page, params={}) + links = [] + if page + links = page.ancestors.reverse.map { |p| { :name => p.title, :url => p.url } } + links << { :name => page.title, :url => page.url } + elsif params[:controller] == 'cms' + id = params[:id] || params[:parent_id] + links = page_trail(Article.find(id)) if id + links << { :name => cms_action(params[:action]), :url => params } if show_cms_action + end + links + end + + def trail(page, profile=nil, params={}) + links = page_trail(page, params) + if profile && !links.empty? && show_profile + [ {:name => profile.name, :url => profile.url} ] + links + else + links + end + end + + def content(args={}) + block = self + lambda do + trail = block.trail(@page, @profile, params) + if !trail.empty? + trail.map { |t| link_to(t[:name], t[:url], :class => 'item') }.join(content_tag('span', ' > ', :class => 'separator')) + else + '' + end + end + end + + def cacheable? + false + end + + protected + + CMS_ACTIONS = {:edit => _('Edit'), :upload_files => _('Upload Files'), :new => _('New')} + + def cms_action(action) + CMS_ACTIONS[action.to_sym] || action + end + +end diff --git a/plugins/breadcrumbs/test/functional/profile_design_controller_test.rb b/plugins/breadcrumbs/test/functional/profile_design_controller_test.rb index 36a9957..ceda959 100644 --- a/plugins/breadcrumbs/test/functional/profile_design_controller_test.rb +++ b/plugins/breadcrumbs/test/functional/profile_design_controller_test.rb @@ -2,16 +2,15 @@ require File.dirname(__FILE__) + '/../test_helper' class ProfileDesignController append_view_path File.join(File.dirname(__FILE__) + '/../../views') - def rescue_action(e) - raise e - end + def rescue_action(e) + raise e + end end class ProfileDesignControllerTest < ActionController::TestCase def setup - Environment.delete_all - @environment = Environment.create(:name => 'testenv', :is_default => true) + @environment = Environment.default @environment.enabled_plugins = ['BreadcrumbsPlugin'] @environment.save! @@ -19,7 +18,7 @@ class ProfileDesignControllerTest < ActionController::TestCase @page = fast_create(Folder, :profile_id => @profile.id) box = Box.create!(:owner => @profile) - @block = BreadcrumbsBlock.create!(:box => box) + @block = BreadcrumbsPlugin::ContentBreadcrumbsBlock.create!(:box => box) user = create_user('testinguser') @profile.add_admin(user.person) diff --git a/plugins/breadcrumbs/test/unit/breadcrumbs_block_test.rb b/plugins/breadcrumbs/test/unit/breadcrumbs_block_test.rb deleted file mode 100644 index 71a7070..0000000 --- a/plugins/breadcrumbs/test/unit/breadcrumbs_block_test.rb +++ /dev/null @@ -1,75 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class BreadcrumbsBlockTest < ActiveSupport::TestCase - - include NoosferoTestHelper - - def setup - @block = BreadcrumbsBlock.new - @profile = fast_create(Community) - @folder = fast_create(Folder, :profile_id => @profile.id) - @article = fast_create(Folder, :profile_id => @profile.id, :parent_id => @folder.id) - @params = {} - end - - attr_reader :params - - should 'has a description' do - assert_not_equal Block.description, BreadcrumbsBlock.description - end - - should 'has a help' do - assert @block.help - end - - should 'return path of links to reach a page' do - links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] - assert_equal links, @block.page_trail(@article) - end - - should 'return path of links when current page is at cms controller' do - params = {:controller => 'cms', :action => 'edit', :id => @article.id} - links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}, {:url=>{:controller=>"cms", :action=>"edit", :id=>@article.id}, :name=>"Edit"}] - assert_equal links, @block.page_trail(nil, params) - end - - should 'not return cms action link when show_cms_action is false' do - params = {:controller => 'cms', :action => 'edit', :id => @article.id} - links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] - @block.show_cms_action = false - assert_equal links, @block.page_trail(nil, params) - end - - should 'include profile link on path of links to reach a page' do - links = [{:name => @profile.name, :url => @profile.url}, {:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] - assert_equal links, @block.trail(@article, @profile) - end - - should 'not include profile link on path of links when show_profile is false' do - links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] - @block.show_profile = false - assert_equal links, @block.trail(@article, @profile) - end - - should 'not include profile link on path of links when trail is empty' do - assert_equal [], @block.trail(nil, @profile) - end - - should 'render trail if there is links to show' do - @page = @article - trail = instance_eval(&@block.content) - assert_match /#{@profile.name}/, trail - assert_match /#{@folder.name}/, trail - assert_match /#{@page.name}/, trail - end - - should 'render nothing if there is no links to show' do - @page = nil - assert_equal '', instance_eval(&@block.content) - end - - should 'not be cacheable' do - assert !@block.cacheable? - end - -end diff --git a/plugins/breadcrumbs/test/unit/breadcrumbs_plugin_test.rb b/plugins/breadcrumbs/test/unit/breadcrumbs_plugin_test.rb index e7fcee7..5506760 100644 --- a/plugins/breadcrumbs/test/unit/breadcrumbs_plugin_test.rb +++ b/plugins/breadcrumbs/test/unit/breadcrumbs_plugin_test.rb @@ -13,9 +13,9 @@ class BreadcrumbsPluginTest < ActiveSupport::TestCase should 'has a description' do assert !BreadcrumbsPlugin.plugin_description.blank? end - + should 'add a block' do - assert_equal [BreadcrumbsBlock], BreadcrumbsPlugin.extra_blocks.keys + assert_equal [BreadcrumbsPlugin::ContentBreadcrumbsBlock], BreadcrumbsPlugin.extra_blocks.keys end end diff --git a/plugins/breadcrumbs/test/unit/content_breadcrumbs_block_test.rb b/plugins/breadcrumbs/test/unit/content_breadcrumbs_block_test.rb new file mode 100644 index 0000000..5368ba1 --- /dev/null +++ b/plugins/breadcrumbs/test/unit/content_breadcrumbs_block_test.rb @@ -0,0 +1,75 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class ContentBreadcrumbsBlockTest < ActiveSupport::TestCase + + include NoosferoTestHelper + + def setup + @block = BreadcrumbsPlugin::ContentBreadcrumbsBlock.new + @profile = fast_create(Community) + @folder = fast_create(Folder, :profile_id => @profile.id) + @article = fast_create(Folder, :profile_id => @profile.id, :parent_id => @folder.id) + @params = {} + end + + attr_reader :params + + should 'has a description' do + assert_not_equal Block.description, BreadcrumbsPlugin::ContentBreadcrumbsBlock.description + end + + should 'has a help' do + assert @block.help + end + + should 'return path of links to reach a page' do + links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] + assert_equal links, @block.page_trail(@article) + end + + should 'return path of links when current page is at cms controller' do + params = {:controller => 'cms', :action => 'edit', :id => @article.id} + links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}, {:url=>{:controller=>"cms", :action=>"edit", :id=>@article.id}, :name=>"Edit"}] + assert_equal links, @block.page_trail(nil, params) + end + + should 'not return cms action link when show_cms_action is false' do + params = {:controller => 'cms', :action => 'edit', :id => @article.id} + links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] + @block.show_cms_action = false + assert_equal links, @block.page_trail(nil, params) + end + + should 'include profile link on path of links to reach a page' do + links = [{:name => @profile.name, :url => @profile.url}, {:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] + assert_equal links, @block.trail(@article, @profile) + end + + should 'not include profile link on path of links when show_profile is false' do + links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] + @block.show_profile = false + assert_equal links, @block.trail(@article, @profile) + end + + should 'not include profile link on path of links when trail is empty' do + assert_equal [], @block.trail(nil, @profile) + end + + should 'render trail if there is links to show' do + @page = @article + trail = instance_eval(&@block.content) + assert_match /#{@profile.name}/, trail + assert_match /#{@folder.name}/, trail + assert_match /#{@page.name}/, trail + end + + should 'render nothing if there is no links to show' do + @page = nil + assert_equal '', instance_eval(&@block.content) + end + + should 'not be cacheable' do + assert !@block.cacheable? + end + +end diff --git a/plugins/breadcrumbs/views/box_organizer/_breadcrumbs_block.rhtml b/plugins/breadcrumbs/views/box_organizer/_breadcrumbs_block.rhtml deleted file mode 100644 index 8692a79..0000000 --- a/plugins/breadcrumbs/views/box_organizer/_breadcrumbs_block.rhtml +++ /dev/null @@ -1,4 +0,0 @@ -
- <%= labelled_form_field check_box(:block, :show_cms_action) + _('Show cms action'), '' %> - <%= labelled_form_field check_box(:block, :show_profile) + _('Show profile'), '' %> -
diff --git a/plugins/breadcrumbs/views/box_organizer/breadcrumbs_plugin/_content_breadcrumbs_block.rhtml b/plugins/breadcrumbs/views/box_organizer/breadcrumbs_plugin/_content_breadcrumbs_block.rhtml new file mode 100644 index 0000000..8692a79 --- /dev/null +++ b/plugins/breadcrumbs/views/box_organizer/breadcrumbs_plugin/_content_breadcrumbs_block.rhtml @@ -0,0 +1,4 @@ +
+ <%= labelled_form_field check_box(:block, :show_cms_action) + _('Show cms action'), '' %> + <%= labelled_form_field check_box(:block, :show_profile) + _('Show profile'), '' %> +
diff --git a/plugins/breadcrumbs/views/profile_design b/plugins/breadcrumbs/views/profile_design deleted file mode 120000 index a75d184..0000000 --- a/plugins/breadcrumbs/views/profile_design +++ /dev/null @@ -1 +0,0 @@ -box_organizer \ No newline at end of file diff --git a/plugins/breadcrumbs/views/profile_design/breadcrumbs_plugin b/plugins/breadcrumbs/views/profile_design/breadcrumbs_plugin new file mode 120000 index 0000000..4db4ec1 --- /dev/null +++ b/plugins/breadcrumbs/views/profile_design/breadcrumbs_plugin @@ -0,0 +1 @@ +../box_organizer/breadcrumbs_plugin/ \ No newline at end of file -- libgit2 0.21.2