Class: Post2
- Inherits:
-
Object
- Object
- Post2
- Includes:
- LuckySneaks::StringExtensions, Mongoid::Document, Mongoid::Timestamps, Tanker
- Defined in:
- app/models/post2.rb
Constant Summary collapse
- STATES =
Constants ======================================================================================
['draft', 'published']
Instance Method Summary collapse
-
#draft? ⇒ Boolean
Instance methods ===============================================================================.
- #full_path ⇒ Object
- #humanize_path ⇒ Object
- #my_index ⇒ Object
- #next_post ⇒ Object
- #path ⇒ Object
- #previous_post ⇒ Object
- #publish! ⇒ Object
- #published? ⇒ Boolean
- #search_description ⇒ Object
- #search_title ⇒ Object
-
#set_slug ⇒ Object
Sets the slug for this locale.
- #state=(arg) ⇒ Object
- #status ⇒ Object
- #unpublish! ⇒ Object
Instance Method Details
#draft? ⇒ Boolean
Instance methods ===============================================================================
63 64 65 |
# File 'app/models/post2.rb', line 63 def draft? self.state == 'draft' || self.state.nil? end |
#full_path ⇒ Object
67 68 69 |
# File 'app/models/post2.rb', line 67 def full_path self.path end |
#humanize_path ⇒ Object
71 72 73 |
# File 'app/models/post2.rb', line 71 def humanize_path "/#{self.slug}".gsub('//', '/') end |
#my_index ⇒ Object
75 76 77 |
# File 'app/models/post2.rb', line 75 def my_index self.blog.posts.index(self) end |
#next_post ⇒ Object
79 80 81 82 83 |
# File 'app/models/post2.rb', line 79 def next_post i = self.my_index + 1 i = 0 if i > (self.blog.posts.size - 1) self.blog.posts[i] end |
#path ⇒ Object
85 86 87 |
# File 'app/models/post2.rb', line 85 def path "#{self.blog.humanize_path}#{self.humanize_path}".gsub('//', '/') end |
#previous_post ⇒ Object
89 90 91 92 93 |
# File 'app/models/post2.rb', line 89 def previous_post i = self.my_index - 1 i = self.blog.posts.size - 1 if i < 0 self.blog.posts[i] end |
#publish! ⇒ Object
95 96 97 |
# File 'app/models/post2.rb', line 95 def publish! self.update_attributes :state => 'published', :published_at => Time.zone.now end |
#published? ⇒ Boolean
99 100 101 |
# File 'app/models/post2.rb', line 99 def published? self.state == 'published' end |
#search_description ⇒ Object
103 104 105 |
# File 'app/models/post2.rb', line 103 def search_description self.summary.gsub(/<\/?[^>]*>/, '')[0..199].html_safe end |
#search_title ⇒ Object
107 108 109 |
# File 'app/models/post2.rb', line 107 def search_title self.title end |
#set_slug ⇒ Object
Sets the slug for this locale. Slugs from the locale tree are used to build this locale’s URL.
112 113 114 |
# File 'app/models/post2.rb', line 112 def set_slug self.slug = self.title.to_s.to_url end |
#state=(arg) ⇒ Object
120 121 122 |
# File 'app/models/post2.rb', line 120 def state=(arg) self[:state] = arg.downcase end |
#status ⇒ Object
124 125 126 |
# File 'app/models/post2.rb', line 124 def status self.state ? self.state.capitalize : 'Draft' end |
#unpublish! ⇒ Object
116 117 118 |
# File 'app/models/post2.rb', line 116 def unpublish! self.update_attributes :state => 'draft' end |