Class: Content

Inherits:
ApplicationRecord
  • Object
show all
Includes:
ContentBase
Defined in:
app/models/content.rb

Direct Known Subclasses

Article, Note, Page

Instance Attribute Summary

Attributes included from ContentBase

#just_changed_published_status

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ContentBase

#default_text_filter, #excerpt_text, #generate_html, #html, #html_map, #html_postprocess, #html_preprocess, included, #really_send_notifications, #send_notification_to_user

Class Method Details

.find_already_published(limit) ⇒ Object

TODO: Inline this method



85
86
87
# File 'app/models/content.rb', line 85

def self.find_already_published(limit)
  published.limit(limit)
end

.search_with(params) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/models/content.rb', line 89

def self.search_with(params)
  params ||= {}
  scoped = unscoped
  scoped = scoped.searchstring(params[:searchstring]) if params[:searchstring].present?

  scoped = scoped.published_at_like(params[:published_at]) if params[:published_at].present? && /(\d\d\d\d)-(\d\d)/ =~ params[:published_at]

  scoped = scoped.user_id(params[:user_id]) if params[:user_id].present? && params[:user_id].to_i > 0

  if params[:published].present?
    scoped = scoped.published if params[:published].to_s == '1'
    scoped = scoped.not_published if params[:published].to_s == '0'
  end

  scoped
end

Instance Method Details

#author=(user) ⇒ Object



35
36
37
38
39
40
41
42
# File 'app/models/content.rb', line 35

def author=(user)
  if user.respond_to?(:login)
    self[:author] = user.
    self.user = user
  elsif user.is_a?(String)
    self[:author] = user
  end
end

#author_nameObject



44
45
46
47
48
49
50
# File 'app/models/content.rb', line 44

def author_name
  if user.present? && user.name.present?
    user.name
  else
    author
  end
end

#rss_descriptionObject



110
111
112
113
114
115
116
117
118
119
# File 'app/models/content.rb', line 110

def rss_description
  return '' unless blog.rss_description

  rss_desc = blog.rss_description_text
  rss_desc.gsub!('%author%', author_name)
  rss_desc.gsub!('%blog_url%', blog.base_url)
  rss_desc.gsub!('%blog_name%', blog.blog_name)
  rss_desc.gsub!('%permalink_url%', permalink_url)
  rss_desc
end

#short_urlObject



121
122
123
# File 'app/models/content.rb', line 121

def short_url
  redirect.from_url if redirect.present?
end

#shorten_urlObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/models/content.rb', line 69

def shorten_url
  return unless published?

  if redirect.present?
    return if redirect.to_path == permalink_url
    redirect.to_path = permalink_url
    redirect.save
  else
    r = Redirect.new(blog: blog)
    r.from_path = r.shorten
    r.to_path = permalink_url
    self.redirect = r
  end
end

#text_filter=(filter) ⇒ Object

Set the text filter for this object. NOTE: Due to how Rails injects association methods, this cannot be put in ContentBase TODO: Allowing assignment of a string here is not very clean.



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/models/content.rb', line 55

def text_filter=(filter)
  filter_object = case filter
                  when TextFilter
                    filter
                  else
                    TextFilter.find_or_default(filter)
                  end
  self.text_filter_id = if filter_object
                          filter_object.id
                        else
                          filter.to_i
                        end
end

#whiteboardObject



106
107
108
# File 'app/models/content.rb', line 106

def whiteboard
  self[:whiteboard] ||= {}
end