Class: Admin::Post

Inherits:
Post
  • Object
show all
Defined in:
lib/ecrire/app/models/admin/post.rb

Instance Attribute Summary

Attributes inherited from Post

#tags

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Post

#content, #draft?, #excerpt, #header?, #month, #published?, #slug, #status=, #title, #title=, #year

Class Method Details

.search(params = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ecrire/app/models/admin/post.rb', line 9

def self.search(params = {})
  rel = self

  if params.has_key?(:tag) && !params[:tag].blank?
    rel = rel.where('? = ANY(posts.tags)', params[:tag])
  end

  if params.has_key?(:title) && !params[:title].blank?
    titles = Admin::Title.search_by_name(params[:title])
    rel = rel.where('id in (?)', titles.pluck(:post_id).uniq.compact)
  end

  if params.has_key?(:status)
    rel = rel.status(params[:status])
  end

  rel
end

Instance Method Details

#content=(content) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ecrire/app/models/admin/post.rb', line 48

def content=(content)
  content_will_change!
  if content.is_a?(String)
    self.content.html = self.content.raw = content
  elsif content.kind_of?(Hash)
    content = content.with_indifferent_access
    self.content.html = content['html']
    self.content.raw = content['raw']
    write_attribute('content', {'raw' => self.content.raw, 'html' => self.content.html})
  end
end

#javascriptObject



44
45
46
# File 'lib/ecrire/app/models/admin/post.rb', line 44

def javascript
  super || ""
end

#publish!(params = {}) ⇒ Object



28
29
30
31
32
# File 'lib/ecrire/app/models/admin/post.rb', line 28

def publish!(params = {})
  self.assign_attributes(params)
  self.published_at = DateTime.now
  self.save!
end

#statusObject



60
61
62
# File 'lib/ecrire/app/models/admin/post.rb', line 60

def status
  published? ? 'published' : 'draft'
end

#stylesheetObject



40
41
42
# File 'lib/ecrire/app/models/admin/post.rb', line 40

def stylesheet
  super || ""
end

#unpublish!(params = {}) ⇒ Object



34
35
36
37
38
# File 'lib/ecrire/app/models/admin/post.rb', line 34

def unpublish!(params = {})
  self.assign_attributes(params)
  self.published_at = nil
  self.save!
end