Module: PageLayoutHelper
- Includes:
- Gitlab::Utils::StrongMemoize
- Included in:
- ApplicationController, Oauth::ApplicationsController, Oauth::AuthorizedApplicationsController
- Defined in:
- app/helpers/page_layout_helper.rb
Instance Method Summary collapse
- #blank_container(enabled = false) ⇒ Object
- #container_class ⇒ Object
- #favicon ⇒ Object
- #fluid_layout ⇒ Object
- #full_content_class ⇒ Object
- #header_title(title = nil, title_url = nil) ⇒ Object
- #nav(name = nil) ⇒ Object
- #page_canonical_link(link = nil) ⇒ Object
-
#page_card_attributes(map = {}) ⇒ Object
Define or get attributes to be used as Twitter card metadata.
- #page_card_meta_tags ⇒ Object
-
#page_description(description = nil) ⇒ Object
Define or get a description for the current page.
- #page_image ⇒ Object
- #page_itemtype(itemtype = nil) ⇒ Object
- #page_title(*titles) ⇒ Object
-
#search_context ⇒ Object
This helper ensures there is always a default ‘Gitlab::SearchContext` available to all controller that use the application layout.
- #sidebar(name = nil) ⇒ Object
- #user_status_properties(user) ⇒ Object
Instance Method Details
#blank_container(enabled = false) ⇒ Object
131 132 133 134 135 136 137 |
# File 'app/helpers/page_layout_helper.rb', line 131 def blank_container(enabled = false) if @blank_container.nil? @blank_container = enabled else @blank_container end end |
#container_class ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'app/helpers/page_layout_helper.rb', line 139 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.join(' ') end |
#favicon ⇒ Object
53 54 55 |
# File 'app/helpers/page_layout_helper.rb', line 53 def favicon Gitlab::Favicon.main end |
#fluid_layout ⇒ Object
127 128 129 |
# File 'app/helpers/page_layout_helper.rb', line 127 def fluid_layout @force_fluid_layout == true || (current_user && current_user.layout == "fluid") end |
#full_content_class ⇒ Object
153 154 155 |
# File 'app/helpers/page_layout_helper.rb', line 153 def full_content_class "#{container_class} #{@content_class}" # rubocop:disable Rails/HelperInstanceVariable end |
#header_title(title = nil, title_url = nil) ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'app/helpers/page_layout_helper.rb', line 90 def header_title(title = nil, title_url = nil) if title @header_title = title @header_title_url = title_url else return @header_title unless @header_title_url (link_to(@header_title, @header_title_url)) end end |
#nav(name = nil) ⇒ Object
109 110 111 112 113 114 115 |
# File 'app/helpers/page_layout_helper.rb', line 109 def nav(name = nil) if name @nav = name else @nav end end |
#page_canonical_link(link = nil) ⇒ Object
45 46 47 48 49 50 51 |
# File 'app/helpers/page_layout_helper.rb', line 45 def page_canonical_link(link = nil) if link @page_canonical_link = link else @page_canonical_link ||= generic_canonical_url 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
71 72 73 74 75 76 77 |
# File 'app/helpers/page_layout_helper.rb', line 71 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_tags ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'app/helpers/page_layout_helper.rb', line 79 def = [] page_card_attributes.each_with_index do |pair, i| << tag.(property: "twitter:label#{i + 1}", content: pair[0]) << tag.(property: "twitter:data#{i + 1}", content: pair[1]) end .join.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.
37 38 39 40 41 42 43 |
# File 'app/helpers/page_layout_helper.rb', line 37 def page_description(description = nil) if description.present? @page_description = description.squish elsif @page_description.present? sanitize(@page_description.truncate_words(30), tags: []) end end |
#page_image ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'app/helpers/page_layout_helper.rb', line 57 def page_image default = image_url('twitter_card.jpg') subject = @project || @user || @group image = subject.avatar_url(only_path: false) if subject.present? image || default end |
#page_itemtype(itemtype = nil) ⇒ Object
157 158 159 160 161 162 163 |
# File 'app/helpers/page_layout_helper.rb', line 157 def page_itemtype(itemtype = nil) if itemtype @page_itemtype = { itemscope: true, itemtype: itemtype } else @page_itemtype || {} end end |
#page_title(*titles) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/helpers/page_layout_helper.rb', line 6 def page_title(*titles) @page_title ||= [] @page_title.push(*titles.compact) if titles.any? if titles.any? && !defined?(@breadcrumb_title) @breadcrumb_title = @page_title.last end # Segments are separated by middot @page_title.join(" · ") end |
#search_context ⇒ Object
This helper ensures there is always a default ‘Gitlab::SearchContext` available to all controller that use the application layout.
119 120 121 122 123 124 125 |
# File 'app/helpers/page_layout_helper.rb', line 119 def search_context strong_memoize(:search_context) do next super if defined?(super) Gitlab::SearchContext::Builder.new(controller.view_context).build! end end |
#sidebar(name = nil) ⇒ Object
101 102 103 104 105 106 107 |
# File 'app/helpers/page_layout_helper.rb', line 101 def (name = nil) if name @sidebar = name else @sidebar end end |
#user_status_properties(user) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'app/helpers/page_layout_helper.rb', line 165 def user_status_properties(user) default_properties = { current_emoji: '', current_message: '', default_emoji: UserStatus::DEFAULT_EMOJI } return default_properties unless user&.status default_properties.merge({ current_emoji: user.status.emoji.to_s, current_message: user.status..to_s, current_availability: user.status.availability.to_s, current_clear_status_after: user_clear_status_at(user) }) end |