Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/helpers/page_layout_helper.rb')
-rw-r--r--app/helpers/page_layout_helper.rb77
1 files changed, 76 insertions, 1 deletions
diff --git a/app/helpers/page_layout_helper.rb b/app/helpers/page_layout_helper.rb
index 775cf5a3dd4..791cb9e50bd 100644
--- a/app/helpers/page_layout_helper.rb
+++ b/app/helpers/page_layout_helper.rb
@@ -4,7 +4,82 @@ module PageLayoutHelper
@page_title.push(*titles.compact) if titles.any?
- @page_title.join(" | ")
+ # Segments are seperated by middot
+ @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.squish
+ else
+ sanitize(@page_description, tags: []).truncate_words(30)
+ 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 || brand_title
+ 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
+
+ # Define or get attributes to be used as Twitter card metadata
+ #
+ # map - Hash of label => data pairs. Keys become labels, values become data
+ #
+ # Raises ArgumentError if given more than two attributes
+ def page_card_attributes(map = {})
+ raise ArgumentError, 'cannot provide more than two attributes' if map.length > 2
+
+ @page_card_attributes ||= {}
+ @page_card_attributes = map.reject { |_,v| v.blank? } if map.present?
+ @page_card_attributes
+ end
+
+ def page_card_meta_tags
+ tags = ''
+
+ page_card_attributes.each_with_index do |pair, i|
+ tags << tag(:meta, property: "twitter:label#{i + 1}", content: pair[0])
+ tags << tag(:meta, property: "twitter:data#{i + 1}", content: pair[1])
+ end
+
+ tags.html_safe
end
def header_title(title = nil, title_url = nil)