Permalink
Browse files

Added support for fetch url parameters through a hierarchy like so: :…

…user => {:comment => :title}
  • Loading branch information...
1 parent fd6f4d8 commit 4182ce0d48930624010f9c59c75632f13bfdd1f2 @roidrage roidrage committed Jun 10, 2009
Showing with 37 additions and 0 deletions.
  1. +15 −0 app/helpers/breadcrumbs_helper.rb
  2. +22 −0 spec/breadcrumbs_helper_spec.rb
@@ -24,6 +24,9 @@ def fetch_parameterized_crumb_url(crumb)
when Hash
if crumb.params[:params]
send(crumb.url, fetch_parameters_recursive(crumb.params[:params]))
+ else
+ result = instance_eval("@#{assemble_crumb_url_parameter(crumb.params).join(".")}")
+ send(crumb.url, result)
end
else
if crumb.url == :current
@@ -67,4 +70,16 @@ def fetch_parameters_recursive(params_hash, parent = nil)
end
parameters
end
+
+ def assemble_crumb_url_parameter(params)
+ result = []
+ params.to_a.flatten.collect do |step|
+ result << if step.is_a?(Hash)
+ assemble_crumb_url_parameter(step)
+ else
+ step
+ end
+ end
+ result
+ end
end
@@ -230,6 +230,28 @@ def its_true!
params[:action] = 'new'
crumbs.should == %Q{<a href="http://test.host/search/jonathan">Search Results</a>}
end
+
+ it "should support resolving parameters for url methods derived from a hash pointing to an object hierarchy" do
+ Breadcrumb.configure do
+ crumb :search_results, 'Search Results', :search_url, :user => :login
+ trail :search, [:create, :new], [:search_results]
+ end
+
+ params[:controller] = 'search'
+ params[:action] = 'new'
+ crumbs.should == %Q{<a href="http://test.host/search/jonathan">Search Results</a>}
+ end
+
+ it "should support resolving parameters for url methods derived from a hash pointing to a nested object hierarchy" do
+ Breadcrumb.configure do
+ crumb :search_results, 'Search Results', :search_url, :user => {:login => :to_s}
+ trail :search, [:create, :new], [:search_results]
+ end
+
+ params[:controller] = 'search'
+ params[:action] = 'new'
+ crumbs.should == %Q{<a href="http://test.host/search/jonathan">Search Results</a>}
+ end
describe "when fetching parameters" do
it "should support nested parameter attributes" do

0 comments on commit 4182ce0

Please sign in to comment.