Skip to content

Instantly share code, notes, and snippets.



Forked from smkelly/gist:4774258
Last active Dec 12, 2015
What would you like to do?
# 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}"
# 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>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment