diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 627f3408..d42488e2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -38,9 +38,9 @@ module ApplicationHelper content_tag(:a, body.html_safe, href: path, class: ("list-group-item #{'active ' if current_page? path}#{options[:class]}")) end - + ## - # + # def bootstrap_color c case c when "error", "alert" @@ -93,4 +93,64 @@ module ApplicationHelper return true if user_agent.match /^Mozilla\/\d+\.\d+ \(i(?:Phone|Pad|Pod); CPU(?:.*) like Mac OS X\)(?:.*) Mobile(?:\S*)$/ false end + + def generate_title(name, junction = nil, content = nil, s = false) + if s + if name[-1] != "s" + name = name + "'s" + else + name = name + "'" + end + end + + list = [name] + + list.push junction unless junction.nil? + + unless content.nil? + content = strip_markdown(content) + if content.length > 45 + content = content[0..42] + "..." + end + list.push content + end + list.push "|", APP_CONFIG['site_name'] + + list.join " " + end + + def question_title(question) + name = user_screen_name question.user, question.author_is_anonymous, false + generate_title name, "asked", question.content + end + + def answer_title(answer) + name = user_screen_name answer.user, false, false + generate_title name, "answered", answer.content + end + + def user_title(user, junction = nil) + name = user_screen_name user, false, 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 group_title(group) + generate_title group.name + end end diff --git a/app/views/answer/show.html.haml b/app/views/answer/show.html.haml index 301e8629..9c1b3f1d 100644 --- a/app/views/answer/show.html.haml +++ b/app/views/answer/show.html.haml @@ -1,3 +1,3 @@ -- provide(:title, "#{@answer.user.display_name.blank? ? "@#{@answer.user.screen_name}'s" : "#{@answer.user.display_name}'s"} answer | #{APP_CONFIG['site_name']}") +- provide(:title, answer_title(@answer)) .container.j2-page = render 'shared/answerbox', a: @answer diff --git a/app/views/devise/confirmations/new.html.haml b/app/views/devise/confirmations/new.html.haml index f71e2208..c6a533a1 100644 --- a/app/views/devise/confirmations/new.html.haml +++ b/app/views/devise/confirmations/new.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "Resend confirmation instructions | #{APP_CONFIG['site_name']}") +- provide(:title, generate_title("Resend confirmation instructions")) .container %h1 Resend confirmation instructions = bootstrap_form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| diff --git a/app/views/devise/passwords/edit.html.haml b/app/views/devise/passwords/edit.html.haml index 8ac67b9a..d773a8c1 100644 --- a/app/views/devise/passwords/edit.html.haml +++ b/app/views/devise/passwords/edit.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "Change your password | #{APP_CONFIG['site_name']}") +- provide(:title, generate_title("Reset Password")) .container %h1 Change your password = bootstrap_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| diff --git a/app/views/devise/passwords/new.html.haml b/app/views/devise/passwords/new.html.haml index 5db5f61d..71045f16 100644 --- a/app/views/devise/passwords/new.html.haml +++ b/app/views/devise/passwords/new.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "Forgot your password? | #{APP_CONFIG['site_name']}") +- provide(:title, generate_title("Forgot your Password?")) .container %h1 Forgot your password? = bootstrap_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| diff --git a/app/views/devise/registrations/new.html.haml b/app/views/devise/registrations/new.html.haml index a5c8dc45..3d5792d3 100644 --- a/app/views/devise/registrations/new.html.haml +++ b/app/views/devise/registrations/new.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "Sign up | #{APP_CONFIG['site_name']}") +- provide(:title, generate_title("Sign Up")) .container %h1 Sign up diff --git a/app/views/devise/sessions/new.html.haml b/app/views/devise/sessions/new.html.haml index 26f5893d..e6e4e0d2 100644 --- a/app/views/devise/sessions/new.html.haml +++ b/app/views/devise/sessions/new.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "Sign in | #{APP_CONFIG['site_name']}") +- provide(:title, generate_title("Sign In")) .container %h1 Sign in = render 'layouts/messages' diff --git a/app/views/devise/unlocks/new.html.haml b/app/views/devise/unlocks/new.html.haml index e718da96..f35c61e4 100644 --- a/app/views/devise/unlocks/new.html.haml +++ b/app/views/devise/unlocks/new.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "Unlock | #{APP_CONFIG['site_name']}") +- provide(:title, generate_title("Unlock")) .container %h1 Resend unlock instructions = render 'layouts/messages' diff --git a/app/views/group/index.html.haml b/app/views/group/index.html.haml index e95f8c98..1ce3ecac 100644 --- a/app/views/group/index.html.haml +++ b/app/views/group/index.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "#{@group.display_name} | #{APP_CONFIG['site_name']}") +- provide(:title, group_title(@group)) = render 'static/mobile_nav' .container.j2-page .col-md-3.col-sm-3 diff --git a/app/views/inbox/show.html.haml b/app/views/inbox/show.html.haml index f5acd1b9..c597545b 100644 --- a/app/views/inbox/show.html.haml +++ b/app/views/inbox/show.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "Inbox | #{APP_CONFIG['site_name']}") +- provide(:title, generate_title("Inbox")) .container.j2-page .row .col-md-3.col-xs-12.col-sm-3.hidden-xs diff --git a/app/views/moderation/index.html.haml b/app/views/moderation/index.html.haml index 672983b3..2eba0a2d 100644 --- a/app/views/moderation/index.html.haml +++ b/app/views/moderation/index.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "Moderation | #{APP_CONFIG['site_name']}") +- provide(:title, generate_title("Inbox")) = render 'moderation/moderation_nav' .container.j2-page .row diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index b3d3055c..c22e28cf 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "Notifications | #{APP_CONFIG['site_name']}") +- provide(:title, generate_title("Notifications")) = render 'notifications/notification_nav' .container.j2-page = render 'notification_tabs' diff --git a/app/views/public/index.html.haml b/app/views/public/index.html.haml index 59a86c9d..b0f425e5 100644 --- a/app/views/public/index.html.haml +++ b/app/views/public/index.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "Public Timeline | #{APP_CONFIG['site_name']}") +- provide(:title, generate_title("Public Timeline")) = render 'static/mobile_nav' .container.j2-page .col-md-3.col-sm-3 diff --git a/app/views/question/show.html.haml b/app/views/question/show.html.haml index 1bb30c6e..5ccbc6c4 100644 --- a/app/views/question/show.html.haml +++ b/app/views/question/show.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "#{@question.user.display_name.blank? ? "@#{@question.user.screen_name}'s" : "#{@question.user.display_name}'s"} question | #{APP_CONFIG['site_name']}") +- provide(:title, question_title(@question)) = render 'shared/question_header', question: @question, hidden: false = render 'shared/question_header', question: @question, hidden: true .container.question-page diff --git a/app/views/services/index.html.haml b/app/views/services/index.html.haml index fe04011b..a198bce9 100644 --- a/app/views/services/index.html.haml +++ b/app/views/services/index.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "Service Settings | #{APP_CONFIG['site_name']}") +- provide(:title, generate_title("Service Settings")) .container.j2-page = render 'user/settings_tabs' .col-md-9.col-xs-12.col-sm-9 diff --git a/app/views/static/about.html.haml b/app/views/static/about.html.haml index 52c09428..e1a9a97f 100644 --- a/app/views/static/about.html.haml +++ b/app/views/static/about.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "About | #{APP_CONFIG['site_name']}") +- provide(:title, generate_title("About")) .jumbotron.j2-jumbo.text-center.particle-jumbotron #particles .particle-content diff --git a/app/views/static/faq.html.haml b/app/views/static/faq.html.haml index 8d04b734..56c937b9 100644 --- a/app/views/static/faq.html.haml +++ b/app/views/static/faq.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "Frequently Asked Questions | #{APP_CONFIG['site_name']}") +- provide(:title, generate_title("Frequently Asked Questions")) .jumbotron.j2-jumbo.text-center.particle-jumbotron #particles .particle-content diff --git a/app/views/static/privacy_policy.html.haml b/app/views/static/privacy_policy.html.haml index 7ea7c7c5..931a71ad 100644 --- a/app/views/static/privacy_policy.html.haml +++ b/app/views/static/privacy_policy.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "Privacy Policy | #{APP_CONFIG['site_name']}") +- provide(:title, generate_title("Privacy Policy")) .container .panel.panel-default .panel-body diff --git a/app/views/static/terms.html.haml b/app/views/static/terms.html.haml index f918cab0..b31f8da7 100644 --- a/app/views/static/terms.html.haml +++ b/app/views/static/terms.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "Terms of Service | #{APP_CONFIG['site_name']}") +- provide(:title, generate_title("Terms of Service")) .container .panel.panel-default .panel-body diff --git a/app/views/user/_account.html.haml b/app/views/user/_account.html.haml index 0c9eda99..208d4d1f 100644 --- a/app/views/user/_account.html.haml +++ b/app/views/user/_account.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "Account Settings | #{APP_CONFIG['site_name']}") +- provide(:title, generate_title("Account Settings")) .container.j2-page = render 'user/settings_tabs' .col-md-9.col-xs-12.col-sm-9 diff --git a/app/views/user/edit.html.haml b/app/views/user/edit.html.haml index 9a646467..07d9f0d9 100644 --- a/app/views/user/edit.html.haml +++ b/app/views/user/edit.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "Profile Settings | #{APP_CONFIG['site_name']}") +- provide(:title, generate_title("Profile Settings")) .container.j2-page = render 'settings_tabs' .col-md-9.col-xs-12.col-sm-9 diff --git a/app/views/user/edit_privacy.html.haml b/app/views/user/edit_privacy.html.haml index b705cb12..26aad1cc 100644 --- a/app/views/user/edit_privacy.html.haml +++ b/app/views/user/edit_privacy.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "Privacy Settings | #{APP_CONFIG['site_name']}") +- provide(:title, generate_title("Privacy Settings")) .container.j2-page = render 'settings_tabs' .col-md-9.col-xs-12.col-sm-9 diff --git a/app/views/user/questions.html.haml b/app/views/user/questions.html.haml index 884e88b3..480447a1 100644 --- a/app/views/user/questions.html.haml +++ b/app/views/user/questions.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "#{@user.display_name.blank? ? "@#{@user.screen_name}'s" : "#{@user.display_name}'s"} questions | #{APP_CONFIG['site_name']}") +- provide(:title, questions_title(@user)) .profile--header .container.j2-page .col-md-3.col-xs-12.col-sm-4.j2-col-reset diff --git a/app/views/user/show.html.haml b/app/views/user/show.html.haml index 47e32e9d..9170e382 100644 --- a/app/views/user/show.html.haml +++ b/app/views/user/show.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "#{@user.display_name.blank? ? "@#{@user.screen_name}" : "#{@user.display_name} (@#{@user.screen_name})"} | #{APP_CONFIG['site_name']}") +- provide(:title, user_title(@user)) - no_header = unless @user.profile_header.exists? then "profile--no-header" else "" end #profile--header.hidden-xs{class: no_header} %img.profile--header-img{src: @user.profile_header.url(:web)} diff --git a/app/views/user/show_follow.html.haml b/app/views/user/show_follow.html.haml index f1af7740..d1d3878f 100644 --- a/app/views/user/show_follow.html.haml +++ b/app/views/user/show_follow.html.haml @@ -1,4 +1,4 @@ -- provide(:title, "#{@user.display_name.blank? ? "@#{@user.screen_name}'s" : "#{@user.display_name}'s"} friends & followers | #{APP_CONFIG['site_name']}") +- provide(:title, user_title(@user, "friends and followers")) .profile--header .container.j2-page .col-md-3.col-xs-12.col-sm-4.j2-col-reset