Skip to content

Commit

Permalink
Fix returning path for ApplicationController. Add variables into i18n…
Browse files Browse the repository at this point in the history
… action names
  • Loading branch information
staszek committed Apr 4, 2010
1 parent d804936 commit 152fa26
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
10 changes: 4 additions & 6 deletions lib/easycrumbs/breadcrumb.rb
Expand Up @@ -65,23 +65,21 @@ def add_prefix(object_name, action, prefix, i18n)
else
prefix || [:new, :edit]
end
name = "#{action_name(action, i18n)} #{name}" if prefix.include?(action.to_sym)
name = action_name(action, i18n, name) if prefix.include?(action.to_sym)
end
name
end

# Return name of action.
def action_name(action, i18n)
i18n == true ? I18n.t("breadcrumbs.actions.#{action}") : action.titlecase
def action_name(action, i18n, name)
i18n == true ? I18n.t("breadcrumbs.actions.#{action}", :name => name) : "#{action.titlecase} #{name}"
end

# Set path using hash from ActionController::Routing::Routes.recognize_path
# Example looks like:
# {:country_id => "1", :movie_id => "1", :id => "1", :action => "show", :controller => "movies"}
def set_path(path, blank_links)
unless path.nil?
path.empty? ? "/" : ActionController::Routing::Routes.generate_extras(path).first
end
path.nil? || path.empty? ? "/" : ActionController::Routing::Routes.generate_extras(path).first
rescue ActionController::RoutingError => e
raise EasyCrumbs::NoPath.new(e.message) unless blank_links == true
nil
Expand Down
7 changes: 6 additions & 1 deletion test/test_easycrumbs.rb
Expand Up @@ -92,7 +92,8 @@ class TestEasycrumbs < Test::Unit::TestCase
end

should "return transalted action as a prefix" do
I18n.expects(:t).with("breadcrumbs.actions.edit").returns("Editzione")
name = "Leonardo Di Caprio"
I18n.expects(:t).with("breadcrumbs.actions.edit", {:name => name}).returns("Editzione #{name}")
assert_equal("Editzione Leonardo Di Caprio", Breadcrumb.new(@leo, :i18n => true, :action => "edit").name)
end
end
Expand All @@ -113,6 +114,10 @@ class TestEasycrumbs < Test::Unit::TestCase
should "return root path for empty path" do
assert_equal("/", Breadcrumb.new(@leo, :path => {}).path)
end

should "return root path for nil path" do
assert_equal("/", Breadcrumb.new(@leo).path)
end
end
end
end
Expand Down

0 comments on commit 152fa26

Please sign in to comment.