Class: Blog

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

Instance Method Summary collapse

Instance Method Details

#copy_postsObject

Migrates this blog’s embedded posts to referenced ones.



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

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.blog_category_ids = post.blog_category_ids
    p.save
    self.post2s << p
  end
end

#feedString

Returns this blog’s RSS feed.

Returns:

  • (String)

    the RSS feed as a URL path



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

def feed
  "#{self.path}/feed.rss"
end

#feed_addressObject

Deprecated.

Please use #feed instead



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

def feed_address
  warn "[DEPRECATION] `feed_address` is deprecated.  Please use `feed` instead."
  self.feed
end

#humanize_pathObject

Deprecated.

Please use #path instead



52
53
54
55
# File 'app/models/blog.rb', line 52

def humanize_path
  warn "[DEPRECATION] `humanize_path` is deprecated.  Please use `path` instead."
  self.path
end

#pathString

Returns this blog’s path.

Returns:

  • (String)

    the path for this blog



60
61
62
# File 'app/models/blog.rb', line 60

def path
  "/#{self.slug}"
end

#path_tsString

Returns this blog’s path with a trailing slash.

Returns:

  • (String)

    the path for this blog



67
68
69
# File 'app/models/blog.rb', line 67

def path_ts
  "#{self.path}/"
end

#posts_by_monthHash

Returns this blog’s posts keyed by publication date.

Returns:

  • (Hash)

    this blog’s posts keyed by publication date



74
75
76
77
78
79
80
81
82
83
84
# File 'app/models/blog.rb', line 74

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) ⇒ Array

Returns published posts matching the specified keyword.

Parameters:

  • the (String)

    keyword to search for

Returns:

  • (Array)

    matching published posts



90
91
92
# File 'app/models/blog.rb', line 90

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