Skip to content

Instantly share code, notes, and snippets.

@evanrs
Created April 17, 2014 04:09
Show Gist options
  • Save evanrs/10952243 to your computer and use it in GitHub Desktop.
Save evanrs/10952243 to your computer and use it in GitHub Desktop.
Angular Route Factory
var routeFactory = {
build: function(components, routes){
components = _.reduce(components, function (accumulator, component, index) {
if(_.isEmpty(accumulator)) return component
if(_.isString(accumulator)) accumulator = [accumulator]
var transform = accumulator.slice(0)
_.map(accumulator, function(route){
var slug = component
if(slug[0] === '/') slug = slug.slice(1)
else if(slug[0] === ':'){}
else if(slug.split('/').length < 2)
slug = [slug, ':'+slug].join('/')
transform.push([route,slug].join('/'))
return route
})
return transform
}, (_.isArray(routes)? routes: null) )
return routes? components.slice(routes.length) : components
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment