summaryrefslogtreecommitdiff
path: root/app/models/node.rb
diff options
context:
space:
mode:
authorhukl <hukl@eight.local>2009-01-31 23:14:54 +0100
committerhukl <hukl@eight.local>2009-01-31 23:14:54 +0100
commit5ccb76770646d8eb13ea379f5042670a8376d21e (patch)
tree0efb195af04acf4b8bb7ce9de9f7978661bd552d /app/models/node.rb
parent8de27a58b5c401ecb324014bf9827b28f30d6044 (diff)
added everything needed to render a page
Diffstat (limited to 'app/models/node.rb')
-rw-r--r--app/models/node.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/app/models/node.rb b/app/models/node.rb
index 6e54004..5acf563 100644
--- a/app/models/node.rb
+++ b/app/models/node.rb
@@ -3,6 +3,27 @@ class Node < ActiveRecord::Base
3 3
4 has_many :pages, :order => "revision ASC" 4 has_many :pages, :order => "revision ASC"
5 5
6 # Class methods
7
8 def self.find_page path, revision = :current
9
10 node = Node.find_by_unique_name(path)
11
12 if node
13
14 case revision
15 when :current
16 return node.pages.last
17 when /\d+/
18 return node.pages.find_by_revision revision
19 end
20 end
21
22 nil
23 end
24
25 # Instance Methods
26
6 # returns array with pages up to root excluding root 27 # returns array with pages up to root excluding root
7 def path_to_root 28 def path_to_root
8 parent.nil? && [slug] || parent.path_to_root.push(slug) 29 parent.nil? && [slug] || parent.path_to_root.push(slug)