118 lines
2.9 KiB
Ruby
118 lines
2.9 KiB
Ruby
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
|
|
eval(@categories_query) rescue nil
|
|
end
|
|
|
|
def get_tags
|
|
eval(@tags_query) rescue nil
|
|
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["default_widget"]= DefaultWidget.get_interface_args unless @default_widget.blank?
|
|
hash
|
|
end
|
|
|
|
def get_default_widget
|
|
return @default_widget
|
|
end
|
|
|
|
end
|
|
|
|
class DefaultWidget
|
|
STYLE = ["typeA","typeB_style2","typeB_style3","typeB_style4","typeC"]
|
|
|
|
def initialize(&block)
|
|
@query = nil
|
|
@image = nil
|
|
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
|
|
end
|
|
|
|
def self.get_interface_args
|
|
#will need to work with design
|
|
{:name=>"default_widget",:field=>nil,:label=>'label',:style=>STYLE}
|
|
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
|
|
@style= options[:style]
|
|
end
|
|
|
|
def to_hash
|
|
{:name => @name,:fields=>@fields,:label=>@label,:style=>@style}
|
|
end
|
|
|
|
def finalize!
|
|
|
|
end
|
|
|
|
protected
|
|
|
|
end# of widget
|
|
end # of WidgetRegisition
|
|
end # of Module
|
|
end # of OrbitApp
|