Created
November 5, 2012 03:07
-
-
Save zhangyuan/4015104 to your computer and use it in GitHub Desktop.
bootstrap nav_list rendering helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationHelper | |
# render nav list for twitter bootstrap. | |
# define the nav list items. | |
def nav_list | |
[ | |
[:a, 'A', 'http://example.com/a'], | |
[:b, 'B', 'http://example.com/b'], | |
[:c, 'C', 'http://example.com/c'], | |
[:d, 'D', 'http://example.com/d'], | |
] | |
end | |
# call render_nav_tabs to render current nav with active item | |
# e.g. render_nav_tabs(:a, nav_list) | |
def render_nav_tabs(name, nav_list, options = {}) | |
nav_class = options[:nav_class] || 'nav nav-tabs' | |
content_tag(:ul, class: nav_class) do | |
text = nav_list.map do |entry| | |
if entry[0] == name | |
content_tag(:li, class: 'active') do | |
link_to entry[1], '#' | |
end | |
else | |
content_tag(:li) do | |
link_to entry[1], entry.last | |
end | |
end.html_safe | |
end.join.html_safe | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment