Created
April 17, 2014 04:09
-
-
Save evanrs/10952243 to your computer and use it in GitHub Desktop.
Angular Route Factory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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