Skip to content

Instantly share code, notes, and snippets.

@mutewinter
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mutewinter/375697a9f78aa3b26fab to your computer and use it in GitHub Desktop.
Save mutewinter/375697a9f78aa3b26fab to your computer and use it in GitHub Desktop.
fnd's router
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()
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')
@toranb
Copy link

toranb commented Feb 7, 2015

Where does ITUNES_MODELS come from in that context?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment