Class: Kiosk::WordPress::Post

Inherits:
Resource
  • Object
show all
Includes:
ContentTeaser
Defined in:
lib/kiosk/word_press/post.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ContentTeaser

#teaser

Methods inherited from Resource

collection_path, #content, #content_document, #destroy, element_path, element_path_by_slug, #excerpt, find, find_by_associated, find_by_slug, instantiate_collection, instantiate_record, #raw_content, #raw_excerpt, #save, #to_param, with_parameters

Methods included from Cacheable::Resource

#expire

Class Method Details

.allObject



26
27
28
# File 'lib/kiosk/word_press/post.rb', line 26

def all
  Category.all.inject([]) { |posts,cat| posts += categorized_as(cat) }.uniq { |p| p.id }
end

.categorized_as(category, params = {}) ⇒ Object

Fetches posts for the given category.



32
33
34
35
36
37
# File 'lib/kiosk/word_press/post.rb', line 32

def categorized_as(category, params = {})
  category = Kiosk::WordPress::Category.find_by_slug(category) if category.is_a?(String)
  find_by_associated(category, {:count => 100000}.merge(params))
rescue ResourceNotFound
  []
end

.created_on(date) ⇒ Object

Fetches posts that were created on the given date.



41
42
43
# File 'lib/kiosk/word_press/post.rb', line 41

def created_on(date)
  find(:all, :method => :get_date_posts, :params => [:date => date])
end

.recentObject

Fetches recently made posts.



47
48
49
# File 'lib/kiosk/word_press/post.rb', line 47

def recent
  find(:all, :method => :get_recent_posts)
end

.tagged_with(tag) ⇒ Object

Fetches posts with the given tag.



53
54
55
# File 'lib/kiosk/word_press/post.rb', line 53

def tagged_with(tag)
  find_by_associated(tag)
end

Instance Method Details

#categoriesObject

Returns the post categories.



64
65
66
# File 'lib/kiosk/word_press/post.rb', line 64

def categories
  attributes[:categories] || []
end

#categoryObject

Returns the first category of the post.



70
71
72
# File 'lib/kiosk/word_press/post.rb', line 70

def category
  categories.first
end

#created_atObject

The time at which this post was authored.



76
77
78
# File 'lib/kiosk/word_press/post.rb', line 76

def created_at
  attributes[:date].to_time
end

#modified_atObject

The time at which this post was modified.



82
83
84
# File 'lib/kiosk/word_press/post.rb', line 82

def modified_at
  attributes[:modified].to_time
end