Class: Humpyard::Pages::NewsPage

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/humpyard/pages/news_page.rb

Overview

Humpyard::Pages::NewsPage is a page containing news articles

Instance Method Summary collapse

Instance Method Details

#child_pagesObject



35
36
37
# File 'app/models/humpyard/pages/news_page.rb', line 35

def child_pages
  []
end

#is_humpyard_dynamic_page?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'app/models/humpyard/pages/news_page.rb', line 11

def is_humpyard_dynamic_page?
  true
end

#last_modified_with_news_itemsObject

Return the logical modification time for the page, suitable for http caching, generational cache keys, etc.



64
65
66
67
# File 'app/models/humpyard/pages/news_page.rb', line 64

def last_modified_with_news_items
  timestamps = [last_modified_without_news_items] + news_items.collect{|i| i.updated_at}
  timestamps.sort.last
end

#parent_pageObject



39
40
41
# File 'app/models/humpyard/pages/news_page.rb', line 39

def parent_page
  super
end

#parse_path(path) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/humpyard/pages/news_page.rb', line 15

def parse_path(path)
  return nil if path.size != 4
  begin
    item_created_on = Time.local(path[0], path[1], path[2]).to_date
  rescue
    # Rescue if no valid date was given in first 3 path parts
    return nil
  end
  
  item = news_items.find_by_title_for_url(path[3])
  return nil if item.nil?
  
  return nil if item.created_at.to_date != item_created_on
  
  return {
    :partial => 'detail',
    :locals => {:item => item}
    }
end

#site_map(locale) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/humpyard/pages/news_page.rb', line 43

def site_map(locale)
  if page.in_sitemap        
    {
      :url => page.human_url(:locale => locale),
      :lastmod => page.last_modified,
      :hidden => !page.in_sitemap,
      :children => news_items.map do |i|
        { 
          :url => i.human_url(:locale => locale),
          :lastmod => i.updated_at,
          :hidden => !page.in_sitemap,
          :children => []
        }
      end
    }  
  else
    nil
  end
end