class Pettanr.Router extends Backbone.Router parse_query_string: (query_string) -> params = {} if query_string ary = _.map decodeURI(query_string).split(/&/g), (el, i) -> aux = el.split('=') o = {} if aux.length >= 1 val = undefined if aux.length == 2 val = aux[1] o[aux[0]] = val o _.each ary, (o) -> _.extend(params, o) params fire: (params) -> c = Pettanr[Pettanr.camelize(params['controller']) + 'Controller'] controller = new c controller.params = params controller[params['action']]() initialize: () -> this['c_i_a'] = (controller, id, action, query_string) -> params = this.parse_query_string(query_string) params['controller'] = controller params['format'] = 'html' t = id.split('.') if t.length > 1 params['format'] = t[1] id = t[0] t = action.split('.') if t.length > 1 params['format'] = t[1] action = t[0] if Pettanr.is_number(action) params['action'] = id params['id'] = action else params['action'] = action params['id'] = id this.fire(params) this['c_i'] = (controller, id, query_string) -> params = this.parse_query_string(query_string) params['controller'] = controller params['format'] = 'html' t = id.split('.') if t.length > 1 params['format'] = t[1] id = t[0] if Pettanr.is_number(id) params['action'] = 'show' params['id'] = id else if id params['action'] = id else params['action'] = 'index' this.fire(params) this['c'] = (controller, query_string) -> params = this.parse_query_string(query_string) params['controller'] = controller params['format'] = 'html' params['action'] = 'index' this.fire(params) this.route('', 'home') this.route(':controller/:id/:action?*query_string', 'c_i_a') this.route(':controller/:id/:action', 'c_i_a') this.route(':controller/:id?*query_string', 'c_i') this.route(':controller/:id', 'c_i') this.route(':controller?*query_string', 'c') this.route(':controller', 'c') home: () -> params = {} params['controller'] = 'folders' params['action'] = 'root' @fire(params) hoge: () -> names = _.map Manifest.manifest().controllers, (controller_manifest, controller_name) -> c = Pettanr[Pettanr.camelize(controller_name) + 'Controller'] controller = new c _.map controller_manifest.actions, (action_manifest, action_name) -> { event_name: controller_name + '_' + action_name, controller: controller, controller_name: controller_name, action_manifest: action_manifest, action_name: action_name } _this = this _.each _.flatten(names), (status) -> _status = status switch status.action_manifest.type when 'list' e = status.event_name e_f = e + '_format' _this[e] = (queryString) -> params = _this.parse_query_string(query_string) console.log(params) _status.controller[_status.action_name](params) c = _status.controller_name a = _status.action_name c_a_url = c + '/' + a _this.route(c_a_url, e) r = r + '?*queryString' _this.route(r, _status.event_name) if _status.action_name == 'index' r = _status.controller_name + '/' _this.route(r, _status.event_name) when 'show' e = status.event_name e_f = e + '_format' _this[e] = (id, query_string) -> params = _this.parse_query_string(query_string) t = id.split('.') if t.length > 1 params['format'] = t[1] id = t[0] console.log(id) console.log(params) _status.controller[_status.action_name](id, params) _this[e_f] = (id, format, query_string) -> params = _this.parse_query_string(query_string) params['format'] = format console.log(id) console.log(params) _status.controller[_status.action_name](id, params) c = _status.controller_name a = _status.action_name q = '?*query_string' i = '\/([0-9]+)' c_id_a_url = c + '/:id/' + a c_id_a_f_url = c + '/:id/' + a + '.:format' c_id_a_q_url = c_id_a_url + q c_id_a_q_url = c_id_a_url + '.:format' + q _this.route(c_id_a_q_url, e_f) _this.route(c_id_a_q_url, e) _this.route(c_id_a_f_url, e_f) _this.route(c_id_a_url, e) if a == 'show' c_id_url = c + '/:id' c_id_q_url = c_id_url + q _this.route(c_id_q_url, e) _this.route(c_id_url, e)