discourse/app/serializers/post_excerpt_serializer.rb

38 lines
690 B
Ruby
Raw Normal View History

2013-02-06 03:16:51 +08:00
require_dependency 'excerpt_type'
class PostExcerptSerializer < ActiveModel::Serializer
include ExcerptType
attributes :topic_id, :muted, :excerpt, :username, :created_at, :has_multiple_posts, :last_post_url, :first_post_url, :avatar_template
def muted
object.topic.muted?(scope.current_user)
end
def avatar_template
object.user.avatar_template
end
def has_multiple_posts
(object.topic.posts_count > 1)
end
def last_post_url
object.topic.last_post_url
end
def first_post_url
object.topic.relative_url
end
def include_last_post_url?
object.post_number == 1
end
def include_first_post_url?
object.post_number > 1
end
end