summaryrefslogtreecommitdiff
path: root/app/helpers
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-12-23 16:56:27 -0500
committerRobert Speicher <rspeicher@gmail.com>2015-12-23 16:56:27 -0500
commitb26eb782f5536d8c383aebe3d65571fb16a20bcd (patch)
tree5ce450e297a9de15925ecfbead926b36a153f4e7 /app/helpers
parent3f452f539b909d1a379a4f3c5d48307246a14fff (diff)
downloadgitlab-ce-b26eb782f5536d8c383aebe3d65571fb16a20bcd.tar.gz
Add page descriptions and images
A limited number of pages have defined their own descriptions, but otherwise we default to the Project's description (if `@project` is set), or the old `brand_title` fallback. The image will either be the uploaded project icon (never a generated one), the user's uploaded icon or Gravatar, or, finally, the GitLab logo.
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/page_layout_helper.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/app/helpers/page_layout_helper.rb b/app/helpers/page_layout_helper.rb
index 9bf750124b2..6b16528dde6 100644
--- a/app/helpers/page_layout_helper.rb
+++ b/app/helpers/page_layout_helper.rb
@@ -8,6 +8,56 @@ module PageLayoutHelper
@page_title.join(" \u00b7 ")
end
+ # Define or get a description for the current page
+ #
+ # description - String (default: nil)
+ #
+ # If this helper is called multiple times with an argument, only the last
+ # description will be returned when called without an argument. Descriptions
+ # have newlines replaced with spaces and all HTML tags are sanitized.
+ #
+ # Examples:
+ #
+ # page_description # => "GitLab Community Edition"
+ # page_description("Foo")
+ # page_description # => "Foo"
+ #
+ # page_description("<b>Bar</b>\nBaz")
+ # page_description # => "Bar Baz"
+ #
+ # Returns an HTML-safe String.
+ def page_description(description = nil)
+ @page_description ||= page_description_default
+
+ if description.present?
+ @page_description = description
+ else
+ sanitize(@page_description.squish, tags: [])
+ end
+ end
+
+ # Default value for page_description when one hasn't been defined manually by
+ # a view
+ def page_description_default
+ if @project
+ @project.description
+ else
+ brand_title
+ end
+ end
+
+ def page_image
+ default = image_url('gitlab_logo.png')
+
+ if @project
+ @project.avatar_url || default
+ elsif @user
+ avatar_icon(@user)
+ else
+ default
+ end
+ end
+
def header_title(title = nil, title_url = nil)
if title
@header_title = title