2022-01-15 16:04:47 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-01-10 13:14:58 -08:00
|
|
|
module ApplicationHelper::TitleMethods
|
|
|
|
include MarkdownHelper
|
|
|
|
include UserHelper
|
|
|
|
|
2022-01-16 05:13:01 -08:00
|
|
|
def generate_title(name, junction = nil, content = nil, possessive = false)
|
|
|
|
if possessive
|
2022-01-15 16:04:47 -08:00
|
|
|
name = if name[-1].downcase == "s"
|
|
|
|
"#{name}'"
|
|
|
|
else
|
|
|
|
"#{name}'s"
|
|
|
|
end
|
2022-01-10 13:14:58 -08:00
|
|
|
end
|
|
|
|
|
2022-01-15 16:04:47 -08:00
|
|
|
list = [name, junction].compact
|
2022-01-10 13:14:58 -08:00
|
|
|
|
|
|
|
unless content.nil?
|
|
|
|
content = strip_markdown(content)
|
2022-01-15 16:04:47 -08:00
|
|
|
content = "#{content[0..42]}…" if content.length > 45
|
2022-01-10 13:14:58 -08:00
|
|
|
list.push content
|
|
|
|
end
|
2022-01-15 16:04:47 -08:00
|
|
|
list.push "|", APP_CONFIG["site_name"]
|
2022-01-10 13:14:58 -08:00
|
|
|
|
|
|
|
list.join " "
|
|
|
|
end
|
|
|
|
|
|
|
|
def question_title(question)
|
|
|
|
name = user_screen_name question.user, anonymous: question.author_is_anonymous, url: false
|
|
|
|
generate_title name, "asked", question.content
|
|
|
|
end
|
|
|
|
|
|
|
|
def answer_title(answer)
|
|
|
|
name = user_screen_name answer.user, anonymous: false, url: false
|
|
|
|
generate_title name, "answered", answer.question.content
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_title(user, junction = nil)
|
|
|
|
name = user_screen_name user, anonymous: false, url: false
|
|
|
|
generate_title name, junction, nil, !junction.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
def questions_title(user)
|
|
|
|
user_title user, "questions"
|
|
|
|
end
|
|
|
|
|
|
|
|
def answers_title(user)
|
|
|
|
user_title user, "answers"
|
|
|
|
end
|
|
|
|
|
|
|
|
def smiles_title(user)
|
|
|
|
user_title user, "smiles"
|
|
|
|
end
|
|
|
|
|
|
|
|
def comments_title(user)
|
|
|
|
user_title user, "comments"
|
|
|
|
end
|
|
|
|
|
|
|
|
def list_title(list)
|
|
|
|
generate_title list.name
|
|
|
|
end
|
2022-01-15 16:04:47 -08:00
|
|
|
end
|