Skip to content

Commit

Permalink
Fixes #28 via #29. Adds option for linking current breadcrumb to the …
Browse files Browse the repository at this point in the history
…request path
  • Loading branch information
WilHall committed Jul 10, 2016
1 parent a0a3f12 commit b1dd865
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 13 deletions.
12 changes: 9 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ source "http://rubygems.org"
# development dependencies will be added by default to the :development group.
gemspec

# jquery-rails is used by the dummy application
gem "jquery-rails"

# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.

# To use debugger
# gem 'debugger'

group :development do
# jquery-rails is used by the dummy application
gem "jquery-rails"
end

group :test do
gem 'test-unit', '~> 3.0' if RUBY_VERSION >= "2.2"
end
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Option | Description
:autoroot | Whether it should automatically link to the `:root` crumb if no parent is given. | True
:display_single_fragment | Whether it should display the breadcrumb if it includes only one link. | False
:link_current | Whether the current crumb should be linked to. | False
:link_current_to_request_path | Whether the current crumb should always link to the current request path. *Note:* This option will have no effect unless `:link_current` is set to `true`. | True
:semantic | Whether it should generate [semantic breadcrumbs](http://support.google.com/webmasters/bin/answer.py?hl=en&answer=185417). | False
:id | ID for the breadcrumbs container. | None
:class | CSS class for the breadcrumbs container. Can be set to `nil` for no class. | `"breadcrumbs"`
Expand Down
2 changes: 2 additions & 0 deletions gemfiles/Gemfile-rails.3.1.x
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ gem "jquery-rails"

# To use debugger
# gem 'debugger'

gem 'test-unit', '~> 3.0' if RUBY_VERSION >= "2.2"
2 changes: 2 additions & 0 deletions gemfiles/Gemfile-rails.4.0.x
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ gem "jquery-rails"

# To use debugger
# gem 'debugger'

gem 'test-unit', '~> 3.0' if RUBY_VERSION >= "2.2"
2 changes: 2 additions & 0 deletions gemfiles/Gemfile-rails.4.1.x
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ gem "jquery-rails"

# To use debugger
# gem 'debugger'

gem 'test-unit', '~> 3.0' if RUBY_VERSION >= "2.2"
9 changes: 5 additions & 4 deletions lib/gretel/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Renderer
autoroot: true,
display_single_fragment: false,
link_current: false,
link_current_to_request_path: true,
semantic: false,
class: "breadcrumbs",
current_class: "current",
Expand Down Expand Up @@ -84,7 +85,7 @@ def links_for_render(options = {})
end

# Set current link to actual path
if out.any? && request
if options[:link_current_to_request_path] && out.any? && request
out.last.url = request.fullpath
end

Expand All @@ -111,7 +112,7 @@ def links

# Links of first crumb
links = crumb.links.dup

# Get parent links
links.unshift *parent_links_for(crumb)

Expand All @@ -137,9 +138,9 @@ def method_missing(method, *args, &block)

class << self
include Resettable

# Registers a style for later use.
#
#
# Gretel::Renderer.register_style :ul, { container_tag: :ul, fragment_tag: :li }
def register_style(style_key, options)
styles[style_key] = options
Expand Down
19 changes: 13 additions & 6 deletions test/helper_methods_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ def itemscope_value
links[0].tap do |link|
assert link.title?
assert_equal "My Title", link.title

assert link.other?
assert_equal "Other Option", link.other

assert !link.nonexistent?
assert_nil link.nonexistent
end
Expand Down Expand Up @@ -263,15 +263,15 @@ def itemscope_value

test "with_breadcrumb" do
breadcrumb :basic

assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
breadcrumbs.to_s

with_breadcrumb(:with_parent_object, issues(:one)) do
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/projects/1">Test Project</a> &rsaquo; <span class="current">Test Issue</span></div>},
breadcrumbs.to_s
end
end

assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
breadcrumbs.to_s
end
Expand All @@ -298,6 +298,13 @@ def itemscope_value
assert_equal "/testpath?a=1&b=2", breadcrumbs.last.url
end

test "current link url is not set to fullpath using link_current_to_request_path=false" do
self.request = OpenStruct.new(fullpath: "/testpath?a=1&b=2")

breadcrumb :basic
assert_equal "/about", breadcrumbs(:link_current_to_request_path => false).last.url
end

test "calling the breadcrumb method with wrong arguments" do
assert_nothing_raised do
breadcrumb :basic, test: 1
Expand Down Expand Up @@ -378,7 +385,7 @@ def itemscope_value

test "register style" do
Gretel.register_style :test_style, { container_tag: :one, fragment_tag: :two }

breadcrumb :basic

assert_dom_equal %{<one class="breadcrumbs"><two><a href="/">Home</a></two><two class="current">About</two></one>},
Expand Down

0 comments on commit b1dd865

Please sign in to comment.