Skip to content

Commit

Permalink
Merge pull request #738 from ng/bootstrap3
Browse files Browse the repository at this point in the history
Add option to disable turbolinks on nav brand link
  • Loading branch information
seyhunak committed Jun 1, 2014
2 parents 0d430bc + 7aea1dd commit 1648a89
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions app/helpers/navbar_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module NavbarHelper
def nav_bar(options={}, &block)
nav_bar_nav(options) do
container_div(options[:brand], options[:brand_link], options[:responsive], options[:fluid]) do
container_div(options[:brand], options[:brand_link], options[:responsive], options[:fluid], options[:no_turbolink]) do
yield if block_given?
end
end
Expand Down Expand Up @@ -94,7 +94,7 @@ def uri_state(uri, options={})
:inactive
end
end
end
end

private

Expand All @@ -109,30 +109,32 @@ def nav_bar_nav(options, &block)
end
end

def container_div(brand, brand_link, responsive, fluid, &block)
def container_div(brand, brand_link, responsive, fluid, no_turbolink, &block)
div_container_class = fluid ? "container-fluid" : "container"
no_turbolink ||= false

content_tag :div, :class => div_container_class do
container_div_with_block(brand, brand_link, responsive, &block)
container_div_with_block(brand, brand_link, responsive, no_turbolink, &block)
end
end

def container_div_with_block(brand, brand_link, responsive, &block)
def container_div_with_block(brand, brand_link, responsive, no_turbolink, &block)
output = []
if responsive == true
output << responsive_nav_header(brand, brand_link)
output << responsive_nav_header(brand, brand_link, no_turbolink)
output << responsive_div { capture(&block) }
else
output << brand_link(brand, brand_link)
output << brand_link(brand, brand_link, no_turbolink)
output << capture(&block)
end
output.join("\n").html_safe
end

def responsive_nav_header(brand, brand_link)
def responsive_nav_header(brand, brand_link, no_turbolink)
content_tag(:div, :class => "navbar-header") do
output = []
output << responsive_button
output << brand_link(brand, brand_link)
output << brand_link(brand, brand_link, no_turbolink)
output.join("\n").html_safe
end
end
Expand All @@ -144,10 +146,15 @@ def nav_bar_css_class(position, inverse = false)
css_class.join(" ")
end

def brand_link(name, url)
def brand_link(name, url, no_turbolink)
return "" if name.blank?
url ||= root_url
link_to(name, url, :class => "navbar-brand")

if no_turbolink
link_to(name, url, :class => "navbar-brand", :data => { :no_turbolink => true})
else
link_to(name, url, :class => "navbar-brand")
end
end

def responsive_button
Expand Down

0 comments on commit 1648a89

Please sign in to comment.