From 51ab8e8517691934a260d579196a530962bcb5d9 Mon Sep 17 00:00:00 2001 From: Simon Menke Date: Thu, 29 Apr 2010 15:12:15 +0200 Subject: [PATCH] Better bread crumb --- app/helpers/application_helper.rb | 25 +++++++++++------------ app/views/shared/_breadcrumb.html.haml | 28 ++++++++++++++++++-------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 538605d..1a061c2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -137,7 +137,7 @@ def css_class(class_name='', value=nil, check=nil) end end end - + def abbreviation(value=nil) unless value.nil? abbreviation = value @@ -148,19 +148,18 @@ def abbreviation(value=nil) return abbreviation end end - + def breadcrumb_root - unless @breadcrumb_root - if @user or @users - @breadcrumb_root = { :text => 'Users', :link => admin_users_path } - elsif @project or @projects - @breadcrumb_root = { :text => 'Projects', :link => root_path } - elsif @user_session - @breadcrumb_root = { :text => 'Login', :link => new_user_session_path } - else - @breadcrumb_root = { :text => 'Home', :link => root_path } - end + return @breadcrumb_root if @breadcrumb_root + if @user or @users and request.path.starts_with?('/admin') + @breadcrumb_root = { :text => 'Users', :link => admin_users_path } + elsif @project or @projects + @breadcrumb_root = { :text => 'Projects', :link => root_path } + elsif @user_session + @breadcrumb_root = { :text => 'Login', :link => new_user_session_path } + else + @breadcrumb_root = { :text => 'Home', :link => root_path } end end - + end diff --git a/app/views/shared/_breadcrumb.html.haml b/app/views/shared/_breadcrumb.html.haml index d68bc06..ea5041a 100644 --- a/app/views/shared/_breadcrumb.html.haml +++ b/app/views/shared/_breadcrumb.html.haml @@ -1,11 +1,23 @@ - breadcrumb_root - menu_block do |link| - - link.to(@breadcrumb_root[:text], @breadcrumb_root[:link]) - - @error = @occurence.error if @occurence and !@error - - @project = @error.project if @error and !@project - - link.to(@project.name, @project,:class => "action2") { true } if @project and !@project.new_record? - - link.to(@error.id, @error,:class => "open") {true} if @error - - link.to(@occurence.id, @occurence,:class => "action2") {true} if @occurence - - - link.to("edit my account",{:action => "edit"},:class => "action2") {true} if params[:action]=="edit" and !@error and !@project \ No newline at end of file + - if @breadcrumb_root + - link.to(@breadcrumb_root[:text], @breadcrumb_root[:link]) + + - @error ||= (@occurence.error if @occurence) + - @project ||= (@error.project if @error) + + - if @project and !@project.new_record? + - link.to(@project.name, @project,:class => "action2") { true } + + - if @error + - link.to(@error.id, @error,:class => "open") {true} + + - if @occurence + - link.to(@occurence.id, @occurence,:class => "action2") {true} + + - if @user and request.path.starts_with?('/admin') + - link.to(@user.name, admin_user_path(@user), :class => "action2") + + - elsif @user + - link.to("edit my account",{:action => "edit"}, :class => "action2") {true} \ No newline at end of file