Skip to content

Instantly share code, notes, and snippets.

@manufaktor
Created November 2, 2011 20:00
Show Gist options
  • Save manufaktor/1334717 to your computer and use it in GitHub Desktop.
Save manufaktor/1334717 to your computer and use it in GitHub Desktop.
Middleman navigation helper
module Middleman::Features::Navigation
class << self
def registered(app)
app.helpers NavigationHelpers
end
alias :included :registered
end
module NavigationHelpers
def link_to(label, url)
current = false
if url == '/'
current = url == '/' && request.path == 'index.html'
else
current = "/#{request.path}".include?(url)
end
"<a href='#{url}' #{'class="current"' if current}>#{label}</a>"
end
end
end
activate :navigation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment