Class: Post
- Inherits:
-
Object
show all
- Includes:
- BlogLogic::Base, Mongoid::Document, Mongoid::Timestamps, Tanker
- Defined in:
- app/models/post.rb
Defined Under Namespace
Classes: DesiredSlugPresenceAndUniquenessValidator
Constant Summary
collapse
- STATES =
Constants ======================================================================================
['draft', 'published']
Instance Attribute Summary collapse
-
#desired_slug ⇒ Object
Behavior =======================================================================================.
Instance Method Summary
collapse
included, #make_slug
Instance Attribute Details
#desired_slug ⇒ Object
Behavior =======================================================================================
34
35
36
|
# File 'app/models/post.rb', line 34
def desired_slug
@desired_slug
end
|
Instance Method Details
#draft? ⇒ Boolean
Instance methods ===============================================================================
64
65
66
|
# File 'app/models/post.rb', line 64
def draft?
self.state == 'draft' || self.state.nil?
end
|
#full_path ⇒ Object
68
69
70
|
# File 'app/models/post.rb', line 68
def full_path
self.path
end
|
#humanize_path ⇒ Object
72
73
74
|
# File 'app/models/post.rb', line 72
def humanize_path
"/#{self.slug}".gsub('//', '/')
end
|
#my_index ⇒ Object
76
77
78
|
# File 'app/models/post.rb', line 76
def my_index
self.blog.posts.index(self)
end
|
#next_post ⇒ Object
80
81
82
83
84
|
# File 'app/models/post.rb', line 80
def next_post
i = self.my_index + 1
i = 0 if i > (self.blog.posts.size - 1)
self.blog.posts[i]
end
|
#path ⇒ Object
86
87
88
|
# File 'app/models/post.rb', line 86
def path
"#{self.blog.humanize_path}#{self.humanize_path}".gsub('//', '/')
end
|
#previous_post ⇒ Object
90
91
92
93
94
|
# File 'app/models/post.rb', line 90
def previous_post
i = self.my_index - 1
i = self.blog.posts.size - 1 if i < 0
self.blog.posts[i]
end
|
#publish! ⇒ Object
96
97
98
|
# File 'app/models/post.rb', line 96
def publish!
self.update_attributes :state => 'published', :published_at => Time.zone.now
end
|
#published? ⇒ Boolean
100
101
102
|
# File 'app/models/post.rb', line 100
def published?
self.state == 'published'
end
|
#search_description ⇒ Object
104
105
106
|
# File 'app/models/post.rb', line 104
def search_description
self.summary.gsub(/<\/?[^>]*>/, '')[0..199].html_safe
end
|
#search_title ⇒ Object
108
109
110
|
# File 'app/models/post.rb', line 108
def search_title
self.title
end
|
#state=(arg) ⇒ Object
116
117
118
|
# File 'app/models/post.rb', line 116
def state=(arg)
self[:state] = arg.downcase
end
|
#status ⇒ Object
120
121
122
|
# File 'app/models/post.rb', line 120
def status
self.state ? self.state.capitalize : 'Draft'
end
|
#unpublish! ⇒ Object
112
113
114
|
# File 'app/models/post.rb', line 112
def unpublish!
self.update_attributes :state => 'draft'
end
|