2012-09-24 03:43:48 +00:00
|
|
|
module OrbitApp
|
|
|
|
module Module
|
|
|
|
module Registration
|
|
|
|
Version = "0.1"
|
|
|
|
|
|
|
|
module ClassMethods
|
|
|
|
@@registrations = []
|
|
|
|
|
|
|
|
def new( name ,&block)
|
|
|
|
@@registrations << DataSheet.new(name,&block)
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_by_key(key)
|
|
|
|
@@registrations.each{|t|
|
2012-11-29 06:21:46 +00:00
|
|
|
return t if t.key == key
|
2012-09-24 03:43:48 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def all
|
|
|
|
return @@registrations
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
extend ClassMethods
|
|
|
|
def self.included( other )
|
|
|
|
other.extend( ClassMethods )
|
|
|
|
end
|
|
|
|
|
|
|
|
class DataSheet
|
2012-11-29 06:21:46 +00:00
|
|
|
attr_reader :name,:key,:base_path,:module_label
|
2012-09-24 03:43:48 +00:00
|
|
|
|
|
|
|
def initialize(name, &block)
|
|
|
|
@name = name
|
2012-11-29 06:21:46 +00:00
|
|
|
@key = name.underscore.singularize
|
2012-11-20 07:56:52 +00:00
|
|
|
@side_bar = nil
|
2012-11-29 06:21:46 +00:00
|
|
|
@front_end_app_pages = nil
|
2012-09-24 03:43:48 +00:00
|
|
|
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
|
2012-11-29 06:21:46 +00:00
|
|
|
setup_module_app
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup_module_app
|
|
|
|
module_app = ModuleApp.first(conditions: {:key=>@key,:title=>name})
|
|
|
|
module_app = ModuleApp.new(:key=>@key,:title=>name) if module_app.nil?
|
|
|
|
|
|
|
|
begin
|
|
|
|
module_app.save(:validate=>false)
|
|
|
|
rescue
|
|
|
|
retry
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_label_i18n
|
|
|
|
@module_label
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_default_widget
|
|
|
|
if @widget_set.nil? # Init not defining widget
|
|
|
|
return {}
|
|
|
|
elsif @widget_set.get_default_widget.nil? # Init had defining widget,but say nothing about default_widget
|
|
|
|
return {}
|
|
|
|
else
|
|
|
|
@widget_set.get_default_widget.to_module_app_format
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_enable_frontend
|
|
|
|
(@front_end_app_pages.nil? ? false : true)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_app_pages
|
|
|
|
@front_end_app_pages.nil? ? [] : @front_end_app_pages.to_module_app_format
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_widgets
|
|
|
|
@widget_set.nil? ? {} : @widget_set.to_module_app_format
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_categories
|
|
|
|
eval(@widget_set.categories_query) rescue nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_tags
|
|
|
|
eval(@widget_set.tags_query) rescue nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def front_end(&block)
|
|
|
|
@front_end_app_pages = FrontendUtility::AppPageSet.new(&block)
|
2012-09-24 03:43:48 +00:00
|
|
|
end
|
|
|
|
|
2012-11-20 07:56:52 +00:00
|
|
|
def side_bar(&block)
|
2012-11-29 06:21:46 +00:00
|
|
|
@side_bar = SideBarRegisition::SideBar.new(@name,@key,&block)
|
2012-09-24 03:43:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def personal_plugin(params)
|
|
|
|
# TODO 這裡要看是一些檔案是不是都有
|
|
|
|
Plugin::Registration.new_from_module_app(@name,@base_path,params)
|
|
|
|
end
|
|
|
|
|
2012-11-29 06:21:46 +00:00
|
|
|
def widgets(&block)
|
|
|
|
# @widgets = WidgetRegisition::WidgetSet.new(&block)
|
|
|
|
@widget_set = WidgetUtility::WidgetSet.new(&block)
|
|
|
|
|
|
|
|
# @widgets = widget_set.widgets
|
|
|
|
# @default_widget = widget_set.default_widget
|
|
|
|
end
|
|
|
|
|
|
|
|
%w{module_label category base_url version organization author intro update_info}.each do |field|
|
|
|
|
define_method(field){|var| instance_variable_set( "@" + field, var)}
|
2012-09-24 03:43:48 +00:00
|
|
|
end
|
2012-11-29 06:21:46 +00:00
|
|
|
|
|
|
|
end # of class DataSheet
|
|
|
|
|
2012-09-24 03:43:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|