Class: Lustr::BuilderBase
- Inherits:
-
Object
- Object
- Lustr::BuilderBase
- Defined in:
- lib/lustr/builder.rb
Overview
BuilderBase is the base class of all builders used in toolkits. A “builder” takes the definition from the DSL and creates a widget instance (runtime) or generates the appropriate UI source code (generative). The norm is for builders to be subclasses of BuilderBase and declared through Lustr.declare()
.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#event_handlers ⇒ Object
readonly
Returns the value of attribute event_handlers.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#widget_type ⇒ Object
readonly
Returns the value of attribute widget_type.
Instance Method Summary collapse
- #<<(child) ⇒ Object
- #all_event_handlers ⇒ Object
- #build_all(eval_context, parent_widget = nil) ⇒ Object
- #dup_from(options) ⇒ Object
-
#initialize(widget_type, options = {}) ⇒ BuilderBase
constructor
A new instance of BuilderBase.
Constructor Details
#initialize(widget_type, options = {}) ⇒ BuilderBase
Returns a new instance of BuilderBase.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/lustr/builder.rb', line 29 def initialize(, ={}) @widget_type= @children=[] @event_handlers={} if @options=Lustr.defaults().merge() else @options= end @name=self.[:name] end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
26 27 28 |
# File 'lib/lustr/builder.rb', line 26 def children @children end |
#event_handlers ⇒ Object (readonly)
Returns the value of attribute event_handlers.
26 27 28 |
# File 'lib/lustr/builder.rb', line 26 def event_handlers @event_handlers end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
26 27 28 |
# File 'lib/lustr/builder.rb', line 26 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
27 28 29 |
# File 'lib/lustr/builder.rb', line 27 def @options end |
#widget_type ⇒ Object (readonly)
Returns the value of attribute widget_type.
26 27 28 |
# File 'lib/lustr/builder.rb', line 26 def @widget_type end |
Instance Method Details
#<<(child) ⇒ Object
53 54 55 |
# File 'lib/lustr/builder.rb', line 53 def <<(child) children << child if child end |
#all_event_handlers ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/lustr/builder.rb', line 43 def all_event_handlers result=event_handlers children.each do |child| result.merge!(child.all_event_handlers) end return result end |
#build_all(eval_context, parent_widget = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/lustr/builder.rb', line 57 def build_all(eval_context, =nil) =nil if =build(.resolve_parent) else =build(nil) end .() .name=[:name] .eval_context=eval_context .gadget=eval_context.current_gadget eval_context.current_gadget.[.name]= if eval_context.current_gadget && .name proc=lambda { children.each do |child| tree=child.build_all(eval_context, .resolve) << tree end } if .respond_to?(:init_block=) .init_block=proc elsif .kind_of?(Gadget) eval_context.for_gadget(, proc) else proc.call end return end |
#dup_from(options) ⇒ Object
90 91 92 |
# File 'lib/lustr/builder.rb', line 90 def dup_from() self.class.new(, ) end |