Class: PagesCms::Article

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
MarkdownRenderer
Defined in:
app/models/pages_cms/article.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MarkdownRenderer

#markdown

Class Method Details

.publishedObject



52
53
54
# File 'app/models/pages_cms/article.rb', line 52

def self.published
  self.where('archived != true AND draft != true')
end

Instance Method Details

#article_statusObject



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

def article_status
  if self.draft && !self.archived
    'Draft'
  elsif self.archived && !self.draft
    'Archived'
  elsif !self.draft && !self.archived
    'Published'
  elsif self.draft && self.archived
    'Archived'
  end
end

#content?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/models/pages_cms/article.rb', line 19

def content?
  content.present?
end

#content_eitherObject



27
28
29
30
31
32
33
34
35
# File 'app/models/pages_cms/article.rb', line 27

def content_either
  if content_md?
    self.content_md_rendered
  elsif content?
    self.content
  else
    'Article not saved properly.'
  end
end

#content_md=(value) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'app/models/pages_cms/article.rb', line 37

def content_md=(value)
  old = value
  if value.nil?
    new = value
  else
    new = markdown(value)
  end
  self[:content_md_rendered] = new
  self[:content_md] = old
end

#content_md?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'app/models/pages_cms/article.rb', line 23

def content_md?
  content_md.present?
end

#tags=(val) ⇒ Object



48
49
50
# File 'app/models/pages_cms/article.rb', line 48

def tags=(val)
  write_attribute(:tags, val.strip.gsub(/\s+/, '_').split(',') )
end

#to_paramObject



5
6
7
# File 'app/models/pages_cms/article.rb', line 5

def to_param
  "#{id}-#{title.parameterize}"
end

#xor(a, b) ⇒ Object



82
83
84
# File 'app/models/pages_cms/article.rb', line 82

def xor(a,b)
  (a || b) && !(a && b)
end