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.
30 31 32 33 34 35 36 |
# File 'lib/utopia/content/node.rb', line 30 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.
40 41 42 |
# File 'lib/utopia/content/node.rb', line 40 def file_path @file_path end |
#request_path ⇒ Object (readonly)
Returns the value of attribute request_path.
38 39 40 |
# File 'lib/utopia/content/node.rb', line 38 def request_path @request_path end |
#uri_path ⇒ Object (readonly)
Returns the value of attribute uri_path.
39 40 41 |
# File 'lib/utopia/content/node.rb', line 39 def uri_path @uri_path end |
Instance Method Details
#call(transaction, state) ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/utopia/content/node.rb', line 109 def call(transaction, state) template = @controller.fetch_template(@file_path) context = Context.new(transaction, state) markup = template.to_buffer(context) transaction.parse_markup(markup) end |
#link ⇒ Object
42 43 44 |
# File 'lib/utopia/content/node.rb', line 42 def link return Link.new(:file, uri_path) end |
#links(path = '.', **options, &block) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/utopia/content/node.rb', line 78 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
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/utopia/content/node.rb', line 50 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
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/utopia/content/node.rb', line 63 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
46 47 48 |
# File 'lib/utopia/content/node.rb', line 46 def lookup_node(path) @controller.lookup_node(path) end |
#parent_path ⇒ Object
74 75 76 |
# File 'lib/utopia/content/node.rb', line 74 def parent_path uri_path.dirname end |
#process!(request, response, attributes = {}) ⇒ Object
118 119 120 121 122 |
# File 'lib/utopia/content/node.rb', line 118 def process!(request, response, attributes = {}) transaction = Transaction.new(request, response) output = transaction.render_node(self, attributes) response.write(output) end |
#related_links ⇒ Object
89 90 91 92 93 |
# File 'lib/utopia/content/node.rb', line 89 def name = @uri_path.last.split('.', 2).first return Links.index(@controller.root, uri_path.dirname, :name => name, :indices => true) end |
#sibling_links(**options) ⇒ Object
105 106 107 |
# File 'lib/utopia/content/node.rb', line 105 def sibling_links(**) return Links.index(@controller.root, siblings_path, ) end |
#siblings_path ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/utopia/content/node.rb', line 95 def siblings_path name = @uri_path.last.split('.', 2).first if name == INDEX @uri_path.dirname(2) else @uri_path.dirname end end |