public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Search Repo:
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
mephisto / app / drops / section_drop.rb
100644 57 lines (45 sloc) 1.526 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class SectionDrop < BaseDrop
  include Mephisto::Liquid::UrlMethods
  
  liquid_attributes.push(*[:name, :path, :archive_path])
  
  def current() @current == true end
 
  def initialize(source, current = false)
    super source
    @current = current
    @liquid['articles_count'] = @source.send(:read_attribute, :articles_count)
    {:is_blog => :blog?, :is_paged => :paged?, :is_home => :home?}.each { |k, v| @liquid[k.to_s] = @source.send(v) }
  end
  
  def articles
    @articles ||= latest_articles
  end
  
  def comments
    @comments ||= latest_comments
  end
 
  def latest_articles(limit = nil)
    liquify(*@source.articles.find_by_date(:limit => (limit || @source.articles_per_page)))
  end
 
  def latest_comments(limit = nil)
    liquify(*@source.find_comments(:limit => (limit || @source.articles_per_page)))
  end
 
  def pages
    @pages ||= liquify(*@source.articles) { |article, i| article.to_liquid(:page => i.zero?) }
  end
 
  def url
    @url ||= absolute_url(*@source.to_url)
  end
  
  def earliest_month
    @earliest_month ||= @source.articles.find_by_date(:limit => 1, :order => 'published_at').first.published_at.beginning_of_month.to_date rescue :false
  end
  
  def months
    if @months.nil?
      this_month = Time.now.utc.beginning_of_month.to_date
      date = earliest_month.is_a?(Date) && earliest_month
      @months = []
      while date && date <= this_month
        @months << date
        date = date >> 1
      end
      @months.reverse!
    end
    
    @months
  end
end