Class: Rtml::WidgetCore::GuiConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/rtml/widget_core/gui_configuration.rb

Overview

This class is yielded to Rtml::Widget#gui in order to set up the Widget in question for use within the RTML Application Builder (the GUI).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(widget_class) ⇒ GuiConfiguration

Returns a new instance of GuiConfiguration.



21
22
23
24
25
26
27
# File 'lib/rtml/widget_core/gui_configuration.rb', line 21

def initialize(widget_class)
  @widget_class = widget_class
  @title = nil#widget_class.name.gsub(/Rtml(\:\:|\/)Widgets(\:\:|\/)/, '').titleize
  @fields = ActiveSupport::OrderedHash.new
  @entry_points = :all
  initializer_arguments { |fields| [fields] }
end

Instance Attribute Details

#fieldsObject (readonly)

A hash whose keys represent options to be passed to this Widget when it is instantiated. The value for each key is either a Symbol or an Array containing a String and a Symbol:

Examples:

# This is what the Screens Widget looks like:

gui do |config|
  . . .
  config.fields[:next] = { :caption => "Next Screen", :type => :screen_ref }
  config.fields[:name] = :string
end


19
20
21
# File 'lib/rtml/widget_core/gui_configuration.rb', line 19

def fields
  @fields
end

#iconObject

Returns the value of attribute icon.



4
5
6
# File 'lib/rtml/widget_core/gui_configuration.rb', line 4

def icon
  @icon
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/rtml/widget_core/gui_configuration.rb', line 4

def title
  @title
end

#tooltip_messageObject

Returns the value of attribute tooltip_message.



4
5
6
# File 'lib/rtml/widget_core/gui_configuration.rb', line 4

def tooltip_message
  @tooltip_message
end

#widget_classObject (readonly)

Returns the value of attribute widget_class.



5
6
7
# File 'lib/rtml/widget_core/gui_configuration.rb', line 5

def widget_class
  @widget_class
end

Instance Method Details

#construct_arguments(fields) ⇒ Object

Takes a hash of fields and produces an array of arguments.



91
92
93
# File 'lib/rtml/widget_core/gui_configuration.rb', line 91

def construct_arguments(fields)
  @initializer_arguments.call(fields)
end

#entry_pointsObject

Returns all entry points found in #widget_class that can be associated with the GUI. By default, this returns all entry points. See also #entry_points=



57
58
59
60
61
# File 'lib/rtml/widget_core/gui_configuration.rb', line 57

def entry_points
  return widget_class.entry_points if @entry_points == :all
  return @entry_points if @entry_points.kind_of?(Array)
  return [@entry_points]
end

#entry_points=(entry_point_or_points) ⇒ Object

Defines the specific entry points which can be used with this GUI. If this is set to :all, then all entry points in the #widget_class will be used.

This can be a symbol, string or an array of symbols/strings.



67
68
69
# File 'lib/rtml/widget_core/gui_configuration.rb', line 67

def entry_points=(entry_point_or_points)
  @entry_points = entry_point_or_points
end

#fields_with_inferencesObject

Constructs a complete options hash for each field, and then returns an array containing those hashes. A complete options hash includes :name, :caption and :type. If not found, :type defaults to :string and :caption defaults to options.titleize.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rtml/widget_core/gui_configuration.rb', line 32

def fields_with_inferences
  field_array = []
  fields.each do |name, setup|
    field_options = {:name => name, :caption => name.to_s.titleize, :type => setup || :string}
    if setup.kind_of?(Array)
      field_options[:caption] = setup[0]
      field_options[:type] = setup[1] || :string
      if setup[1].nil? && field_options[:caption].is_a?(Symbol)
        field_options[:type] = field_options[:caption]
        field_options[:caption] = name.to_s.titleize
      end
      if field_options[:caption].is_a?(Symbol) && field_options[:type].is_a?(String)
        field_options[:caption], field_options[:type] = field_options[:type], field_options[:caption]
      end
    elsif setup.kind_of?(Hash)
      field_options.merge! setup
    end
    field_array << field_options
  end
  field_array
end

#id(addl = nil) ⇒ Object



71
72
73
# File 'lib/rtml/widget_core/gui_configuration.rb', line 71

def id(addl = nil)
  "#{title}_#{addl}".parameterize('_').to_s
end

#initializer_arguments(&block) ⇒ Object

Give this method a block which returns an Array. That array will be converted to arguments to initialize an instance of this Widget.

Example:

# This is the default implementation:
gui do |config|
  . . .
  config.initializer_arguments do |fields|
    [ fields ] # since fields is a hash, this will look like [ :name => '...', :next => '...', :etc => '...' ]
  end
end


86
87
88
# File 'lib/rtml/widget_core/gui_configuration.rb', line 86

def initializer_arguments(&block)
  @initializer_arguments = block
end