Class: Rtml::WidgetCore::GuiConfiguration
- Inherits:
-
Object
- Object
- Rtml::WidgetCore::GuiConfiguration
- 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
-
#fields ⇒ Object
readonly
A hash whose keys represent options to be passed to this Widget when it is instantiated.
-
#icon ⇒ Object
Returns the value of attribute icon.
-
#title ⇒ Object
Returns the value of attribute title.
-
#tooltip_message ⇒ Object
Returns the value of attribute tooltip_message.
-
#widget_class ⇒ Object
readonly
Returns the value of attribute widget_class.
Instance Method Summary collapse
-
#construct_arguments(fields) ⇒ Object
Takes a hash of fields and produces an array of arguments.
-
#entry_points ⇒ Object
Returns all entry points found in #widget_class that can be associated with the GUI.
-
#entry_points=(entry_point_or_points) ⇒ Object
Defines the specific entry points which can be used with this GUI.
-
#fields_with_inferences ⇒ Object
Constructs a complete options hash for each field, and then returns an array containing those hashes.
- #id(addl = nil) ⇒ Object
-
#initialize(widget_class) ⇒ GuiConfiguration
constructor
A new instance of GuiConfiguration.
-
#initializer_arguments(&block) ⇒ Object
Give this method a block which returns an Array.
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 = @title = nil#widget_class.name.gsub(/Rtml(\:\:|\/)Widgets(\:\:|\/)/, '').titleize @fields = ActiveSupport::OrderedHash.new @entry_points = :all initializer_arguments { |fields| [fields] } end |
Instance Attribute Details
#fields ⇒ Object (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 |
#icon ⇒ Object
Returns the value of attribute icon.
4 5 6 |
# File 'lib/rtml/widget_core/gui_configuration.rb', line 4 def icon @icon end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/rtml/widget_core/gui_configuration.rb', line 4 def title @title end |
#tooltip_message ⇒ Object
Returns the value of attribute tooltip_message.
4 5 6 |
# File 'lib/rtml/widget_core/gui_configuration.rb', line 4 def @tooltip_message end |
#widget_class ⇒ Object (readonly)
Returns the value of attribute widget_class.
5 6 7 |
# File 'lib/rtml/widget_core/gui_configuration.rb', line 5 def @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_points ⇒ Object
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 .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_inferences ⇒ Object
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| = {:name => name, :caption => name.to_s.titleize, :type => setup || :string} if setup.kind_of?(Array) [:caption] = setup[0] [:type] = setup[1] || :string if setup[1].nil? && [:caption].is_a?(Symbol) [:type] = [:caption] [:caption] = name.to_s.titleize end if [:caption].is_a?(Symbol) && [:type].is_a?(String) [:caption], [:type] = [:type], [:caption] end elsif setup.kind_of?(Hash) .merge! setup end field_array << 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 |