Module: ContentBase
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#just_changed_published_status ⇒ Object
(also: #just_changed_published_status?)
Returns the value of attribute just_changed_published_status.
Class Method Summary collapse
Instance Method Summary collapse
-
#default_text_filter ⇒ Object
The default text filter.
- #excerpt_text(length = 160) ⇒ Object
-
#generate_html(field, text = nil) ⇒ Object
Generate HTML for a specific field using the text_filter in use for this object.
-
#html(field = :all) ⇒ Object
Return HTML for some part of this object.
- #html_map(field) ⇒ Object
-
#html_postprocess(_field, html) ⇒ Object
Post-process the HTML.
- #html_preprocess(_field, html) ⇒ Object
- #really_send_notifications ⇒ Object
- #send_notification_to_user(user) ⇒ Object
- #text_filter ⇒ Object
Instance Attribute Details
#just_changed_published_status ⇒ Object Also known as: just_changed_published_status?
Returns the value of attribute just_changed_published_status.
8 9 10 |
# File 'app/models/content_base.rb', line 8 def just_changed_published_status @just_changed_published_status end |
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'app/models/content_base.rb', line 4 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#default_text_filter ⇒ Object
The default text filter. Generally, this is the filter specified by blog.text_filter, but comments may use a different default.
75 76 77 |
# File 'app/models/content_base.rb', line 75 def default_text_filter blog.text_filter_object end |
#excerpt_text(length = 160) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/content_base.rb', line 56 def excerpt_text(length = 160) text = if respond_to?(:excerpt) && (excerpt || "") != "" generate_html(:excerpt, excerpt) else html(:all) end text = text.strip_html text.slice(0, length) + (text.length > length ? "..." : "") end |
#generate_html(field, text = nil) ⇒ Object
Generate HTML for a specific field using the text_filter in use for this object.
35 36 37 38 39 40 |
# File 'app/models/content_base.rb', line 35 def generate_html(field, text = nil) text ||= self[field].to_s prehtml = html_preprocess(field, text).to_s html = (text_filter || default_text_filter).filter_text(prehtml) || prehtml html_postprocess(field, html).to_s end |
#html(field = :all) ⇒ Object
Return HTML for some part of this object.
23 24 25 26 27 28 29 30 31 |
# File 'app/models/content_base.rb', line 23 def html(field = :all) if field == :all generate_html(:all, content_fields.map { |f| self[f].to_s }.join("\n\n")) elsif html_map(field) generate_html(field) else raise "Unknown field: #{field.inspect} in content.html" end end |
#html_map(field) ⇒ Object
52 53 54 |
# File 'app/models/content_base.rb', line 52 def html_map(field) content_fields.include? field end |
#html_postprocess(_field, html) ⇒ Object
Post-process the HTML. This is a noop by default, but Comment overrides it to enforce HTML sanity.
44 45 46 |
# File 'app/models/content_base.rb', line 44 def html_postprocess(_field, html) html end |
#html_preprocess(_field, html) ⇒ Object
48 49 50 |
# File 'app/models/content_base.rb', line 48 def html_preprocess(_field, html) html end |
#really_send_notifications ⇒ Object
11 12 13 14 15 16 |
# File 'app/models/content_base.rb', line 11 def really_send_notifications interested_users.each do |value| send_notification_to_user(value) end true end |
#send_notification_to_user(user) ⇒ Object
18 19 20 |
# File 'app/models/content_base.rb', line 18 def send_notification_to_user(user) notify_user_via_email(user) end |
#text_filter ⇒ Object
69 70 71 |
# File 'app/models/content_base.rb', line 69 def text_filter TextFilter.make_filter(text_filter_name) end |