2023-10-18 14:26:10 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "cgi"
|
2021-12-26 13:04:46 -08:00
|
|
|
|
|
|
|
module SocialHelper::TumblrMethods
|
|
|
|
def tumblr_title(answer)
|
|
|
|
asker = if answer.question.author_is_anonymous?
|
2022-06-21 07:27:07 -07:00
|
|
|
answer.user.profile.anon_display_name.presence || APP_CONFIG["anonymous_name"]
|
2022-06-21 05:52:23 -07:00
|
|
|
else
|
|
|
|
answer.question.user.profile.safe_name
|
|
|
|
end
|
2021-12-26 13:04:46 -08:00
|
|
|
|
|
|
|
"#{asker} asked: #{answer.question.content}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def tumblr_body(answer)
|
2022-07-23 03:06:05 -07:00
|
|
|
answer_url = answer_url(
|
2023-10-18 14:26:10 -07:00
|
|
|
id: answer.id,
|
|
|
|
username: answer.user.screen_name,
|
|
|
|
host: APP_CONFIG["hostname"],
|
|
|
|
protocol: (APP_CONFIG["https"] ? :https : :http),
|
2021-12-26 13:04:46 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
"#{answer.content}\n\n[Smile or comment on the answer here](#{answer_url})"
|
|
|
|
end
|
|
|
|
|
|
|
|
def tumblr_share_url(answer)
|
2022-07-23 03:06:05 -07:00
|
|
|
answer_url = answer_url(
|
2023-10-18 14:26:10 -07:00
|
|
|
id: answer.id,
|
2021-12-26 13:04:46 -08:00
|
|
|
username: answer.user.screen_name,
|
2023-10-18 14:26:10 -07:00
|
|
|
host: APP_CONFIG["hostname"],
|
|
|
|
protocol: (APP_CONFIG["https"] ? :https : :http),
|
2021-12-26 13:04:46 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
"https://www.tumblr.com/widgets/share/tool?shareSource=legacy&posttype=text&title=#{CGI.escape(tumblr_title(answer))}&url=#{CGI.escape(answer_url)}&caption=&content=#{CGI.escape(tumblr_body(answer))}"
|
|
|
|
end
|
2022-07-23 03:06:05 -07:00
|
|
|
end
|