Module: PageLayoutHelper

Included in:
ApplicationController, Oauth::ApplicationsController, Oauth::AuthorizedApplicationsController
Defined in:
app/helpers/page_layout_helper.rb

Instance Method Summary collapse

Instance Method Details

#blank_container(enabled = false) ⇒ Object


103
104
105
106
107
108
109
# File 'app/helpers/page_layout_helper.rb', line 103

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

#container_classObject


111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/helpers/page_layout_helper.rb', line 111

def container_class
  css_class = "container-fluid"

  unless fluid_layout
    css_class += " container-limited"
  end

  if blank_container
    css_class += " container-blank"
  end

  css_class
end

#fluid_layout(enabled = false) ⇒ Object


95
96
97
98
99
100
101
# File 'app/helpers/page_layout_helper.rb', line 95

def fluid_layout(enabled = false)
  if @fluid_layout.nil?
    @fluid_layout = (current_user && current_user.layout == "fluid") || enabled
  else
    @fluid_layout
  end
end

#header_title(title = nil, title_url = nil) ⇒ Object


70
71
72
73
74
75
76
77
# File 'app/helpers/page_layout_helper.rb', line 70

def header_title(title = nil, title_url = nil)
  if title
    @header_title     = title
    @header_title_url = title_url
  else
    @header_title_url ? link_to(@header_title, @header_title_url) : @header_title
  end
end

87
88
89
90
91
92
93
# File 'app/helpers/page_layout_helper.rb', line 87

def nav(name = nil)
  if name
    @nav = name
  else
    @nav
  end
end

#page_card_attributes(map = {}) ⇒ Object

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

Raises:

  • (ArgumentError)

51
52
53
54
55
56
57
# File 'app/helpers/page_layout_helper.rb', line 51

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

#page_card_meta_tagsObject


59
60
61
62
63
64
65
66
67
68
# File 'app/helpers/page_layout_helper.rb', line 59

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

#page_description(description = nil) ⇒ Object

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.


29
30
31
32
33
34
35
# File 'app/helpers/page_layout_helper.rb', line 29

def page_description(description = nil)
  if description.present?
    @page_description = description.squish
  elsif @page_description.present?
    sanitize(@page_description, tags: []).truncate_words(30)
  end
end

#page_imageObject


37
38
39
40
41
42
43
44
# File 'app/helpers/page_layout_helper.rb', line 37

def page_image
  default = image_url('gitlab_logo.png')

  subject = @project || @user || @group

  image = subject.avatar_url if subject.present?
  image || default
end

#page_title(*titles) ⇒ Object


2
3
4
5
6
7
8
9
# File 'app/helpers/page_layout_helper.rb', line 2

def page_title(*titles)
  @page_title ||= []

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

  # Segments are seperated by middot
  @page_title.join(" \u00b7 ")
end

79
80
81
82
83
84
85
# File 'app/helpers/page_layout_helper.rb', line 79

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