Class: Utopia::XNode::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/xnode/processor.rb

Instance Method Summary collapse

Constructor Details

#initialize(content, delegate, options = {}) ⇒ Processor

Returns a new instance of Processor.



29
30
31
32
33
34
# File 'lib/utopia/xnode/processor.rb', line 29

def initialize(content, delegate, options = {})
	@delegate = delegate
	@stack = []

	@scanner = (options[:scanner] || Scanner).new(self, content)
end

Instance Method Details

#attribute(name, value) ⇒ Object



77
78
79
# File 'lib/utopia/xnode/processor.rb', line 77

def attribute(name, value)
	@stack.last[0].attributes[name] = value
end

#begin_tag(tag_name, begin_tag_type) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/utopia/xnode/processor.rb', line 48

def begin_tag(tag_name, begin_tag_type)
	if begin_tag_type == OPENED_TAG
		@stack << [Tag.new(tag_name, {}), @scanner.pos]
	else
		cur, pos = @stack.pop
	
		if (tag_name != cur.name)
			raise UnbalancedTagError.new(@scanner, pos, cur.name, tag_name)
		end
	
		@delegate.tag_end(cur)
	end
end

#cdata(text) ⇒ Object



40
41
42
# File 'lib/utopia/xnode/processor.rb', line 40

def cdata(text)
	@delegate.cdata(text)
end

#comment(text) ⇒ Object



44
45
46
# File 'lib/utopia/xnode/processor.rb', line 44

def comment(text)
	cdata("<!#{text}>")
end

#finish_tag(begin_tag_type, end_tag_type) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/utopia/xnode/processor.rb', line 62

def finish_tag(begin_tag_type, end_tag_type)
	if begin_tag_type == OPENED_TAG # <...
		if end_tag_type == CLOSED_TAG # <.../>
			cur, pos = @stack.pop
			cur.closed = true

			@delegate.tag_complete(cur)
		elsif end_tag_type == OPENED_TAG # <...>
			cur, pos = @stack.last

			@delegate.tag_begin(cur)
		end
	end
end

#instruction(content) ⇒ Object



81
82
83
# File 'lib/utopia/xnode/processor.rb', line 81

def instruction(content)
	cdata("<?#{content}?>")
end

#parseObject



36
37
38
# File 'lib/utopia/xnode/processor.rb', line 36

def parse
	@scanner.parse
end