Commit 5ee350532b800644216089c83815dc14f7738a2b
1 parent
ce0d03ab
Exists in
staging
and in
42 other branches
Added a block to display breadcrumbs
Showing
2 changed files
with
55 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,40 @@ |
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 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 = trail(Article.find(id)) if id | |
22 | + links << { :name => params[:action], :url => params } if show_cms_action | |
23 | + end | |
24 | + links | |
25 | + end | |
26 | + | |
27 | + def content(args={}) | |
28 | + block = self | |
29 | + lambda do | |
30 | + trail = block.trail(@page, params) | |
31 | + if !trail.empty? | |
32 | + trail = [ {:name => @profile.name, :url => @profile.url} ] + trail if block.show_profile | |
33 | + trail.map { |t| link_to(t[:name], t[:url], :class => 'item') }.join(content_tag('span', ' > ', :class => 'separator')) | |
34 | + else | |
35 | + '' | |
36 | + end | |
37 | + end | |
38 | + end | |
39 | + | |
40 | +end | ... | ... |
... | ... | @@ -0,0 +1,15 @@ |
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 | + { BreadcrumbsBlock => {} } | |
13 | + end | |
14 | + | |
15 | +end | ... | ... |