module OrbitApp module Module module WidgetUtility Version = "0.1" module ClassMethods @@widgets = [] def add(var) @@widgets << var end def all return @@widgets end end extend ClassMethods def self.included( other ) other.extend( ClassMethods ) end class WidgetSet attr_reader :widgets,:categories_query,:tags_query def initialize(&block) @widgets = [] @default_widget = nil @categories_query = '' @tags_query = '' block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? end %w{categories_query tags_query}.each do |field| define_method(field){|var| instance_variable_set( "@" + field, var)} end def get_categories @categories_query end def get_tags @tags_query end def default_widget(&block) @default_widget = DefaultWidget.new(&block) end def customize_widget(name,label,options ={}) @widgets << Widget.new(name,label,options) end def to_module_app_format hash = {} @widgets.collect{|t| hash[t.name] = t.to_hash} hash end def get_default_widget return @default_widget end end class DefaultWidget def initialize(&block) @query = nil @image = nil block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? end def to_module_app_format {:query=>@query,:image=>@image} rescue nil end def query(var) @query = var end def image(var) @image = var end end class Widget attr_reader :name,:default_template,:fields def initialize(name,label,options ={}) @name = name @fields = options[:fields] @label = label end def to_hash {:name => @name,:fields=>@fields,:label=>@label} end def finalize! end protected end# of widget end # of WidgetRegisition end # of Module end # of OrbitApp