Class: OrangeBlogPost

Inherits:
Orange::Carton show all
Defined in:
lib/orange-more/blog/cartons/blog_post.rb

Constant Summary

Constants inherited from Orange::Carton

Orange::Carton::SCAFFOLD_OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Orange::Carton

add_scaffold, admin, admin_property, as_resource, asset, boolean, date, datetime, expose, form_props, front, front_property, fulltext, id, init, orange, orange_property, scaffold_property, string, text, time, title, #to_s

Methods included from ClassInheritableAttributes

#cattr_accessor, #cattr_reader, #cattr_writer, eval_in_accessor_module, fetch_value, store_value

Class Method Details

.draftObject



57
58
59
# File 'lib/orange-more/blog/cartons/blog_post.rb', line 57

def self.draft
  all(:published => false)
end

.publishedObject



53
54
55
# File 'lib/orange-more/blog/cartons/blog_post.rb', line 53

def self.published
  all(:published => true)
end

.slug(slug) ⇒ Object



49
50
51
# File 'lib/orange-more/blog/cartons/blog_post.rb', line 49

def self.slug(slug)
  first(:slug => slug)
end

.year_and_month(yr, mnth) ⇒ Object



45
46
47
# File 'lib/orange-more/blog/cartons/blog_post.rb', line 45

def self.year_and_month(yr, mnth)
  all(:published_at.gte => DateTime.new(yr, mnth, 1), :published_at.lt => DateTime.new(yr, mnth + 1, 1))
end

Instance Method Details

#publishObject



35
36
37
38
# File 'lib/orange-more/blog/cartons/blog_post.rb', line 35

def publish
  self.published_at = Time.now if self.published_at.blank?
  self.attribute_set('published', true)
end

#publish!Object



40
41
42
43
# File 'lib/orange-more/blog/cartons/blog_post.rb', line 40

def publish!
  self.publish
  self.save
end

#published=(val) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/orange-more/blog/cartons/blog_post.rb', line 27

def published=(val)
  if val == '1' || val === true
    self.publish
  else
    self.attribute_set('published', false)
  end
end

#title=(t) ⇒ Object



22
23
24
25
# File 'lib/orange-more/blog/cartons/blog_post.rb', line 22

def title=(t)
  self.attribute_set('title', t)
  self.attribute_set('slug', t.downcase.gsub(/[']+/, "").gsub(/[^a-z0-9]+/, "_"))
end