Class: Awestruct::Extensions::Posts::Archive

Inherits:
Object
  • Object
show all
Defined in:
lib/awestruct/extensions/posts.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeArchive

Returns a new instance of Archive.



90
91
92
# File 'lib/awestruct/extensions/posts.rb', line 90

def initialize
  @posts        = {}
end

Instance Attribute Details

#postsObject

Returns the value of attribute posts.



88
89
90
# File 'lib/awestruct/extensions/posts.rb', line 88

def posts
  @posts
end

Instance Method Details

#<<(post) ⇒ Object



94
95
96
97
98
99
# File 'lib/awestruct/extensions/posts.rb', line 94

def <<( post )
  posts[post.date.year] ||= {}
  posts[post.date.year][post.date.month] ||= {}
  posts[post.date.year][post.date.month][post.date.day] ||= []
  posts[post.date.year][post.date.month][post.date.day] << post
end

#generate_pages(engine, template, output_path) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/awestruct/extensions/posts.rb', line 101

def generate_pages( engine, template, output_path )
  pages = []
  posts.keys.sort.each do |year|
    posts[year].keys.sort.each do |month| 
      posts[year][month].keys.sort.each do |day|
        archive_page = engine.find_and_load_site_page( template )
        archive_page.send( "archive=", posts[year][month][day] )
        archive_page.output_path = File.join( output_path, year.to_s, month.to_s, day.to_s, File.basename( template ) + ".html" )
        pages << archive_page
      end
    end
  end
  pages
end