Class: Lustr::BuilderBase

Inherits:
Object
  • Object
show all
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

GadgetBuilder, SimpleBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={})
	@widget_type=widget_type
	@children=[]
	@event_handlers={}

	if widget_type
		@options=Lustr.defaults(widget_type).merge(options)
	else
		@options=options
	end

	@name=self.options[:name]
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



26
27
28
# File 'lib/lustr/builder.rb', line 26

def children
  @children
end

#event_handlersObject (readonly)

Returns the value of attribute event_handlers.



26
27
28
# File 'lib/lustr/builder.rb', line 26

def event_handlers
  @event_handlers
end

#nameObject (readonly)

Returns the value of attribute name.



26
27
28
# File 'lib/lustr/builder.rb', line 26

def name
  @name
end

#optionsObject

Returns the value of attribute options.



27
28
29
# File 'lib/lustr/builder.rb', line 27

def options
  @options
end

#widget_typeObject (readonly)

Returns the value of attribute widget_type.



26
27
28
# File 'lib/lustr/builder.rb', line 26

def widget_type
  @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_handlersObject



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, parent_widget=nil)
	widget=nil
	
	if parent_widget
		widget=build(parent_widget.resolve_parent)
	else
		widget=build(nil)
	end

	widget.init_options(options)
	widget.name=options[:name]
	widget.eval_context=eval_context
	widget.gadget=eval_context.current_gadget
	eval_context.current_gadget.widgets[widget.name]=widget if eval_context.current_gadget && widget.name
		
	proc=lambda {
		children.each do |child|
			tree=child.build_all(eval_context, widget.resolve)
			widget << tree
		end
	}

	if widget.respond_to?(:init_block=)
		widget.init_block=proc
	elsif widget.kind_of?(Gadget)
		eval_context.for_gadget(widget, proc)
	else
		proc.call
	end

	return widget
end

#dup_from(options) ⇒ Object



90
91
92
# File 'lib/lustr/builder.rb', line 90

def dup_from(options)
	self.class.new(widget_type, options)
end