Module: ArchivePageTreeStructure
- Defined in:
- lib/archive_page_tree_structure.rb
Defined Under Namespace
Classes: ArchiveMonthTreePage, ArchiveTreePage, ArchiveYearTreePage
Instance Method Summary
collapse
Instance Method Details
#edge_date(first) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/archive_page_tree_structure.rb', line 16
def edge_date(first)
if !first && children.find(:first, :conditions => 'updated_at is null')
return Time.now
end
order = first ? 'asc' : 'desc'
child = children.find(:first, :order => "published_at #{order}", :conditions => 'not(published_at is null)')
edge = child.published_at if child
child = children.find(:first, :order => "updated_at #{order}", :conditions => 'published_at is null and not(updated_at is null)')
if child
if first
edge = child.updated_at if !edge || child.updated_at < edge
else
edge = child.updated_at if !edge || child.updated_at > edge
end
end
edge
end
|
#tree_child(slug) ⇒ Object
34
35
36
37
38
|
# File 'lib/archive_page_tree_structure.rb', line 34
def tree_child(slug)
first = [edge_date(true),Time.utc(slug.to_i)].max
last = edge_date(false)
ArchiveYearTreePage.new(self, first, last)
end
|
#tree_children ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/archive_page_tree_structure.rb', line 2
def tree_children
tree_children = []
last = edge_date(false)
if last
first = edge_date(true)
current = first
while(current <= last)
tree_children.unshift ArchiveYearTreePage.new(self, current, last)
current = current.next_year.beginning_of_year
end
end
tree_children end
|