Class: Blogr::Post

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/blogr/post.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.tag_countsObject



43
44
45
46
47
# File 'app/models/blogr/post.rb', line 43

def self.tag_counts
  Blogr::Tag.select(
    "#{Blogr::Tag.table_name}.*, COUNT(#{Blogr::Tagging.table_name}.tag_id) AS count"
  ).joins(:taggings).group("#{Blogr::Tagging.table_name}.tag_id")
end

.tagged_with(name) ⇒ Object



39
40
41
# File 'app/models/blogr/post.rb', line 39

def self.tagged_with(name)
  Blogr::Tag.find_by_name!(name).posts
end

Instance Method Details

#content_renderedString

The Markdown content rendered to HTML

Returns:

  • (String)


35
36
37
# File 'app/models/blogr/post.rb', line 35

def content_rendered
  markdown(content).html_safe
end

#date_parsedString

The date parsed as 04 November 2013

Returns:

  • (String)


28
29
30
# File 'app/models/blogr/post.rb', line 28

def date_parsed
  published && published_at.present? ? published_at.strftime("%d %B %Y") : ""
end

#tag_listObject



49
50
51
# File 'app/models/blogr/post.rb', line 49

def tag_list
  tags.map(&:name).join(", ")
end

#tag_list=(names) ⇒ Object



53
54
55
56
57
# File 'app/models/blogr/post.rb', line 53

def tag_list=(names)
  self.tags = names.split(",").map do |n|
    Blogr::Tag.where(name: n.strip).first_or_create!
  end
end

#to_paramObject



20
21
22
# File 'app/models/blogr/post.rb', line 20

def to_param
  permalink
end