-
-module Pettanr
- module Manifest
- class Controller
- def self.set_default my_manifest
- my_manifest.each {|item_name, controller_manifest|
- controller_manifest|['model_name'] ||= item_name
- controller_manifest|['actions'] ||= {}
- controller_manifest|['actions'].each {|action_name, action_manifest|
- action_manifest['options'] ||= {}
- action_manifest['options'].each {option_name, option_manifest|
- raise "undefined list_name for controllers > #{item_name} > actions > #{action_name} > options\n" unless option_manifest['list_name']
- }
- }
- }
- end
-
- class ActionList
- attr :list
- def initialize my_item_name, action_name, conf
- # get home list_name
- @my_item_name = conf['item_name'] if conf['item_name']
- @action_name = action_name
- @conf = conf
- end
-
- def list params, operators
- list_name = @controller_manifest.list_name action_name
- @list = @manifest.list_managers[@my_item_name].open(list_name, params[:page], params[:page_size], operators)
- end
-
- def ready params, operators
- @items = @action.items
-
- end
-
- def exec
- end
-
- def render
- format.html {
- @filer = @action.filer
- render :template => 'system/filer', :locals => {
- :filer => @filer
- }
- }
- end
-
- def cook params, operators
- @action.ready params, operators
- @action.exec
- @action.render
- end
-
- end
-
- class ActionShow
- def initialize my_item_name, action_name, conf
- @my_item_name = conf['item_name'] if conf['item_name']
- @action_name = action_name
- @conf = conf
- end
-
- def ready
- @item = Comic.show(params[:id], @operators)
- end
-
- def exec
- end
-
- def render
- format.html {
- }
- end
-
- end
-
- class Recipe
- end
-
- attr :controller_manifest, :item_name, :manifest, :controller_conf,
- :actions
- @@types = {'list' => ActionList, 'show' => ActionShow}
- def initialize controller_manifest
- @controller_manifest = controller_manifest
- @item_name = @controller_manifest.item_name
- @manifest = @controller_manifest.manifest
- @controller_conf = @controller_manifest.conf
- @actions = {}
- @my_item_name = @controller_conf['item_name'] || @item_name
- @controller_manifest.actions.each {|action_name, conf|
- type = conf['type']
- @actions[action_name] = @@types[type].new @my_item_name, action_name, conf
- }
- end
-
-
+require "manifest/controller/list"
+require "manifest/controller/show"
+module Manifest
+ class Controller
+ include ControllerModule
+ def self.manager manifest, my_manifests
+ my_manifests.map {|controller_name, controller_manifest|
+ self.new(manifest, controller_name, controller_manifest)
+ }
end
+
+ class Recipe
+ end
+
+ attr :manifest, :controller_name, :controller_manifest, :item_name, :actions
+ @@types = {'list' => ActionList, 'show' => ActionShow}
+ def initialize manifest, controller_name, controller_manifest
+ @manifest = manifest
+ @controller_name = controller_name
+ @controller_manifest = controller_manifest
+ self.set_default
+ self.init
+ end
+
+ def set_default
+ @controller_manifest['item_name'] ||= @controller_name
+ @controller_manifest['actions'] ||= {}
+ end
+
+ def init
+ @item_name = @controller_manifest['item_name']
+ @actions = {}
+ @controller_manifest['actions'].each {|action_name, action_manifest|
+ raise "undefined class for controllers > #{@controller_name} > actions > #{action_name} > type > #{action_manifest['type']}\n" unless @@types[action_manifest['type']]
+ @actions[action_name] = @@types[action_manifest['type']].new(self, action_name, action_manifest)
+ }
+ end
+
end
end
-