Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added no_container option to link_to helper #114

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/bh/helpers/link_to_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ module Helpers
# end
# end
def link_to(*args, &block)
options = args.extract_options!.dup
no_container = options.delete(:no_container)
args << options unless options.empty?

link_to = Bh::LinkTo.new self, *args, &block

link_to.append_class! :'alert-link' if Bh::Stack.find(Bh::AlertBox)
Expand All @@ -43,7 +47,9 @@ def link_to(*args, &block)
link_to.merge! tabindex: -1 if Bh::Stack.find(Bh::Dropdown)
html = super link_to.content, link_to.url, link_to.attributes, &nil

if Bh::Stack.find(Bh::Dropdown)
if no_container
html
elsif Bh::Stack.find(Bh::Dropdown)
container = Bh::Base.new(self) { html }
container.merge! role: :presentation
container.render_tag :li
Expand All @@ -56,4 +62,4 @@ def link_to(*args, &block)
end
end
end
end
end
8 changes: 7 additions & 1 deletion spec/shared/link_to_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,17 @@
bh.nav { expect(:link_to).to generate html }
end
end

specify 'does not surround the link in <li> if no_container: true given' do
options = { no_container: true }
html = '<a href="/">content</a>'
bh.nav { expect(link_to: options).to generate html }
end
end

shared_examples_for 'the link wrapped in vertical' do
specify 'surrounds the link in a <li> item' do
html = '<li><a href="/">content</a></li>'
bh.vertical { expect(:link_to).to generate html }
end
end
end