Class: Utopia::Content::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/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.



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



108
109
110
111
112
# File 'lib/utopia/content/node.rb', line 108

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


42
43
44
# File 'lib/utopia/content/node.rb', line 42

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


78
79
80
81
82
83
84
85
86
87
# File 'lib/utopia/content/node.rb', line 78

def links(path = '.', **options, &block)
  path = uri_path.dirname + Path[path]
  links = Links.index(@controller.root, path, options)
  
  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_pathObject



74
75
76
# File 'lib/utopia/content/node.rb', line 74

def parent_path
  uri_path.dirname
end

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



114
115
116
117
# File 'lib/utopia/content/node.rb', line 114

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


89
90
91
92
# File 'lib/utopia/content/node.rb', line 89

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


104
105
106
# File 'lib/utopia/content/node.rb', line 104

def sibling_links(**options)
  return Links.index(@controller.root, siblings_path, options)
end

#siblings_pathObject



94
95
96
97
98
99
100
101
102
# File 'lib/utopia/content/node.rb', line 94

def siblings_path
  name = @uri_path.last.split('.', 2).first
  
  if name == INDEX
    @uri_path.dirname(2)
  else
    @uri_path.dirname
  end
end