class Staticpress::Content::Tag

Attributes

name[R]

Public Class Methods

all() click to toggle source
# File lib/staticpress/content/tag.rb, line 43
def self.all
  reply = []

  content_by_tag.each do |tag, posts|
    1.upto paginate(posts).count do |number|
      reply << new(:name => tag, :number => number)
    end
  end

  reply
end
content_by_tag() click to toggle source
# File lib/staticpress/content/tag.rb, line 63
def self.content_by_tag
  reply = Hash.new { |hash, key| hash[key] = [] }
  Staticpress::Content::Post.published.each do |post|
    (post.meta.tags || []).each do |tag|
      (reply[tag] ||= []) << post
    end
  end
  reply
end
new(params) click to toggle source
Calls superclass method Staticpress::Content::Base::new
# File lib/staticpress/content/tag.rb, line 8
def initialize(params)
  @name = params[:name]
  super
end
published() click to toggle source
# File lib/staticpress/content/tag.rb, line 55
def self.published
  all
end
tags() click to toggle source
# File lib/staticpress/content/tag.rb, line 59
def self.tags
  content_by_tag.keys
end

Public Instance Methods

optional_param_defaults() click to toggle source
# File lib/staticpress/content/tag.rb, line 13
def optional_param_defaults
  { :number => pages_count }
end
pages_count() click to toggle source
# File lib/staticpress/content/tag.rb, line 17
def pages_count
  (self.class.content_by_tag[name].count / config.posts_per_page.to_f).ceil
end
preferred_layout_names() click to toggle source
# File lib/staticpress/content/tag.rb, line 25
def preferred_layout_names
  reply = []

  if params[:name].nil?
    reply << :tag
  else
    if params[:number].nil?
      reply << :tag_index
      reply << :post_index
    end

    reply << :tag_paged
    reply << :post_paged
  end

  reply
end
sub_content() click to toggle source
# File lib/staticpress/content/tag.rb, line 21
def sub_content
  paginate(self.class.content_by_tag[params[:name]].sort)[params[:number] - 1]
end