Class: Utopia::Middleware::Content::Transaction
- Inherits:
-
Object
- Object
- Utopia::Middleware::Content::Transaction
show all
- Defined in:
- lib/utopia/middleware/content/node.rb
Overview
Nodes typically represent XNODE files on the disk. You can get a list of Links from a current directory. This comprises of all files ending in “.xnode”.
Defined Under Namespace
Classes: State
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(request, response) ⇒ Transaction
Returns a new instance of Transaction.
114
115
116
117
118
119
120
|
# File 'lib/utopia/middleware/content/node.rb', line 114
def initialize(request, response)
@begin_tags = []
@end_tags = []
@request = request
@response = response
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
263
264
265
266
267
268
269
270
271
|
# File 'lib/utopia/middleware/content/node.rb', line 263
def method_missing(name, *args)
@begin_tags.reverse_each do |state|
if state.node.respond_to? name
return state.node.send(name, *args)
end
end
super
end
|
Instance Attribute Details
Begin tags represents a list from outer to inner most tag. At any point in parsing xml, begin_tags is a list of the inner most tag, then the next outer tag, etc. This list is used for doing dependent lookups.
136
137
138
|
# File 'lib/utopia/middleware/content/node.rb', line 136
def begin_tags
@begin_tags
end
|
End tags represents a list of execution order. This is the order that end tags have appeared when evaluating nodes.
140
141
142
|
# File 'lib/utopia/middleware/content/node.rb', line 140
def end_tags
@end_tags
end
|
#request ⇒ Object
Returns the value of attribute request.
130
131
132
|
# File 'lib/utopia/middleware/content/node.rb', line 130
def request
@request
end
|
#response ⇒ Object
Returns the value of attribute response.
131
132
133
|
# File 'lib/utopia/middleware/content/node.rb', line 131
def response
@response
end
|
Instance Method Details
#attributes ⇒ Object
142
143
144
|
# File 'lib/utopia/middleware/content/node.rb', line 142
def attributes
return current.attributes
end
|
#binding ⇒ Object
122
123
124
|
# File 'lib/utopia/middleware/content/node.rb', line 122
def binding
super
end
|
#cdata(text) ⇒ Object
207
208
209
|
# File 'lib/utopia/middleware/content/node.rb', line 207
def cdata(text)
current.cdata(text)
end
|
#content ⇒ Object
150
151
152
|
# File 'lib/utopia/middleware/content/node.rb', line 150
def content
@end_tags[-1].content
end
|
#current ⇒ Object
146
147
148
|
# File 'lib/utopia/middleware/content/node.rb', line 146
def current
@begin_tags[-1]
end
|
#first ⇒ Object
159
160
161
|
# File 'lib/utopia/middleware/content/node.rb', line 159
def first
@begin_tags[0]
end
|
#lookup(tag) ⇒ Object
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
# File 'lib/utopia/middleware/content/node.rb', line 244
def lookup(tag)
result = tag
node = nil
@begin_tags.reverse_each do |state|
result = state.lookup(result)
node ||= state.node if state.node.respond_to? :lookup
return result if Node === result
end
@end_tags.reverse_each do |state|
return state.node.lookup(result) if state.node.respond_to? :lookup
end
return nil
end
|
#parent ⇒ Object
154
155
156
157
|
# File 'lib/utopia/middleware/content/node.rb', line 154
def parent
end_tags[-2]
end
|
#parse_xml(xml_data) ⇒ Object
126
127
128
|
# File 'lib/utopia/middleware/content/node.rb', line 126
def parse_xml(xml_data)
XNode::Processor.new(xml_data, self).parse
end
|
#render_node(node, attributes = {}) ⇒ Object
237
238
239
240
241
242
|
# File 'lib/utopia/middleware/content/node.rb', line 237
def render_node(node, attributes = {})
state = State.new(attributes, node)
@begin_tags << state
return tag_end
end
|
#tag(name, attributes) {|node| ... } ⇒ Object
163
164
165
166
167
168
169
170
171
|
# File 'lib/utopia/middleware/content/node.rb', line 163
def tag(name, attributes, &block)
tag = Tag.new(name, attributes)
node = tag_begin(tag)
yield node if block_given?
tag_end(tag)
end
|
#tag_begin(tag, node = nil) ⇒ Object
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
# File 'lib/utopia/middleware/content/node.rb', line 188
def tag_begin(tag, node = nil)
node ||= lookup(tag)
if node
state = State.new(tag, node)
@begin_tags << state
if node.respond_to? :tag_begin
node.tag_begin(self, state)
end
return node
end
current.tag_begin(tag)
return nil
end
|
#tag_complete(tag, node = nil) ⇒ Object
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/utopia/middleware/content/node.rb', line 173
def tag_complete(tag, node = nil)
if tag.name == "content"
current.markup(content)
else
node ||= lookup(tag)
if node
tag_begin(tag, node)
tag_end(tag)
else
current.tag_complete(tag)
end
end
end
|
#tag_end(tag = nil) ⇒ Object
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
# File 'lib/utopia/middleware/content/node.rb', line 211
def tag_end(tag = nil)
top = current
if top.tags.empty?
if top.node.respond_to? :tag_end
top.node.tag_end(self, top)
end
@end_tags << top
buffer = top.call(self)
@begin_tags.pop
@end_tags.pop
if current
current.markup(buffer)
end
return buffer
else
current.tag_end(tag)
end
return nil
end
|