Last active
August 29, 2015 14:14
-
-
Save mutewinter/375697a9f78aa3b26fab to your computer and use it in GitHub Desktop.
fnd's router
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
module.exports = App.FndModel = DS.Model.extend | |
typeKey: (-> | |
@constructor.typeKey | |
).property() | |
routeName: (-> | |
@constructor.routeName() | |
).property() | |
routePath: (-> | |
@constructor.routePath() | |
).property() | |
templateName: (-> | |
@constructor.templateName() | |
).property() | |
dynamicSegmentName: (-> | |
@constructor.dynamicSegmentName() | |
).property() | |
cssClass: (-> | |
@constructor.cssClass() | |
).property() | |
App.FndModel.reopenClass | |
typeKeyFromToString: -> | |
@_typeKeyFromToString or= @toString().split('.')[1].camelize() | |
routeName: -> @typeKeyFromToString().camelize() | |
routePath: -> @typeKeyFromToString().dasherize() | |
templateName: -> @typeKeyFromToString().underscore() | |
cssClass: -> @typeKeyFromToString().dasherize() | |
dynamicSegmentName: -> "#{@typeKeyFromToString().underscore()}_id" | |
loadAll: (store) -> | |
store.pushMany @typeKeyFromToString(), @all() |
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
module.exports = App.Router.map -> | |
@route('missing', path: '*missing') | |
@resource('home', path: '/') | |
@route('about') | |
@resource 'country', path: '/:country_id', -> | |
@resource 'search', path: '/search' | |
@resource 'charts', path: '/charts' | |
@resource 'chart', path: '/charts/:media_type_id/:chart_type_id/:genre_slug' | |
@resource('integrations', path: '/integrations') | |
@resource('integration', path: '/integrations/:integration_id') | |
@resource('bookmarklet', path: '/bookmarklets/:bookmarklet_id') | |
# Will redirect to canonical fnd url from an iTunes ID | |
@resource('any', path: '/any/:id') | |
ITUNES_MODELS.forEach (typeClassName) => | |
type = App[typeClassName] | |
routeName = type.routeName() | |
routePath = type.routePath() | |
dynamicSegment = type.dynamicSegmentName() | |
@resource routeName, path: "/#{routePath}/:#{dynamicSegment}", -> | |
@route('association', path: '/:media_type_id') | |
@route('notAvailableIn', path: '/not-available-in/:desired_country_id') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where does ITUNES_MODELS come from in that context?