Utopia SourceUtopiaContentDocument

class Document

A single request through content middleware. We use a struct to hide instance varibles since we instance_exec within this context.

Nested

Definitions

def controller

A helper method for accessing controller variables from view:

Implementation

def controller
	@controller ||= Utopia::Controller[request]
end

attr :request

The Rack::Request for this document.

attr :attributes

Per-document global attributes.

attr :current

The current state, represents a list from outer to inner most tag by traversing attr :parent. At any point in parsing markup, this is a list of the inner most tag, then the next outer tag, etc.

attr :first

The first class Utopia::Content::Document::State generated by rendering this document. It contains useful information regarding the node and uri used to access the resource.

attr :end_tags

End tags represents a list of execution order. This is the order that end tags have appeared when evaluating nodes.

def lookup_tag(tag)

Maps a tag to a node instance by asking the current node to lookup the tag name. This function is called for each tag and thus heavily affects performance.

Implementation

def lookup_tag(tag)
	# result = tag
	# 
	# # This loop works from inner to outer tags, and updates the tag we are currently searching for based on any overrides:
	# @begin_tags.reverse_each do |state|
	# 	result = state.lookup(result)
	# 	
	# 	return result if result.is_a?(Node)
	# end
	
	# This loop looks up a tag by asking the most embedded node to look it up based on tag name. This almost always only evaluates the top state:
	@end_tags.reverse_each do |state|
		return state.node.lookup_tag(tag) if state.node.respond_to?(:lookup_tag)
	end
	
	return nil
end

def lookup_node(path)

Lookup a node with the given path relative to the current node.

Implementation

def lookup_node(path)
	@end_tags.reverse_each do |state|
		return state.node.lookup_node(path) if state.node.respond_to?(:lookup_node)
	end
end

def content

The content of the node

Implementation

def content
	@end_tags.last.content
end