Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Don't make links if path = nil #32

Merged
merged 2 commits into from

4 participants

@mpartel

Skips the <a> around an element if the element's path is nil. The second commit makes the second parameter of add_breadcrumb optional.

@mpartel

Would handle issue #6.

@lacco

+1 , works great!

@revans

This has been merged into a forked repo here: https://github.com/revans/breadcrumbs_on_rails/pull/1

@weppos weppos was assigned
@weppos weppos merged commit d8eb950 into weppos:master
@weppos
Owner

Great patch, merged!

@weppos weppos referenced this pull request from a commit
@weppos Update CHANGELOG per GH-32, GH-6 f9d8ff0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
4 lib/breadcrumbs_on_rails/action_controller.rb
@@ -19,7 +19,7 @@ module ActionController
protected
- def add_breadcrumb(name, path, options = {})
+ def add_breadcrumb(name, path = nil, options = {})
self.breadcrumbs << Breadcrumbs::Element.new(name, path, options)
end
@@ -60,7 +60,7 @@ def self.convert_to_set_of_strings(value, keys)
module ClassMethods
- def add_breadcrumb(name, path, filter_options = {})
+ def add_breadcrumb(name, path = nil, filter_options = {})
# This isn't really nice here
if eval = Utils.convert_to_set_of_strings(filter_options.delete(:eval), %w(name path))
name = Utils.instance_proc(name) if eval.include?("name")
View
8 lib/breadcrumbs_on_rails/breadcrumbs.rb
@@ -87,7 +87,11 @@ def render
end
def render_element(element)
- content = @context.link_to_unless_current(compute_name(element), compute_path(element), element.options)
+ if element.path == nil
+ content = compute_name(element)
+ else
+ content = @context.link_to_unless_current(compute_name(element), compute_path(element), element.options)
+ end
if @options[:tag]
@context.content_tag(@options[:tag], content)
else
@@ -116,7 +120,7 @@ class Element
# @param [Hash] options The element/link URL.
# @return [Element]
#
- def initialize(name, path, options = {})
+ def initialize(name, path = nil, options = {})
self.name = name
self.path = path
self.options = options
View
10 test/unit/element_test.rb
@@ -2,10 +2,9 @@
class ElementTest < ActiveSupport::TestCase
- def test_initialize_should_require_name_and_path
+ def test_initialize_should_require_name
assert_raise(ArgumentError) { BreadcrumbsOnRails::Breadcrumbs::Element.new }
- assert_raise(ArgumentError) { BreadcrumbsOnRails::Breadcrumbs::Element.new(nil) }
- assert_nothing_raised { BreadcrumbsOnRails::Breadcrumbs::Element.new(nil, nil) }
+ assert_nothing_raised { BreadcrumbsOnRails::Breadcrumbs::Element.new(nil) }
end
def test_initialize_should_set_name
@@ -41,5 +40,10 @@ def test_options
element.options = { :title => "Go to the Homepage" }
assert_equal({ :title => "Go to the Homepage" }, element.options)
end
+
+ def test_path_is_optional
+ element = BreadcrumbsOnRails::Breadcrumbs::Element.new(:homepage)
+ assert_nil element.path
+ end
end
View
8 test/unit/simple_builder_test.rb
@@ -52,6 +52,14 @@ def test_render_with_current_page
simplebuilder(@template, generate_elements(2)).render)
end
+ def test_render_with_no_links
+ elements = (1..2).collect do |index|
+ BreadcrumbsOnRails::Breadcrumbs::Element.new("Element #{index}", nil)
+ end
+ assert_dom_equal("Element 1 &raquo; Element 2",
+ simplebuilder(@template, elements).render)
+ end
+
protected
Something went wrong with that request. Please try again.