OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / assets / javascripts / manifest / manifest.js.coffee
1 class Manifest\r
2   _module_names = null\r
3   \r
4   module_names: () ->\r
5     _module_names\r
6   \r
7   init: () ->\r
8     # managers can't initialize before load  application.rb\r
9     @inflectors = @global_json.inflectors\r
10     @item_names = {}\r
11     @table_names = {}\r
12     _.each @inflectors, (table_name, item_name) =>\r
13       @item_names[item_name] = table_name  # monkey copy\r
14       @table_names[table_name] = item_name\r
15     @items = ManifestBase.load_type_name_args(this, @global_json, 'items', Manifest.ItemFactory)\r
16     @controllers = Manifest.Controller.load(this, @global_json, 'controllers', Manifest.Controller)\r
17     @models = Manifest.Model.load(this, @global_json, 'models', Manifest.Model)\r
18     @replace_action_alias()\r
19     true\r
20   \r
21   replace_action_alias: () ->\r
22     replaces = {}\r
23     _.each @controllers, (controller_manifest, controller_name) ->\r
24       _.each controller_manifest.actions, (action_manifest, action_name) ->\r
25         return if not action_manifest.alias\r
26         alias_action = action_manifest.alias_action()\r
27         return if alias_action.type != action_manifest.type\r
28         args = {}\r
29         _.each action_manifest.a_arg_names(), (name) ->\r
30           args[name] = action_manifest[name] || alias_action[name]\r
31         _.each action_manifest.b_arg_names(), (name) ->\r
32           args[name] = alias_action[name] || action_manifest[name]\r
33         args.original = action_manifest\r
34         json = {type: alias_action.type, args: args}\r
35         new_action_manifest = Manifest.ControllerModule.ActionFactory.factory(\r
36           controller_manifest, action_manifest.name, json, \r
37           action_manifest.module_name, Manifest.ControllerModule.ActionFactory\r
38         )\r
39         replaces[controller_name] ||= {}\r
40         replaces[controller_name][action_name] = new_action_manifest\r
41     _.each replaces, (controller, controller_name) ->\r
42       _.each controller, (action_manifest, action_name) ->\r
43         Manifest.manifest().controllers[controller_name].actions[action_name] = action_manifest\r
44   \r
45   pluralize: (item_name) ->\r
46     @item_names[item_name]\r
47   \r
48   singularize: (table_name) ->\r
49     @table_names[table_name]\r
50   \r
51   @item_name_to_model: (item_name) ->\r
52     Pettanr[Pettanr.camelize(item_name)]\r
53   \r
54   @manifest: () ->\r
55     @mani\r
56   \r
57   @set_manifest: (manifest) ->\r
58     @mani = manifest\r
59   \r
60   constructor: (global_json) ->\r
61     _module_names = []\r
62     @global_json = global_json || {}\r
63     @system_resources = new Manifest.SystemResource(\r
64       this, Manifest.SystemResource.set_default(@global_json['system_resources'])\r
65     )\r
66     @magic_numbers = @global_json['magic_numbers']\r
67     @items = {}\r
68     @controllers = {}\r
69     @models = {}\r
70   \r
71 @Manifest = Manifest\r