class Staticpress::Content::Category
Attributes
name[R]
Public Class Methods
all()
click to toggle source
# File lib/staticpress/content/category.rb, line 43 def self.all reply = [] content_by_category.each do |category, posts| 1.upto paginate(posts).count do |number| reply << new(:name => category, :number => number) end end reply end
categories()
click to toggle source
# File lib/staticpress/content/category.rb, line 59 def self.categories content_by_category.keys end
content_by_category()
click to toggle source
# File lib/staticpress/content/category.rb, line 63 def self.content_by_category reply = Hash.new { |hash, key| hash[key] = [] } Staticpress::Content::Post.published.each do |post| (post.meta.categories || []).each do |category| (reply[category] ||= []) << post end end reply end
new(params)
click to toggle source
Calls superclass method
Staticpress::Content::Base::new
# File lib/staticpress/content/category.rb, line 8 def initialize(params) @name = params[:name] super end
published()
click to toggle source
# File lib/staticpress/content/category.rb, line 55 def self.published all end
Public Instance Methods
optional_param_defaults()
click to toggle source
# File lib/staticpress/content/category.rb, line 13 def optional_param_defaults { :number => pages_count } end
pages_count()
click to toggle source
# File lib/staticpress/content/category.rb, line 17 def pages_count (self.class.content_by_category[name].count / config.posts_per_page.to_f).ceil end
preferred_layout_names()
click to toggle source
# File lib/staticpress/content/category.rb, line 25 def preferred_layout_names reply = [] if params[:name].nil? reply << :category else if params[:number].nil? reply << :category_index reply << :post_index end reply << :category_paged reply << :post_paged end reply end
sub_content()
click to toggle source
# File lib/staticpress/content/category.rb, line 21 def sub_content paginate(self.class.content_by_category[params[:name]].sort)[params[:number] - 1] end