Class: Utopia::Middleware::Content::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/middleware/content/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, uri_path, request_path, file_path) ⇒ Node

Returns a new instance of Node.



285
286
287
288
289
290
291
# File 'lib/utopia/middleware/content/node.rb', line 285

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_pathObject (readonly)

Returns the value of attribute file_path.



295
296
297
# File 'lib/utopia/middleware/content/node.rb', line 295

def file_path
  @file_path
end

#request_pathObject (readonly)

Returns the value of attribute request_path.



293
294
295
# File 'lib/utopia/middleware/content/node.rb', line 293

def request_path
  @request_path
end

#uri_pathObject (readonly)

Returns the value of attribute uri_path.



294
295
296
# File 'lib/utopia/middleware/content/node.rb', line 294

def uri_path
  @uri_path
end

Instance Method Details

#call(transaction, state) ⇒ Object



362
363
364
365
366
# File 'lib/utopia/middleware/content/node.rb', line 362

def call(transaction, state)
	xml_data = @controller.fetch_xml(@file_path).result(transaction.binding)
	
	transaction.parse_xml(xml_data)
end


297
298
299
# File 'lib/utopia/middleware/content/node.rb', line 297

def link
	return Link.new(:file, uri_path)
end


332
333
334
335
336
337
338
339
340
341
# File 'lib/utopia/middleware/content/node.rb', line 332

def links(path = ".", options = {}, &block)
	path = uri_path.dirname + Path.create(path)
	links = Links.index(@controller.root, path, options)
	
	if block_given?
		links.each &block
	else
		links
	end
end

#local_path(path = ".", base = nil) ⇒ Object



305
306
307
308
309
310
311
312
313
314
315
# File 'lib/utopia/middleware/content/node.rb', line 305

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



317
318
319
320
321
322
323
324
325
326
# File 'lib/utopia/middleware/content/node.rb', line 317

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 likely 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



301
302
303
# File 'lib/utopia/middleware/content/node.rb', line 301

def lookup_node(path)
	@controller.lookup_node(path)
end

#parent_pathObject



328
329
330
# File 'lib/utopia/middleware/content/node.rb', line 328

def parent_path
	uri_path.dirname
end

#process!(request, response, attributes = {}) ⇒ Object



368
369
370
371
# File 'lib/utopia/middleware/content/node.rb', line 368

def process!(request, response, attributes = {})
	transaction = Transaction.new(request, response)
	response.write(transaction.render_node(self, attributes))
end


343
344
345
346
# File 'lib/utopia/middleware/content/node.rb', line 343

def related_links
	name = @uri_path.basename.split(".").first
	links = Links.index(@controller.root, uri_path.dirname, :name => name, :indices => true)
end


358
359
360
# File 'lib/utopia/middleware/content/node.rb', line 358

def sibling_links(options = {})
	return Links.index(@controller.root, siblings_path, options)
end

#siblings_pathObject



348
349
350
351
352
353
354
355
356
# File 'lib/utopia/middleware/content/node.rb', line 348

def siblings_path
	name = @uri_path.basename.split(".").first
	
	if name == "index"
		@uri_path.dirname(2)
	else
		@uri_path.dirname
	end
end