Commit 582c3cb32ab6f1a5cf41397ed5071b9c644e46ff
Exists in
master
and in
29 other branches
Merge remote branch 'participa/AI2872-breadcrumbs_block' into breadscrumb-block
Showing
9 changed files
with
241 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,19 @@ |
1 | +class BreadcrumbsPlugin < Noosfero::Plugin | |
2 | + | |
3 | + def self.plugin_name | |
4 | + "BreadcrumbsPlugin" | |
5 | + end | |
6 | + | |
7 | + def self.plugin_description | |
8 | + _("A plugin that add a block to display breadcrumbs.") | |
9 | + end | |
10 | + | |
11 | + def self.extra_blocks | |
12 | + { BreadcrumbsPlugin::ContentBreadcrumbsBlock => {:type => [Community, Person, Enterprise] } } | |
13 | + end | |
14 | + | |
15 | + def stylesheet? | |
16 | + true | |
17 | + end | |
18 | + | |
19 | +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 | ... | ... |
... | ... | @@ -0,0 +1,12 @@ |
1 | +#content .breadcrumbs-plugin_content-breadcrumbs-block a, | |
2 | +#content .breadcrumbs-plugin_content-breadcrumbs-block a:visited { | |
3 | + color: #2c67cd; | |
4 | + text-decoration: none; | |
5 | +} | |
6 | +#content .breadcrumbs-plugin_content-breadcrumbs-block a:hover { | |
7 | + color: black; | |
8 | +} | |
9 | + | |
10 | +#content .breadcrumbs-plugin_content-breadcrumbs-block .separator { | |
11 | + font-size: 11px; | |
12 | +} | ... | ... |
plugins/breadcrumbs/test/functional/profile_design_controller_test.rb
0 → 100644
... | ... | @@ -0,0 +1,44 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class ProfileDesignController | |
4 | + append_view_path File.join(File.dirname(__FILE__) + '/../../views') | |
5 | + def rescue_action(e) | |
6 | + raise e | |
7 | + end | |
8 | +end | |
9 | + | |
10 | +class ProfileDesignControllerTest < ActionController::TestCase | |
11 | + | |
12 | + def setup | |
13 | + @environment = Environment.default | |
14 | + @environment.enabled_plugins = ['BreadcrumbsPlugin'] | |
15 | + @environment.save! | |
16 | + | |
17 | + @profile = fast_create(Community, :environment_id => @environment.id) | |
18 | + @page = fast_create(Folder, :profile_id => @profile.id) | |
19 | + | |
20 | + box = Box.create!(:owner => @profile) | |
21 | + @block = BreadcrumbsPlugin::ContentBreadcrumbsBlock.create!(:box => box) | |
22 | + | |
23 | + user = create_user('testinguser') | |
24 | + @profile.add_admin(user.person) | |
25 | + login_as(user.login) | |
26 | + end | |
27 | + | |
28 | + should 'be able to edit breadcrumbs block' do | |
29 | + get :edit, :id => @block.id, :profile => @profile.identifier | |
30 | + assert_tag :tag => 'input', :attributes => { :id => 'block_title' } | |
31 | + assert_tag :tag => 'input', :attributes => { :id => 'block_show_cms_action' } | |
32 | + assert_tag :tag => 'input', :attributes => { :id => 'block_show_profile' } | |
33 | + end | |
34 | + | |
35 | + should 'be able to save breadcrumbs block' do | |
36 | + get :edit, :id => @block.id, :profile => @profile.identifier | |
37 | + post :save, :id => @block.id, :profile => @profile.identifier, :block => {:title => 'breadcrumbs', :show_cms_action => false, :show_profile => false} | |
38 | + @block.reload | |
39 | + assert_equal 'breadcrumbs', @block.title | |
40 | + assert !@block.show_profile | |
41 | + assert !@block.show_cms_action | |
42 | + end | |
43 | + | |
44 | +end | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +require File.dirname(__FILE__) + '/../../../test/test_helper' | ... | ... |
plugins/breadcrumbs/test/unit/breadcrumbs_plugin_test.rb
0 → 100644
... | ... | @@ -0,0 +1,25 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class BreadcrumbsPluginTest < ActiveSupport::TestCase | |
4 | + | |
5 | + def setup | |
6 | + @plugin = BreadcrumbsPlugin.new | |
7 | + end | |
8 | + | |
9 | + should 'has a name' do | |
10 | + assert !BreadcrumbsPlugin.plugin_name.blank? | |
11 | + end | |
12 | + | |
13 | + should 'has a description' do | |
14 | + assert !BreadcrumbsPlugin.plugin_description.blank? | |
15 | + end | |
16 | + | |
17 | + should 'add a block' do | |
18 | + assert_equal [BreadcrumbsPlugin::ContentBreadcrumbsBlock], BreadcrumbsPlugin.extra_blocks.keys | |
19 | + end | |
20 | + | |
21 | + should 'has stylesheet' do | |
22 | + assert @plugin.stylesheet? | |
23 | + end | |
24 | + | |
25 | +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_plugin/_content_breadcrumbs_block.rhtml
0 → 100644
plugins/breadcrumbs/views/profile_design/breadcrumbs_plugin
0 → 120000