-
Notifications
You must be signed in to change notification settings - Fork 254
/
Copy pathrouter.coffee
31 lines (24 loc) · 1.11 KB
/
router.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class <%= router_namespace %>Router extends Backbone.Router
initialize: (options) ->
@<%= plural_model_name %> = new <%= collection_namespace %>Collection()
@<%= plural_model_name %>.reset options.<%= plural_model_name %>
routes:
"/new" : "new<%= class_name %>"
"/index" : "index"
"/:id/edit" : "edit"
"/:id" : "show"
".*" : "index"
new<%= class_name %>: ->
@view = new <%= "#{view_namespace}.NewView(collection: @#{plural_model_name})" %>
$("#<%= plural_name %>").html(@view.render().el)
index: ->
@view = new <%= "#{view_namespace}.IndexView(#{plural_model_name}: @#{plural_model_name})" %>
$("#<%= plural_name %>").html(@view.render().el)
show: (id) ->
<%= singular_name %> = @<%= plural_model_name %>.get(id)
@view = new <%= "#{view_namespace}.ShowView(model: #{singular_name})" %>
$("#<%= plural_name %>").html(@view.render().el)
edit: (id) ->
<%= singular_name %> = @<%= plural_model_name %>.get(id)
@view = new <%= "#{view_namespace}.EditView(model: #{singular_name})" %>
$("#<%= plural_name %>").html(@view.render().el)