Class: Post
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Post
- Defined in:
- app/models/post.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#body_html ⇒ Object
so that page comments can be rendered from a radius tag.
- #comment? ⇒ Boolean
- #date_html ⇒ Object
- #dom_id ⇒ Object
- #editable_by?(reader = nil) ⇒ Boolean
- #editable_interval ⇒ Object
- #first? ⇒ Boolean
- #forum ⇒ Object
- #has_replies? ⇒ Boolean
- #holder ⇒ Object
- #locked? ⇒ Boolean
- #notify_holder_of_creation ⇒ Object
- #notify_holder_of_destruction ⇒ Object
- #page_when_paginated ⇒ Object
- #reply? ⇒ Boolean
- #save_attachments(files = nil) ⇒ Object
- #still_editable? ⇒ Boolean
- #still_editable_for ⇒ Object
- #title ⇒ Object
- #visible_to?(reader = nil) ⇒ Boolean
Class Method Details
.in_forum(forum) ⇒ Object
55 56 57 |
# File 'app/models/post.rb', line 55 def self.in_forum(forum) in_topics(forum.topics) end |
Instance Method Details
#body_html ⇒ Object
so that page comments can be rendered from a radius tag
129 130 131 132 133 134 135 136 |
# File 'app/models/post.rb', line 129 def body_html if body html = RedCloth.new(body, [ :hard_breaks, :filter_html ]).to_html(:textile, :smilies) Sanitize.clean(html, Sanitize::Config::RELAXED) else "" end end |
#comment? ⇒ Boolean
67 68 69 |
# File 'app/models/post.rb', line 67 def comment? !!page end |
#date_html ⇒ Object
138 139 140 |
# File 'app/models/post.rb', line 138 def date_html self.created_at.to_s end |
#dom_id ⇒ Object
154 155 156 |
# File 'app/models/post.rb', line 154 def dom_id "post_#{self.id}" end |
#editable_by?(reader = nil) ⇒ Boolean
111 112 113 114 |
# File 'app/models/post.rb', line 111 def editable_by?(reader=nil) return false unless reader still_editable? && reader.id == reader_id end |
#editable_interval ⇒ Object
95 96 97 |
# File 'app/models/post.rb', line 95 def editable_interval Radiant::Config['forum.editable_period'].to_i.minutes if Radiant::Config['forum.editable_period'] end |
#first? ⇒ Boolean
83 84 85 |
# File 'app/models/post.rb', line 83 def first? !holder || holder.new_record? || holder.posts.first == self end |
#forum ⇒ Object
79 80 81 |
# File 'app/models/post.rb', line 79 def forum topic.forum unless comment? end |
#has_replies? ⇒ Boolean
91 92 93 |
# File 'app/models/post.rb', line 91 def has_replies? holder.posts.last != self end |
#holder ⇒ Object
59 60 61 |
# File 'app/models/post.rb', line 59 def holder page || topic end |
#locked? ⇒ Boolean
87 88 89 |
# File 'app/models/post.rb', line 87 def locked? holder && holder.locked? end |
#notify_holder_of_creation ⇒ Object
150 151 152 |
# File 'app/models/post.rb', line 150 def notify_holder_of_creation holder.notice_creation_of(self) end |
#notify_holder_of_destruction ⇒ Object
146 147 148 |
# File 'app/models/post.rb', line 146 def notify_holder_of_destruction holder.notice_destruction_of(self) end |
#page_when_paginated ⇒ Object
75 76 77 |
# File 'app/models/post.rb', line 75 def page_when_paginated holder.page_for(self) end |
#reply? ⇒ Boolean
71 72 73 |
# File 'app/models/post.rb', line 71 def reply? !comment? && !first? end |
#save_attachments(files = nil) ⇒ Object
142 143 144 |
# File 'app/models/post.rb', line 142 def (files=nil) files.collect {|file| self..create(:file => file) unless file.blank? } if files end |
#still_editable? ⇒ Boolean
107 108 109 |
# File 'app/models/post.rb', line 107 def still_editable? !editable_interval || Time.now - self.created_at < editable_interval end |
#still_editable_for ⇒ Object
99 100 101 102 103 104 105 |
# File 'app/models/post.rb', line 99 def still_editable_for if editable_interval && still_editable? self.created_at + editable_interval - Time.now else 0 end end |
#title ⇒ Object
63 64 65 |
# File 'app/models/post.rb', line 63 def title holder.title if holder end |
#visible_to?(reader = nil) ⇒ Boolean
116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/models/post.rb', line 116 def visible_to?(reader=nil) if topic && !topic.visible_to?(reader) false elsif page && !page.visible_to?(reader) false elsif !reader && !Radiant::Config['forum.public?'] false else true end end |