batman.js

The Batman routing DSL is similar to Rails 3's routing DSL. It is oriented around the notion of a resource:

  • @route

    @route defines a custom route and can be pointed to a controller action directly. For example:

    class window.Example extends Batman.App
      @route 'comments', 'pages#comments'
    
    class Example.PagesController extends Batman.Controller
      comments: ->

    Would result in /comments being added to the routing map, pointed to PagesController#comments.

  • @resources(resourceName : String[, otherResourceNames... : String][, options : Object][, scopedCallback : Function])

  • @member

    @member defines a routable action you can call on a specific instance of a member of a collection resource. For example, if you have a collection of Page resources, and a user can post a comment on a specific page:

    class window.Example extends Batman.App
      @resources 'pages', ->
        @member 'comment'
    
    class Example.PagesController extends Batman.Controller
      comment: (params) ->

    Would result in /pages/:id/comment being added to the routing map, pointed to PagesController#comment.

  • @collection

    @collection is similar to @member in that it adds routable actions to a @resources set of routes. In this case the action would apply to the entire collection. For example, if you have a list of spam comments made across all your Page resources:

    class window.Example extends Batman.App
      @resources 'pages', ->
        @collection 'spam_comments'
    
    class Example.PagesController extends Batman.Controller
      comments: ->

    Would result in /pages/spam_comments being added to the routing map, pointed to PagesController#spam_comments.

  • @root

    @root defines the root controller and action to be used when visiting the base application URL. For example:

    class window.Example extends Batman.App
      @root 'pages#index'
    
    class Example.PagesController extends Batman.Controller
      index: ->

    Would result in / being pointed to PagesController#index.