Class: Utopia::Middleware::Content::Node
- Inherits:
-
Object
- Object
- Utopia::Middleware::Content::Node
- Defined in:
- lib/utopia/middleware/content/node.rb
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#request_path ⇒ Object
readonly
Returns the value of attribute request_path.
-
#uri_path ⇒ Object
readonly
Returns the value of attribute uri_path.
Instance Method Summary collapse
- #call(transaction, state) ⇒ Object
-
#initialize(controller, uri_path, request_path, file_path) ⇒ Node
constructor
A new instance of Node.
- #link ⇒ Object
- #links(path = ".", options = {}, &block) ⇒ Object
- #local_path(path = ".", base = nil) ⇒ Object
- #lookup(tag) ⇒ Object
- #lookup_node(path) ⇒ Object
- #parent_path ⇒ Object
- #process!(request, response) ⇒ Object
- #related_links ⇒ Object
- #sibling_links(options = {}) ⇒ Object
- #siblings_path ⇒ Object
Constructor Details
#initialize(controller, uri_path, request_path, file_path) ⇒ Node
Returns a new instance of Node.
263 264 265 266 267 268 269 |
# File 'lib/utopia/middleware/content/node.rb', line 263 def initialize(controller, uri_path, request_path, file_path) @controller = controller @uri_path = uri_path @request_path = request_path @file_path = file_path end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
273 274 275 |
# File 'lib/utopia/middleware/content/node.rb', line 273 def file_path @file_path end |
#request_path ⇒ Object (readonly)
Returns the value of attribute request_path.
271 272 273 |
# File 'lib/utopia/middleware/content/node.rb', line 271 def request_path @request_path end |
#uri_path ⇒ Object (readonly)
Returns the value of attribute uri_path.
272 273 274 |
# File 'lib/utopia/middleware/content/node.rb', line 272 def uri_path @uri_path end |
Instance Method Details
#call(transaction, state) ⇒ Object
333 334 335 336 337 |
# File 'lib/utopia/middleware/content/node.rb', line 333 def call(transaction, state) xml_data = @controller.fetch_xml(@file_path).result(transaction.binding) transaction.parse_xml(xml_data) end |
#link ⇒ Object
275 276 277 |
# File 'lib/utopia/middleware/content/node.rb', line 275 def link return Link.new(:file, uri_path) end |
#links(path = ".", options = {}, &block) ⇒ Object
303 304 305 306 307 308 309 310 311 312 |
# File 'lib/utopia/middleware/content/node.rb', line 303 def links(path = ".", = {}, &block) path = uri_path.dirname + Path.create(path) links = Links.index(@controller.root, path, ) if block_given? links.each &block else links end end |
#local_path(path = ".", base = nil) ⇒ Object
283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/utopia/middleware/content/node.rb', line 283 def local_path(path = ".", base = nil) path = Path.create(path) root = Pathname.new(@controller.root) if path.absolute? return root.join(*path.components) else base ||= uri_path.dirname return root.join(*(base + path).components) end end |
#lookup(tag) ⇒ Object
295 296 297 |
# File 'lib/utopia/middleware/content/node.rb', line 295 def lookup(tag) return @controller.lookup_tag(tag.name, parent_path) end |
#lookup_node(path) ⇒ Object
279 280 281 |
# File 'lib/utopia/middleware/content/node.rb', line 279 def lookup_node(path) @controller.lookup_node(path) end |
#parent_path ⇒ Object
299 300 301 |
# File 'lib/utopia/middleware/content/node.rb', line 299 def parent_path uri_path.dirname end |
#process!(request, response) ⇒ Object
339 340 341 342 |
# File 'lib/utopia/middleware/content/node.rb', line 339 def process!(request, response) transaction = Transaction.new(request, response) response.write(transaction.render_node(self)) end |
#related_links ⇒ Object
314 315 316 317 |
# File 'lib/utopia/middleware/content/node.rb', line 314 def name = @uri_path.basename.split(".").first links = Links.index(@controller.root, uri_path.dirname, :name => name, :indices => true) end |
#sibling_links(options = {}) ⇒ Object
329 330 331 |
# File 'lib/utopia/middleware/content/node.rb', line 329 def sibling_links( = {}) return Links.index(@controller.root, siblings_path, ) end |
#siblings_path ⇒ Object
319 320 321 322 323 324 325 326 327 |
# File 'lib/utopia/middleware/content/node.rb', line 319 def siblings_path name = @uri_path.basename.split(".").first if name == "index" @uri_path.dirname(2) else @uri_path.dirname end end |