BigW Consortium Gitlab

page_layout_helper.rb 2.99 KB
Newer Older
1 2 3 4 5 6
module PageLayoutHelper
  def page_title(*titles)
    @page_title ||= []

    @page_title.push(*titles.compact) if titles.any?

7
    if titles.any? && !defined?(@breadcrumb_title)
Phil Hughes committed
8
      @breadcrumb_title = @page_title.last
9 10
    end

11
    # Segments are seperated by middot
12
    @page_title.join(" · ")
13 14
  end

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  # 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?
35
      @page_description = description.squish
36
    elsif @page_description.present?
37
      sanitize(@page_description, tags: []).truncate_words(30)
38 39 40
    end
  end

41
  def favicon
42
    Rails.env.development? ? 'favicon-blue.ico' : 'favicon.ico'
43 44
  end

45 46 47
  def page_image
    default = image_url('gitlab_logo.png')

48 49
    subject = @project || @user || @group

50 51
    image = subject.avatar_url if subject.present?
    image || default
52 53
  end

54 55 56 57 58 59 60 61 62
  # 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 ||= {}
63
    @page_card_attributes = map.reject { |_, v| v.blank? } if map.present?
64 65 66 67 68 69 70 71 72 73 74 75 76 77
    @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

78 79 80 81 82
  def header_title(title = nil, title_url = nil)
    if title
      @header_title     = title
      @header_title_url = title_url
    else
83 84
      return @header_title unless @header_title_url

85
      breadcrumb_list_item(link_to(@header_title, @header_title_url))
86 87 88 89 90 91 92 93 94 95
    end
  end

  def sidebar(name = nil)
    if name
      @sidebar = name
    else
      @sidebar
    end
  end
96

97 98 99 100 101 102 103 104
  def nav(name = nil)
    if name
      @nav = name
    else
      @nav
    end
  end

105 106
  def fluid_layout
    current_user && current_user.layout == "fluid"
107
  end
108 109 110 111 112 113 114 115 116 117 118 119

  def blank_container(enabled = false)
    if @blank_container.nil?
      @blank_container = enabled
    else
      @blank_container
    end
  end

  def container_class
    css_class = "container-fluid"

Dmitriy Zaporozhets committed
120
    unless fluid_layout
121 122 123 124 125 126 127 128 129
      css_class += " container-limited"
    end

    if blank_container
      css_class += " container-blank"
    end

    css_class
  end
130
end