Skip to content

Instantly share code, notes, and snippets.

@sshirokov
Created September 5, 2012 21:11
Show Gist options
  • Select an option

  • Save sshirokov/3644829 to your computer and use it in GitHub Desktop.

Select an option

Save sshirokov/3644829 to your computer and use it in GitHub Desktop.
angular.module('gitstats').controller "NavCtrl", ['$scope', '$route',
class NavCtrl
constructor: (@scope, @route) ->
route_to_nav = (path, route) =>
return if route.redirectTo?
return unless route.name?
current_route_name = () => @route.current?.$route?.name
path: path
name: route.name
classes: ->
"active" if @name == current_route_name()
# The navs are built out of the routing table
# with any redirecting routes or routes without
# names omitted.
@scope.navs = (route_to_nav(path, route) for own path, route of @route.routes).filter (r) => r
]
<ul class="nav" ng-controller="NavCtrl">
<li ng-repeat="nav in navs" ng-class="nav.classes()">
<a ng-href="#{{ nav.path }}" >{{ nav.name }}</a>
</li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment