Class: Lustr::ParseContext

Inherits:
Object
  • Object
show all
Defined in:
lib/lustr/parse_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParseContext

Returns a new instance of ParseContext.



20
21
22
23
24
25
26
# File 'lib/lustr/parse_context.rb', line 20

def initialize
	@gadget_builders={}
	@builder_stack=[]
	builder=GadgetBuilder.new
	gadget_builders[nil]=builder
	@builder_stack.push builder
end

Instance Attribute Details

#gadget_buildersObject (readonly)

Returns the value of attribute gadget_builders.



18
19
20
# File 'lib/lustr/parse_context.rb', line 18

def gadget_builders
  @gadget_builders
end

Instance Method Details

#add_builder(name, options) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/lustr/parse_context.rb', line 32

def add_builder(name, options)
	current=current_builder
	builder_klass=Lustr.get_builder_klass(name)

	if builder_klass.kind_of?(Class)
		child=builder_klass.new(options)
	else
		child=builder_klass.dup_from(options)
	end
	
	current << child
	attach_builder(child) { yield if block_given? }
end

#attach_builder(builder, name = nil) ⇒ Object



46
47
48
49
50
51
# File 'lib/lustr/parse_context.rb', line 46

def attach_builder(builder, name=nil)
	@builder_stack.push builder
	gadget_builders[name]=builder if name && builder.kind_of?(GadgetBuilder)
	yield if block_given?
	@builder_stack.pop
end

#current_builderObject



28
29
30
# File 'lib/lustr/parse_context.rb', line 28

def current_builder
	@builder_stack.last
end

#handle_event(name, callable) ⇒ Object



53
54
55
# File 'lib/lustr/parse_context.rb', line 53

def handle_event(name, callable)
	current_builder.event_handlers[name]=callable
end