Class: Blog

Inherits:
Object
  • Object
show all
Includes:
BlogLogic::Base, Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/blog.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BlogLogic::Base

included, #make_slug

Instance Attribute Details

#desired_slugObject

Behavior =======================================================================================



22
23
24
# File 'app/models/blog.rb', line 22

def desired_slug
  @desired_slug
end

Instance Method Details

#copy_postsObject

Instance methods ===============================================================================



29
30
31
32
33
34
35
36
# File 'app/models/blog.rb', line 29

def copy_posts
  self.posts.each do |post|
    p = Post2.create :slug => post.slug, :content => post.content, :tags => post.tags, :author => post.author, :published_at => post.published_at, :state => post.state, :publication_date => post.publication_date, :summary => post.summary
    p.title = post.title
    p.save
    self.post2s << p
  end
end

#feed_addressObject



38
39
40
# File 'app/models/blog.rb', line 38

def feed_address
  "/#{self.slug}/feed.rss"
end

#humanize_pathObject



42
43
44
# File 'app/models/blog.rb', line 42

def humanize_path
  self.path
end

#pathObject



46
47
48
# File 'app/models/blog.rb', line 46

def path
  "/#{self.slug}/".gsub(/\/\//,'/').gsub(/\/\//,'/')
end

#posts_by_monthObject



50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/blog.rb', line 50

def posts_by_month
  dates = {}
  self.posts.published.each do |p|
    date = p.publication_date.to_s(:year_month)
    dates[date] ||= {}
    dates[date][:full_date] ||= p.publication_date.to_s(:month_year)
    dates[date][:posts] ||= []
    dates[date][:posts] << p
  end
  dates
end

#search(keyword) ⇒ Object



62
63
64
# File 'app/models/blog.rb', line 62

def search(keyword)
  self.posts.published.where(:content => /#{keyword}/i)
end