Class: Utopia::Middleware::Content::Processor
- Inherits:
-
Object
- Object
- Utopia::Middleware::Content::Processor
show all
- Defined in:
- lib/utopia/middleware/content/processor.rb
Defined Under Namespace
Classes: UnbalancedTagError
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(delegate) ⇒ Processor
Returns a new instance of Processor.
57
58
59
60
61
62
|
# File 'lib/utopia/middleware/content/processor.rb', line 57
def initialize(delegate)
@delegate = delegate
@stack = []
@parser = Trenni::Parser.new(self)
end
|
Class Method Details
.parse_xml(xml_data, delegate) ⇒ Object
29
30
31
32
33
|
# File 'lib/utopia/middleware/content/processor.rb', line 29
def self.parse_xml(xml_data, delegate)
processor = self.new(delegate)
processor.parse(xml_data)
end
|
Instance Method Details
#attribute(name, value) ⇒ Object
113
114
115
|
# File 'lib/utopia/middleware/content/processor.rb', line 113
def attribute(name, value)
@stack.last[0].attributes[name] = value
end
|
#begin_parse(scanner) ⇒ Object
68
69
70
|
# File 'lib/utopia/middleware/content/processor.rb', line 68
def begin_parse(scanner)
@scanner = scanner
end
|
#begin_tag(tag_name, begin_tag_type) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/utopia/middleware/content/processor.rb', line 84
def begin_tag(tag_name, begin_tag_type)
if begin_tag_type == :opened
@stack << [Tag.new(tag_name, {}), @scanner.pos]
else
current_tag, current_position = @stack.pop
if (tag_name != current_tag.name)
raise UnbalancedTagError.new(@scanner, current_position, current_tag.name, tag_name)
end
@delegate.tag_end(current_tag)
end
end
|
#cdata(text) ⇒ Object
76
77
78
|
# File 'lib/utopia/middleware/content/processor.rb', line 76
def cdata(text)
@delegate.cdata(Trenni::Strings::to_html(text))
end
|
80
81
82
|
# File 'lib/utopia/middleware/content/processor.rb', line 80
def (text)
@delegate.cdata("<!#{text}>")
end
|
#finish_tag(begin_tag_type, end_tag_type) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/utopia/middleware/content/processor.rb', line 98
def finish_tag(begin_tag_type, end_tag_type)
if begin_tag_type == :opened if end_tag_type == :closed cur, pos = @stack.pop
cur.closed = true
@delegate.tag_complete(cur)
elsif end_tag_type == :opened cur, pos = @stack.last
@delegate.tag_begin(cur)
end
end
end
|
#instruction(content) ⇒ Object
117
118
119
|
# File 'lib/utopia/middleware/content/processor.rb', line 117
def instruction(content)
cdata("<?#{content}?>")
end
|
#parse(input) ⇒ Object
64
65
66
|
# File 'lib/utopia/middleware/content/processor.rb', line 64
def parse(input)
@parser.parse(input)
end
|
#text(text) ⇒ Object
72
73
74
|
# File 'lib/utopia/middleware/content/processor.rb', line 72
def text(text)
@delegate.cdata(text)
end
|