Skip to content

Instantly share code, notes, and snippets.

@bobthecow bobthecow/gist:4774286 forked from smkelly/gist:4774258
Last active Dec 12, 2015

Embed
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}"
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
You can’t perform that action at this time.