Skip to content

Instantly share code, notes, and snippets.

@bobthecow
Forked from smkelly/gist:4774258
Last active December 12, 2015 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobthecow/4774286 to your computer and use it in GitHub Desktop.
Save bobthecow/4774286 to your computer and use it in GitHub Desktop.
# 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