lib/plate/dsl.rb in plate-0.7.1 vs lib/plate/dsl.rb in plate-0.7.2
- old
+ new
@@ -1,5 +1,8 @@
+require 'active_support'
+require 'active_support/core_ext/array'
+
module Plate
# The Dsl class provides the methods available in plugin files in order to extend
# the functionality a generated site.
class Dsl
class << self
@@ -229,9 +232,53 @@
proxy.instance_eval(&block)
page.write!
proxy = nil
page = nil
end
+ end
+ end
+ end
+
+ # Paged archived posts
+ def archive_paged_items(options, &block)
+ filter_category = options[:category] || nil
+ per_page = options[:per_page] || 10
+
+ callback :site, :after_render do |site|
+ posts = []
+ current_page = 1
+
+ site.posts.archives.keys.each do |year|
+ site.posts.archives[year].keys.each do |month|
+ site.posts.archives[year][month].each_value do |day|
+ posts << day.select { |post| filter_category == nil or post.category == filter_category }
+ end
+ end
+ end
+
+ posts.flatten!
+
+ groups = posts.in_groups_of(per_page, false)
+
+ groups.each do |group|
+ page = DynamicPage.new(site, "/page/#{current_page}")
+ proxy = PageProxy.new(page, site)
+ proxy._category = filter_category if filter_category
+
+ proxy.locals = {
+ :current_page => current_page,
+ :previous_page => (current_page > 1 ? (current_page - 1) : nil),
+ :next_page => (current_page < groups.size ? (current_page + 1) : nil),
+ :paged_posts => group,
+ :page => current_page
+ }
+
+ proxy.instance_eval(&block)
+ page.write!
+ proxy = nil
+ page = nil
+
+ current_page = current_page + 1
end
end
end
end
end
\ No newline at end of file