Utopia SourceUtopiaContentNode

class Node

Represents an immutable node within the content hierarchy.

Definitions

def lookup_tag(tag)

Lookup the given tag which is being rendered within the given node. Invoked by class Utopia::Content::Document.

Implementation

def lookup_tag(tag)
	return @controller.lookup_tag(tag.name, self)
end

def call(document, state)

Invoked when the node is being rendered by class Utopia::Content::Document.

Implementation

def call(document, state)
	# Load the template:
	template = @controller.fetch_template(@file_path)
	
	# Evaluate the template/code:
	context = Context.new(document, state)
	markup = template.to_buffer(context)
	
	# Render the resulting markup into the document:
	document.parse_markup(markup)
end

Context

This is a special context in which a limited set of well defined methods are exposed in the content view.

Implementation

Context = Struct.new(:document, :state) do
	def partial(*arguments, &block)
		if block_given?
			state.defer(&block)
		else
			state.defer do |document|
				document.tag(*arguments)
			end
		end
	end
	
	alias deferred_tag partial
	
	def controller
		document.controller
	end
	
	def localization
		document.localization
	end
	
	def request
		document.request
	end
	
	def response
		document
	end
	
	def attributes
		state.attributes
	end
	
	def [] key
		state.attributes.fetch(key) {document.attributes[key]}
	end
	
	alias current state
	
	def content
		document.content
	end
	
	def parent
		document.parent
	end
	
	def first
		document.first
	end
	
	def links(*arguments, **options, &block)
		state.node.links(*arguments, **options, &block)
	end
end