OSDN Git Service

fx Manifest
[pettanr/pettanr.git] / lib / manifest / controller.rb
1
2 module Pettanr
3   module Manifest
4     class Controller
5       def self.set_default my_manifest
6         my_manifest.each {|item_name, controller_manifest|
7           controller_manifest|['model_name'] ||= item_name
8           controller_manifest|['actions'] ||= {}
9           controller_manifest|['actions'].each {|action_name, action_manifest|
10             action_manifest['options'] ||= {}
11             action_manifest['options'].each {option_name, option_manifest|
12               raise "undefined list_name for controllers > #{item_name} > actions > #{action_name} > options\n" unless option_manifest['list_name']
13             }
14           }
15         }
16       end
17       
18       class ActionList
19         attr :list
20         def initialize my_item_name, action_name, conf
21           # get home list_name
22           @my_item_name = conf['item_name'] if conf['item_name']
23           @action_name = action_name
24           @conf = conf
25         end
26         
27         def list params, operators
28           list_name = @controller_manifest.list_name action_name
29           @list = @manifest.list_managers[@my_item_name].open(list_name, params[:page], params[:page_size], operators)
30         end
31         
32         def ready params, operators
33           @items = @action.items 
34           
35         end
36         
37         def exec
38         end
39         
40         def render
41           format.html {
42             @filer = @action.filer
43             render :template => 'system/filer', :locals => {
44               :filer => @filer
45             }
46           }
47         end
48         
49         def cook params, operators
50           @action.ready params, operators
51           @action.exec
52           @action.render
53         end
54         
55       end
56       
57       class ActionShow
58         def initialize my_item_name, action_name, conf
59           @my_item_name = conf['item_name'] if conf['item_name']
60           @action_name = action_name
61           @conf = conf
62         end
63         
64         def ready
65           @item = Comic.show(params[:id], @operators)
66         end
67         
68         def exec
69         end
70         
71         def render
72           format.html {
73           }
74         end
75         
76       end
77       
78       class Recipe
79       end
80       
81       attr :controller_manifest, :item_name, :manifest, :controller_conf, 
82         :actions
83       @@types = {'list' => ActionList, 'show' => ActionShow}
84       def initialize controller_manifest
85         @controller_manifest = controller_manifest
86         @item_name = @controller_manifest.item_name
87         @manifest = @controller_manifest.manifest
88         @controller_conf = @controller_manifest.conf
89         @actions = {}
90         @my_item_name = @controller_conf['item_name'] || @item_name
91         @controller_manifest.actions.each {|action_name, conf|
92           type = conf['type']
93           @actions[action_name] = @@types[type].new @my_item_name, action_name, conf
94         }
95       end
96       
97       
98     end
99   end
100 end
101