Class: BcmsBlog::BlogPost

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/bcms_blog/blog_post.rb

Constant Summary collapse

INCORRECT_PARAMETERS =
"Incorrect parameters. This is probably because you are trying to view the " +
"portlet through the CMS interface, and so we have no way of knowing what " +
"post(s) to show"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.columns_for_indexObject



68
69
70
71
# File 'app/models/bcms_blog/blog_post.rb', line 68

def self.columns_for_index
  [ {:label => "Name", :method => :name, :order => "name" },
    {:label => "Published At", :method => :published_label, :order => "published_at" } ]
end

.default_orderObject



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

def self.default_order
  "created_at desc"
end

Instance Method Details

#after_publish_with_set_published_atObject Also known as: after_publish

This is necessary because, oddly, the publish! method in the Publishing behaviour sends an update query directly to the database, bypassing callbacks, so published_at does not get set by our set_published_at callback.



51
52
53
54
55
56
57
# File 'app/models/bcms_blog/blog_post.rb', line 51

def after_publish_with_set_published_at
  if published_at.nil?
    self.published_at = Time.now
    self.save!
  end
  after_publish_without_set_published_at if respond_to? :after_publish_without_set_published_at
end

#attachmentObject

Return true if this model has an attachment



104
105
106
# File 'app/models/bcms_blog/blog_post.rb', line 104

def attachment
  !file.blank?
end

#dayObject



99
100
101
# File 'app/models/bcms_blog/blog_post.rb', line 99

def day
  published_at.strftime("%d") unless published_at.blank?
end

#monthObject



95
96
97
# File 'app/models/bcms_blog/blog_post.rb', line 95

def month
  published_at.strftime("%m") unless published_at.blank?
end

#pathObject



81
82
83
# File 'app/models/bcms_blog/blog_post.rb', line 81

def path
  send("#{blog.name_for_path}_post_path", route_params)
end

#published_labelObject



73
74
75
# File 'app/models/bcms_blog/blog_post.rb', line 73

def published_label
  published_at ? published_at.to_s(:date) : nil
end

#route_nameObject



84
85
86
# File 'app/models/bcms_blog/blog_post.rb', line 84

def route_name
  "#{blog.name_for_path}_post"
end

#route_paramsObject



87
88
89
# File 'app/models/bcms_blog/blog_post.rb', line 87

def route_params
  {:year => year, :month => month, :day => day, :slug => slug}
end

#set_published_atObject



42
43
44
45
46
# File 'app/models/bcms_blog/blog_post.rb', line 42

def set_published_at
  if !published_at && publish_on_save
    self.published_at = Time.now
  end
end

#set_slugObject



77
78
79
# File 'app/models/bcms_blog/blog_post.rb', line 77

def set_slug
  self.slug = name.to_slug
end

#yearObject



91
92
93
# File 'app/models/bcms_blog/blog_post.rb', line 91

def year
  published_at.strftime("%Y") unless published_at.blank?
end