Module: ContentBase

Included in:
Content, Feedback
Defined in:
app/models/content_base.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#just_changed_published_statusObject 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_filterObject

The default text filter. Generally, this is the filter specified by blog.text_filter, but comments may use a different default.



70
71
72
# File 'app/models/content_base.rb', line 70

def default_text_filter
  blog.text_filter_object
end

#excerpt_text(length = 160) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/content_base.rb', line 51

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
# File 'app/models/content_base.rb', line 35

def generate_html(field, text = nil)
  text ||= self[field].to_s
  html = (text_filter || default_text_filter).filter_text(text) || text
  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 ArgumentError, "Field #{field.inspect} is not valid for #{self.class}"
  end
end

#html_map(field) ⇒ Object



47
48
49
# File 'app/models/content_base.rb', line 47

def html_map(field)
  content_fields.include? field
end

#html_postprocess(_field, html) ⇒ Object

Post-process the HTML



42
43
44
45
# File 'app/models/content_base.rb', line 42

def html_postprocess(_field, html)
  helper = PublifyCore::ContentTextHelpers.new
  helper.sanitize html
end

#really_send_notificationsObject



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_filterObject



64
65
66
# File 'app/models/content_base.rb', line 64

def text_filter
  TextFilter.make_filter(text_filter_name)
end