retrospring/app/helpers/social_helper/tumblr_methods.rb
Georg Gadinger 66efa5d4f4 clean up routes
- replace `match` with `get`/`post`/`patch`/`delete`
- format routes.rb
- rename the `show_user_{profile,question,answer}` routes to
  `profile`, `question`, `answer` so `url_for` (used by Rails Admin)
  works fine for these things
- also add `to_param` to the `User` model so that `url_for(some_user)`
  uses the user name
2022-07-23 12:14:06 +02:00

35 lines
1.1 KiB
Ruby

require 'cgi'
module SocialHelper::TumblrMethods
def tumblr_title(answer)
asker = if answer.question.author_is_anonymous?
answer.user.profile.anon_display_name.presence || APP_CONFIG["anonymous_name"]
else
answer.question.user.profile.safe_name
end
"#{asker} asked: #{answer.question.content}"
end
def tumblr_body(answer)
answer_url = answer_url(
id: answer.id,
username: answer.user.screen_name,
host: APP_CONFIG['hostname'],
protocol: (APP_CONFIG['https'] ? :https : :http)
)
"#{answer.content}\n\n[Smile or comment on the answer here](#{answer_url})"
end
def tumblr_share_url(answer)
answer_url = answer_url(
id: answer.id,
username: answer.user.screen_name,
host: APP_CONFIG['hostname'],
protocol: (APP_CONFIG['https'] ? :https : :http)
)
"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
end