Class: Post

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/post.rb

Constant Summary collapse

@@per_page =
Spree::Config[:cms_posts_per_page]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_all_tagged_with(tag_or_tags, conditions = []) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'app/models/post.rb', line 26

def self.find_all_tagged_with(tag_or_tags, conditions=[])
  return [] if tag_or_tags.nil? || tag_or_tags.empty?
  case tag_or_tags
  when Array, IsTaggable::TagList
    includes('tags', 'taggings').where(conditions).select { |record| tag_or_tags.all? { |tag| record.tags.map(&:name).include?(tag) } } || []
  else
    includes('tags', 'taggings').where(conditions).select { |record| record.tags.map(&:name).include?(tag_or_tags)  } || []
  end
end

Instance Method Details

#format_markupObject



41
42
43
44
45
# File 'app/models/post.rb', line 41

def format_markup
  if not self.body_raw.nil?
    self.body = RedCloth.new(self.body_raw,[:sanitize_html, :filter_html]).to_html
  end
end

#monthObject



64
65
66
# File 'app/models/post.rb', line 64

def month
  published_at.strftime('%B %Y')
end

#publishedObject

def link

ensure_slash_prefix permalink

end



51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/post.rb', line 51

def published
  #self.published_at ||= Time.now unless self.is_active == 0
  if self.is_active == 0
    if !self.published_at.blank?
        self.published_at = nil
    end
  else
    if self.published_at.blank?
        self.published_at = Time.now
    end
  end
end

#to_paramObject



36
37
38
39
# File 'app/models/post.rb', line 36

def to_param
  return permalink unless permalink.blank?
  title.to_url
end