joosy/joosy — pull request #69 by teodor-pripoae (2013-01-20 19:54:41+00:00)
Title: Add reverse url support to Joosy.Router

Hi,

I've added reverse url support to Joosy.Router. For this, I created a new method named draw, which works similar to one in Ruby on Rails, with a nice DSL. Example code:

```coffeescript
Joosy.Router.draw ->
@root to: Dashboard.IndexPage
@not_found to: -> alert("Not found")

@match '/activities', to: Activities.IndexPage, as: "activities"
@match '/feed', to: Feed.FeedPage

@namespace '/projects', as: "projects", ->
@match "/", to: Projects.IndexPage, as: "index"
@namespace "/:id", ->
@match "/", to: Projects.ShowPage, as: "show"
@match "/edit", to: Projects.EditPage, as: "edit"
@match "/delete", to: Projects.DeletePage, as: "delete"

@namespace '/tickets', ->
@match "/", to: Tickets.IndexPage, as: "tickets_index"
```

Now it's easy to get reverse url for this:

```coffeescript
root_path() # #!/
activities_path # #!/activities
projects_index_path # #!/projects/
projects_edit_path # #!/projects/:id/edit

root_url() # http://example.com/current/path/#!/
activities_url() # http://example.com/current/path/#!/activities
```