Class: Utopia::Content::Node
- Inherits:
-
Object
- Object
- Utopia::Content::Node
- Defined in:
- lib/utopia/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, attributes = {}) ⇒ 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.
298 299 300 301 302 303 304 |
# File 'lib/utopia/content/node.rb', line 298 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.
308 309 310 |
# File 'lib/utopia/content/node.rb', line 308 def file_path @file_path end |
#request_path ⇒ Object (readonly)
Returns the value of attribute request_path.
306 307 308 |
# File 'lib/utopia/content/node.rb', line 306 def request_path @request_path end |
#uri_path ⇒ Object (readonly)
Returns the value of attribute uri_path.
307 308 309 |
# File 'lib/utopia/content/node.rb', line 307 def uri_path @uri_path end |
Instance Method Details
#call(transaction, state) ⇒ Object
376 377 378 379 380 |
# File 'lib/utopia/content/node.rb', line 376 def call(transaction, state) xml_data = @controller.fetch_xml(@file_path).evaluate(transaction) transaction.parse_xml(xml_data) end |
#link ⇒ Object
310 311 312 |
# File 'lib/utopia/content/node.rb', line 310 def link return Link.new(:file, uri_path) end |
#links(path = '.', **options, &block) ⇒ Object
346 347 348 349 350 351 352 353 354 355 |
# File 'lib/utopia/content/node.rb', line 346 def links(path = '.', **, &block) path = uri_path.dirname + Path[path] links = Links.index(@controller.root, path, ) if block_given? links.each &block else links end end |
#local_path(path = '.', base = nil) ⇒ Object
318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/utopia/content/node.rb', line 318 def local_path(path = '.', base = nil) path = Path[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
331 332 333 334 335 336 337 338 339 340 |
# File 'lib/utopia/content/node.rb', line 331 def lookup(tag) from_path = parent_path # If the current node is called 'foo', we can't lookup 'foo' in the current directory or we will have infinite recursion. if tag.name == @uri_path.basename from_path = from_path.dirname end return @controller.lookup_tag(tag.name, from_path) end |
#lookup_node(path) ⇒ Object
314 315 316 |
# File 'lib/utopia/content/node.rb', line 314 def lookup_node(path) @controller.lookup_node(path) end |
#parent_path ⇒ Object
342 343 344 |
# File 'lib/utopia/content/node.rb', line 342 def parent_path uri_path.dirname end |
#process!(request, response, attributes = {}) ⇒ Object
382 383 384 385 |
# File 'lib/utopia/content/node.rb', line 382 def process!(request, response, attributes = {}) transaction = Transaction.new(request, response) response.write(transaction.render_node(self, attributes)) end |
#related_links ⇒ Object
357 358 359 360 |
# File 'lib/utopia/content/node.rb', line 357 def name = @uri_path.last.split('.', 2).first links = Links.index(@controller.root, uri_path.dirname, :name => name, :indices => true) end |
#sibling_links(**options) ⇒ Object
372 373 374 |
# File 'lib/utopia/content/node.rb', line 372 def sibling_links(**) return Links.index(@controller.root, siblings_path, ) end |
#siblings_path ⇒ Object
362 363 364 365 366 367 368 369 370 |
# File 'lib/utopia/content/node.rb', line 362 def siblings_path name = @uri_path.last.split('.', 2).first if name == INDEX @uri_path.dirname(2) else @uri_path.dirname end end |