2015-05-01 08:39:11 +00:00
|
|
|
module PageLayoutHelper
|
|
|
|
def page_title(*titles)
|
|
|
|
@page_title ||= []
|
|
|
|
|
|
|
|
@page_title.push(*titles.compact) if titles.any?
|
|
|
|
|
2017-09-06 10:58:24 +00:00
|
|
|
if titles.any? && !defined?(@breadcrumb_title)
|
2017-07-14 07:56:06 +00:00
|
|
|
@breadcrumb_title = @page_title.last
|
2017-07-12 08:04:22 +00:00
|
|
|
end
|
|
|
|
|
2015-12-02 13:57:51 +00:00
|
|
|
# Segments are seperated by middot
|
2017-08-23 11:23:41 +00:00
|
|
|
@page_title.join(" · ")
|
2015-05-01 08:39:11 +00:00
|
|
|
end
|
|
|
|
|
2015-12-23 21:56:27 +00:00
|
|
|
# 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)
|
|
|
|
if description.present?
|
2015-12-24 21:26:52 +00:00
|
|
|
@page_description = description.squish
|
2016-01-06 12:02:51 +00:00
|
|
|
elsif @page_description.present?
|
2015-12-24 21:26:52 +00:00
|
|
|
sanitize(@page_description, tags: []).truncate_words(30)
|
2015-12-23 21:56:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-15 14:07:29 +00:00
|
|
|
def favicon
|
2017-06-27 11:49:50 +00:00
|
|
|
return 'favicon-yellow.ico' if ENV['CANARY'] == 'true'
|
|
|
|
return 'favicon-blue.ico' if Rails.env.development?
|
|
|
|
'favicon.ico'
|
2017-02-15 14:07:29 +00:00
|
|
|
end
|
|
|
|
|
2015-12-23 21:56:27 +00:00
|
|
|
def page_image
|
|
|
|
default = image_url('gitlab_logo.png')
|
|
|
|
|
2016-01-05 19:50:52 +00:00
|
|
|
subject = @project || @user || @group
|
|
|
|
|
2016-01-06 12:02:51 +00:00
|
|
|
image = subject.avatar_url if subject.present?
|
|
|
|
image || default
|
2015-12-23 21:56:27 +00:00
|
|
|
end
|
|
|
|
|
2015-12-24 22:03:54 +00:00
|
|
|
# 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 ||= {}
|
2016-06-29 13:23:44 +00:00
|
|
|
@page_card_attributes = map.reject { |_, v| v.blank? } if map.present?
|
2015-12-24 22:03:54 +00:00
|
|
|
@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
|
|
|
|
|
2015-05-01 08:39:11 +00:00
|
|
|
def header_title(title = nil, title_url = nil)
|
|
|
|
if title
|
|
|
|
@header_title = title
|
|
|
|
@header_title_url = title_url
|
|
|
|
else
|
2017-09-06 10:55:23 +00:00
|
|
|
return @header_title unless @header_title_url
|
|
|
|
|
2017-09-06 11:19:03 +00:00
|
|
|
breadcrumb_list_item(link_to(@header_title, @header_title_url))
|
2015-05-01 08:39:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def sidebar(name = nil)
|
|
|
|
if name
|
|
|
|
@sidebar = name
|
|
|
|
else
|
|
|
|
@sidebar
|
|
|
|
end
|
|
|
|
end
|
2015-08-26 09:51:28 +00:00
|
|
|
|
2016-04-19 18:05:30 +00:00
|
|
|
def nav(name = nil)
|
|
|
|
if name
|
|
|
|
@nav = name
|
|
|
|
else
|
|
|
|
@nav
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-19 23:02:52 +00:00
|
|
|
def fluid_layout
|
|
|
|
current_user && current_user.layout == "fluid"
|
2015-08-26 09:51:28 +00:00
|
|
|
end
|
2015-09-09 21:29:19 +00:00
|
|
|
|
|
|
|
def blank_container(enabled = false)
|
|
|
|
if @blank_container.nil?
|
|
|
|
@blank_container = enabled
|
|
|
|
else
|
|
|
|
@blank_container
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def container_class
|
|
|
|
css_class = "container-fluid"
|
|
|
|
|
2015-09-10 07:51:37 +00:00
|
|
|
unless fluid_layout
|
2015-09-09 21:29:19 +00:00
|
|
|
css_class += " container-limited"
|
|
|
|
end
|
|
|
|
|
|
|
|
if blank_container
|
|
|
|
css_class += " container-blank"
|
|
|
|
end
|
|
|
|
|
|
|
|
css_class
|
|
|
|
end
|
2015-05-01 08:39:11 +00:00
|
|
|
end
|