discourse/app/serializers/permalink_serializer.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
991 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2015-07-15 20:54:28 +08:00
class PermalinkSerializer < ApplicationSerializer
attributes :id,
:url,
:topic_id,
:topic_title,
:topic_url,
:post_id,
:post_url,
:post_number,
:post_topic_title,
2020-05-25 17:48:54 +08:00
:category_id,
:category_name,
:category_url,
:external_url,
:tag_id,
:tag_name,
:tag_url
def topic_title
object&.topic&.title
end
def topic_url
object&.topic&.url
end
def post_url
# use `full_url` to support subfolder setups
object&.post&.full_url
end
2015-07-20 20:10:22 +08:00
def post_number
object&.post&.post_number
2015-07-20 20:10:22 +08:00
end
def post_topic_title
object&.post&.topic&.title
2015-07-20 20:10:22 +08:00
end
def category_name
object&.category&.name
end
def category_url
object&.category&.url
end
2020-05-25 17:48:54 +08:00
def tag_name
object&.tag&.name
end
def tag_url
object&.tag&.full_url
end
2015-07-15 20:54:28 +08:00
end