Commit 8bb809101b910ad58a10a86af8d5eab99a201eb7
1 parent
777b0a5f
Exists in
master
and in
8 other branches
Add breadcrumbs plugin namespace and rename block to ContentBreadcrumbsBlock
Showing
11 changed files
with
149 additions
and
150 deletions
Show diff stats
plugins/breadcrumbs/lib/breadcrumbs_block.rb
... | ... | @@ -1,60 +0,0 @@ |
1 | -class BreadcrumbsBlock < Block | |
2 | - | |
3 | - settings_items :show_cms_action, :type => :boolean, :default => true | |
4 | - settings_items :show_profile, :type => :boolean, :default => true | |
5 | - | |
6 | - def self.description | |
7 | - _('Breadcrumbs') | |
8 | - end | |
9 | - | |
10 | - def help | |
11 | - _('This block displays breadcrumb trail.') | |
12 | - end | |
13 | - | |
14 | - def page_trail(page, params={}) | |
15 | - links = [] | |
16 | - if page | |
17 | - links = page.ancestors.reverse.map { |p| { :name => p.title, :url => p.url } } | |
18 | - links << { :name => page.title, :url => page.url } | |
19 | - elsif params[:controller] == 'cms' | |
20 | - id = params[:id] || params[:parent_id] | |
21 | - links = page_trail(Article.find(id)) if id | |
22 | - links << { :name => cms_action(params[:action]), :url => params } if show_cms_action | |
23 | - end | |
24 | - links | |
25 | - end | |
26 | - | |
27 | - def trail(page, profile=nil, params={}) | |
28 | - links = page_trail(page, params) | |
29 | - if profile && !links.empty? && show_profile | |
30 | - [ {:name => profile.name, :url => profile.url} ] + links | |
31 | - else | |
32 | - links | |
33 | - end | |
34 | - end | |
35 | - | |
36 | - def content(args={}) | |
37 | - block = self | |
38 | - lambda do | |
39 | - trail = block.trail(@page, @profile, params) | |
40 | - if !trail.empty? | |
41 | - trail.map { |t| link_to(t[:name], t[:url], :class => 'item') }.join(content_tag('span', ' > ', :class => 'separator')) | |
42 | - else | |
43 | - '' | |
44 | - end | |
45 | - end | |
46 | - end | |
47 | - | |
48 | - def cacheable? | |
49 | - false | |
50 | - end | |
51 | - | |
52 | - protected | |
53 | - | |
54 | - CMS_ACTIONS = {:edit => _('Edit'), :upload_files => _('Upload Files'), :new => _('New')} | |
55 | - | |
56 | - def cms_action(action) | |
57 | - CMS_ACTIONS[action.to_sym] || action | |
58 | - end | |
59 | - | |
60 | -end |
plugins/breadcrumbs/lib/breadcrumbs_plugin.rb
... | ... | @@ -7,9 +7,9 @@ class BreadcrumbsPlugin < Noosfero::Plugin |
7 | 7 | def self.plugin_description |
8 | 8 | _("A plugin that add a block to display breadcrumbs.") |
9 | 9 | end |
10 | - | |
10 | + | |
11 | 11 | def self.extra_blocks |
12 | - { BreadcrumbsBlock => {:type => [Community, Person, Enterprise] } } | |
12 | + { BreadcrumbsPlugin::ContentBreadcrumbsBlock => {:type => [Community, Person, Enterprise] } } | |
13 | 13 | end |
14 | 14 | |
15 | 15 | end | ... | ... |
plugins/breadcrumbs/lib/breadcrumbs_plugin/content_breadcrumbs_block.rb
0 → 100644
... | ... | @@ -0,0 +1,60 @@ |
1 | +class BreadcrumbsPlugin::ContentBreadcrumbsBlock < Block | |
2 | + | |
3 | + settings_items :show_cms_action, :type => :boolean, :default => true | |
4 | + settings_items :show_profile, :type => :boolean, :default => true | |
5 | + | |
6 | + def self.description | |
7 | + _('Content Breadcrumbs') | |
8 | + end | |
9 | + | |
10 | + def help | |
11 | + _('This block displays breadcrumb trail.') | |
12 | + end | |
13 | + | |
14 | + def page_trail(page, params={}) | |
15 | + links = [] | |
16 | + if page | |
17 | + links = page.ancestors.reverse.map { |p| { :name => p.title, :url => p.url } } | |
18 | + links << { :name => page.title, :url => page.url } | |
19 | + elsif params[:controller] == 'cms' | |
20 | + id = params[:id] || params[:parent_id] | |
21 | + links = page_trail(Article.find(id)) if id | |
22 | + links << { :name => cms_action(params[:action]), :url => params } if show_cms_action | |
23 | + end | |
24 | + links | |
25 | + end | |
26 | + | |
27 | + def trail(page, profile=nil, params={}) | |
28 | + links = page_trail(page, params) | |
29 | + if profile && !links.empty? && show_profile | |
30 | + [ {:name => profile.name, :url => profile.url} ] + links | |
31 | + else | |
32 | + links | |
33 | + end | |
34 | + end | |
35 | + | |
36 | + def content(args={}) | |
37 | + block = self | |
38 | + lambda do | |
39 | + trail = block.trail(@page, @profile, params) | |
40 | + if !trail.empty? | |
41 | + trail.map { |t| link_to(t[:name], t[:url], :class => 'item') }.join(content_tag('span', ' > ', :class => 'separator')) | |
42 | + else | |
43 | + '' | |
44 | + end | |
45 | + end | |
46 | + end | |
47 | + | |
48 | + def cacheable? | |
49 | + false | |
50 | + end | |
51 | + | |
52 | + protected | |
53 | + | |
54 | + CMS_ACTIONS = {:edit => _('Edit'), :upload_files => _('Upload Files'), :new => _('New')} | |
55 | + | |
56 | + def cms_action(action) | |
57 | + CMS_ACTIONS[action.to_sym] || action | |
58 | + end | |
59 | + | |
60 | +end | ... | ... |
plugins/breadcrumbs/test/functional/profile_design_controller_test.rb
... | ... | @@ -2,16 +2,15 @@ require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | |
3 | 3 | class ProfileDesignController |
4 | 4 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') |
5 | - def rescue_action(e) | |
6 | - raise e | |
7 | - end | |
5 | + def rescue_action(e) | |
6 | + raise e | |
7 | + end | |
8 | 8 | end |
9 | 9 | |
10 | 10 | class ProfileDesignControllerTest < ActionController::TestCase |
11 | 11 | |
12 | 12 | def setup |
13 | - Environment.delete_all | |
14 | - @environment = Environment.create(:name => 'testenv', :is_default => true) | |
13 | + @environment = Environment.default | |
15 | 14 | @environment.enabled_plugins = ['BreadcrumbsPlugin'] |
16 | 15 | @environment.save! |
17 | 16 | |
... | ... | @@ -19,7 +18,7 @@ class ProfileDesignControllerTest < ActionController::TestCase |
19 | 18 | @page = fast_create(Folder, :profile_id => @profile.id) |
20 | 19 | |
21 | 20 | box = Box.create!(:owner => @profile) |
22 | - @block = BreadcrumbsBlock.create!(:box => box) | |
21 | + @block = BreadcrumbsPlugin::ContentBreadcrumbsBlock.create!(:box => box) | |
23 | 22 | |
24 | 23 | user = create_user('testinguser') |
25 | 24 | @profile.add_admin(user.person) | ... | ... |
plugins/breadcrumbs/test/unit/breadcrumbs_block_test.rb
... | ... | @@ -1,75 +0,0 @@ |
1 | -require File.dirname(__FILE__) + '/../test_helper' | |
2 | - | |
3 | -class BreadcrumbsBlockTest < ActiveSupport::TestCase | |
4 | - | |
5 | - include NoosferoTestHelper | |
6 | - | |
7 | - def setup | |
8 | - @block = BreadcrumbsBlock.new | |
9 | - @profile = fast_create(Community) | |
10 | - @folder = fast_create(Folder, :profile_id => @profile.id) | |
11 | - @article = fast_create(Folder, :profile_id => @profile.id, :parent_id => @folder.id) | |
12 | - @params = {} | |
13 | - end | |
14 | - | |
15 | - attr_reader :params | |
16 | - | |
17 | - should 'has a description' do | |
18 | - assert_not_equal Block.description, BreadcrumbsBlock.description | |
19 | - end | |
20 | - | |
21 | - should 'has a help' do | |
22 | - assert @block.help | |
23 | - end | |
24 | - | |
25 | - should 'return path of links to reach a page' do | |
26 | - links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] | |
27 | - assert_equal links, @block.page_trail(@article) | |
28 | - end | |
29 | - | |
30 | - should 'return path of links when current page is at cms controller' do | |
31 | - params = {:controller => 'cms', :action => 'edit', :id => @article.id} | |
32 | - links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}, {:url=>{:controller=>"cms", :action=>"edit", :id=>@article.id}, :name=>"Edit"}] | |
33 | - assert_equal links, @block.page_trail(nil, params) | |
34 | - end | |
35 | - | |
36 | - should 'not return cms action link when show_cms_action is false' do | |
37 | - params = {:controller => 'cms', :action => 'edit', :id => @article.id} | |
38 | - links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] | |
39 | - @block.show_cms_action = false | |
40 | - assert_equal links, @block.page_trail(nil, params) | |
41 | - end | |
42 | - | |
43 | - should 'include profile link on path of links to reach a page' do | |
44 | - links = [{:name => @profile.name, :url => @profile.url}, {:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] | |
45 | - assert_equal links, @block.trail(@article, @profile) | |
46 | - end | |
47 | - | |
48 | - should 'not include profile link on path of links when show_profile is false' do | |
49 | - links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] | |
50 | - @block.show_profile = false | |
51 | - assert_equal links, @block.trail(@article, @profile) | |
52 | - end | |
53 | - | |
54 | - should 'not include profile link on path of links when trail is empty' do | |
55 | - assert_equal [], @block.trail(nil, @profile) | |
56 | - end | |
57 | - | |
58 | - should 'render trail if there is links to show' do | |
59 | - @page = @article | |
60 | - trail = instance_eval(&@block.content) | |
61 | - assert_match /#{@profile.name}/, trail | |
62 | - assert_match /#{@folder.name}/, trail | |
63 | - assert_match /#{@page.name}/, trail | |
64 | - end | |
65 | - | |
66 | - should 'render nothing if there is no links to show' do | |
67 | - @page = nil | |
68 | - assert_equal '', instance_eval(&@block.content) | |
69 | - end | |
70 | - | |
71 | - should 'not be cacheable' do | |
72 | - assert !@block.cacheable? | |
73 | - end | |
74 | - | |
75 | -end |
plugins/breadcrumbs/test/unit/breadcrumbs_plugin_test.rb
... | ... | @@ -13,9 +13,9 @@ class BreadcrumbsPluginTest < ActiveSupport::TestCase |
13 | 13 | should 'has a description' do |
14 | 14 | assert !BreadcrumbsPlugin.plugin_description.blank? |
15 | 15 | end |
16 | - | |
16 | + | |
17 | 17 | should 'add a block' do |
18 | - assert_equal [BreadcrumbsBlock], BreadcrumbsPlugin.extra_blocks.keys | |
18 | + assert_equal [BreadcrumbsPlugin::ContentBreadcrumbsBlock], BreadcrumbsPlugin.extra_blocks.keys | |
19 | 19 | end |
20 | 20 | |
21 | 21 | end | ... | ... |
plugins/breadcrumbs/test/unit/content_breadcrumbs_block_test.rb
0 → 100644
... | ... | @@ -0,0 +1,75 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class ContentBreadcrumbsBlockTest < ActiveSupport::TestCase | |
4 | + | |
5 | + include NoosferoTestHelper | |
6 | + | |
7 | + def setup | |
8 | + @block = BreadcrumbsPlugin::ContentBreadcrumbsBlock.new | |
9 | + @profile = fast_create(Community) | |
10 | + @folder = fast_create(Folder, :profile_id => @profile.id) | |
11 | + @article = fast_create(Folder, :profile_id => @profile.id, :parent_id => @folder.id) | |
12 | + @params = {} | |
13 | + end | |
14 | + | |
15 | + attr_reader :params | |
16 | + | |
17 | + should 'has a description' do | |
18 | + assert_not_equal Block.description, BreadcrumbsPlugin::ContentBreadcrumbsBlock.description | |
19 | + end | |
20 | + | |
21 | + should 'has a help' do | |
22 | + assert @block.help | |
23 | + end | |
24 | + | |
25 | + should 'return path of links to reach a page' do | |
26 | + links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] | |
27 | + assert_equal links, @block.page_trail(@article) | |
28 | + end | |
29 | + | |
30 | + should 'return path of links when current page is at cms controller' do | |
31 | + params = {:controller => 'cms', :action => 'edit', :id => @article.id} | |
32 | + links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}, {:url=>{:controller=>"cms", :action=>"edit", :id=>@article.id}, :name=>"Edit"}] | |
33 | + assert_equal links, @block.page_trail(nil, params) | |
34 | + end | |
35 | + | |
36 | + should 'not return cms action link when show_cms_action is false' do | |
37 | + params = {:controller => 'cms', :action => 'edit', :id => @article.id} | |
38 | + links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] | |
39 | + @block.show_cms_action = false | |
40 | + assert_equal links, @block.page_trail(nil, params) | |
41 | + end | |
42 | + | |
43 | + should 'include profile link on path of links to reach a page' do | |
44 | + links = [{:name => @profile.name, :url => @profile.url}, {:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] | |
45 | + assert_equal links, @block.trail(@article, @profile) | |
46 | + end | |
47 | + | |
48 | + should 'not include profile link on path of links when show_profile is false' do | |
49 | + links = [{:name => @folder.name, :url => @folder.url}, {:name => @article.name, :url => @article.url}] | |
50 | + @block.show_profile = false | |
51 | + assert_equal links, @block.trail(@article, @profile) | |
52 | + end | |
53 | + | |
54 | + should 'not include profile link on path of links when trail is empty' do | |
55 | + assert_equal [], @block.trail(nil, @profile) | |
56 | + end | |
57 | + | |
58 | + should 'render trail if there is links to show' do | |
59 | + @page = @article | |
60 | + trail = instance_eval(&@block.content) | |
61 | + assert_match /#{@profile.name}/, trail | |
62 | + assert_match /#{@folder.name}/, trail | |
63 | + assert_match /#{@page.name}/, trail | |
64 | + end | |
65 | + | |
66 | + should 'render nothing if there is no links to show' do | |
67 | + @page = nil | |
68 | + assert_equal '', instance_eval(&@block.content) | |
69 | + end | |
70 | + | |
71 | + should 'not be cacheable' do | |
72 | + assert !@block.cacheable? | |
73 | + end | |
74 | + | |
75 | +end | ... | ... |
plugins/breadcrumbs/views/box_organizer/_breadcrumbs_block.rhtml
plugins/breadcrumbs/views/box_organizer/breadcrumbs_plugin/_content_breadcrumbs_block.rhtml
0 → 100644
plugins/breadcrumbs/views/profile_design
plugins/breadcrumbs/views/profile_design/breadcrumbs_plugin
0 → 120000