class Utopia::Content::Node
Represents an immutable node within the content hierarchy.
Constants
- Context
This is a special context in which a limited set of well defined methods are exposed in the content view.
Attributes
file_path[R]
request_path[R]
uri_path[R]
Public Class Methods
new(controller, uri_path, request_path, file_path)
click to toggle source
# File lib/utopia/content/node.rb, line 34 def initialize(controller, uri_path, request_path, file_path) @controller = controller @uri_path = uri_path @request_path = request_path @file_path = file_path end
Public Instance Methods
call(document, state)
click to toggle source
Invoked when the node is being rendered by {Document}.
# File lib/utopia/content/node.rb, line 113 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
links(path = '.', **options, &block)
click to toggle source
# File lib/utopia/content/node.rb, line 78 def links(path = '.', **options, &block) path = uri_path.dirname + Path[path] links = @controller.links(path, **options) if block_given? links.each(&block) else links end end
local_path(path = '.', base = nil)
click to toggle source
# File lib/utopia/content/node.rb, line 54 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_node(path)
click to toggle source
# File lib/utopia/content/node.rb, line 50 def lookup_node(path) @controller.lookup_node(parent_path + Path[path]) end
lookup_tag(tag)
click to toggle source
Lookup the given tag which is being rendered within the given node. Invoked by {Document}. @return [Node] The node which will be used to render the tag.
# File lib/utopia/content/node.rb, line 108 def lookup_tag(tag) return @controller.lookup_tag(tag.name, self) end
name()
click to toggle source
# File lib/utopia/content/node.rb, line 46 def name @uri_path.basename end
parent_path()
click to toggle source
# File lib/utopia/content/node.rb, line 74 def parent_path @uri_path.dirname end
process!(request, attributes = {})
click to toggle source
# File lib/utopia/content/node.rb, line 125 def process!(request, attributes = {}) Document.render(self, request, attributes).to_a end
relative_path(path = '.')
click to toggle source
# File lib/utopia/content/node.rb, line 67 def relative_path(path = '.') path = Path[path] base = uri_path.dirname return base + path end
sibling_links(**options)
click to toggle source
# File lib/utopia/content/node.rb, line 102 def sibling_links(**options) return @controller.links(siblings_path, **options) end
siblings_path()
click to toggle source
# File lib/utopia/content/node.rb, line 94 def siblings_path if @uri_path.basename == INDEX @uri_path.dirname(2) else @uri_path.dirname end end