-
-
Save bobthecow/4774286 to your computer and use it in GitHub Desktop.
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
# if you want an icon, add it to your attributes: | |
# menu_link('Foo', '/foo/', icon: 'bar') | |
def menu_link(text, target, attributes={}) | |
# Prepend the icon, if supplied | |
if icon = attributes.delete(:icon) | |
text = "<i class='#{icon}'></i>#{text}" | |
end | |
# Build a link | |
link = link_to(text, target, attributes) | |
# Check for current page | |
path = target.is_a?(String) ? target : target.path | |
active = @item_rep && @item_rep.path == path | |
# And return a list item | |
"<li#{active ? ' class=\'active\'' : ''}>#{link}</li>" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment