Commit 1993a444 authored by gfyoung's avatar gfyoung

Enable frozen string for app/helpers/**/*.rb

Partially addresses #47424.
parent 07d5ee36
# frozen_string_literal: true
module AccountsHelper
def incoming_email_token_enabled?
current_user.incoming_email_token && Gitlab::IncomingEmail.supports_issue_creation?
......
# frozen_string_literal: true
module ActiveSessionsHelper
# Maps a device type as defined in `ActiveSession` to an svg icon name and
# outputs the icon html.
......
# frozen_string_literal: true
module AppearancesHelper
def brand_title
current_appearance&.title.presence || 'GitLab Community Edition'
......
# frozen_string_literal: true
require 'digest/md5'
require 'uri'
......@@ -106,11 +108,11 @@ module ApplicationHelper
#
# Returns an HTML-safe String
def time_ago_with_tooltip(time, placement: 'top', html_class: '', short_format: false)
css_classes = short_format ? 'js-short-timeago' : 'js-timeago'
css_classes << " #{html_class}" unless html_class.blank?
css_classes = [short_format ? 'js-short-timeago' : 'js-timeago']
css_classes << html_class unless html_class.blank?
element = content_tag :time, l(time, format: "%b %d, %Y"),
class: css_classes,
class: css_classes.join(' '),
title: l(time.to_time.in_time_zone, format: :timeago_tooltip),
datetime: time.to_time.getutc.iso8601,
data: {
......
# frozen_string_literal: true
module ApplicationSettingsHelper
extend self
......@@ -73,12 +75,12 @@ module ApplicationSettingsHelper
def oauth_providers_checkboxes
button_based_providers.map do |source|
disabled = Gitlab::CurrentSettings.disabled_oauth_sign_in_sources.include?(source.to_s)
css_class = 'btn'
css_class << ' active' unless disabled
css_class = ['btn']
css_class << 'active' unless disabled
checkbox_name = 'application_setting[enabled_oauth_sign_in_sources][]'
name = Gitlab::Auth::OAuth::Provider.label_for(source)
label_tag(checkbox_name, class: css_class) do
label_tag(checkbox_name, class: css_class.join(' ')) do
check_box_tag(checkbox_name, source, !disabled,
autocomplete: 'off',
id: name.tr(' ', '_')) + name
......
# frozen_string_literal: true
module AuthHelper
PROVIDERS_WITH_ICONS = %w(twitter github gitlab bitbucket google_oauth2 facebook azure_oauth2 authentiq).freeze
LDAP_PROVIDER = /\Aldap/
......
# frozen_string_literal: true
module AutoDevopsHelper
def show_auto_devops_callout?(project)
Feature.get(:auto_devops_banner_disabled).off? &&
......
# frozen_string_literal: true
module AvatarsHelper
def project_icon(project_id, options = {})
source_icon(Project, project_id, options)
......@@ -125,9 +127,9 @@ module AvatarsHelper
def source_identicon(source, options = {})
bg_key = (source.id % 7) + 1
options[:class] ||= ''
options[:class] << ' identicon'
options[:class] << " bg#{bg_key}"
options[:class] =
[*options[:class], "identicon bg#{bg_key}"].join(' ')
content_tag(:div, class: options[:class].strip) do
source.name[0, 1].upcase
......
# frozen_string_literal: true
module AwardEmojiHelper
def toggle_award_url(awardable)
return url_for([:toggle_award_emoji, awardable]) unless @project || awardable.is_a?(Note)
......
# frozen_string_literal: true
module BlameHelper
def age_map_duration(blame_groups, project)
now = Time.zone.now
......
# frozen_string_literal: true
module BlobHelper
def highlight(blob_name, blob_content, repository: nil, plain: false)
plain ||= blob_content.length > Blob::MAXIMUM_TEXT_HIGHLIGHT_SIZE
......
# frozen_string_literal: true
module BoardsHelper
def board
@board ||= @board || @boards.first
......
# frozen_string_literal: true
module BranchesHelper
def project_branches
options_for_select(@project.repository.branch_names, @project.default_branch)
......
# frozen_string_literal: true
module BreadcrumbsHelper
def add_to_breadcrumbs(text, link)
@breadcrumbs_extra_links ||= []
......
# frozen_string_literal: true
module BroadcastMessagesHelper
def broadcast_message(message)
return unless message.present?
......@@ -8,18 +10,17 @@ module BroadcastMessagesHelper
end
def broadcast_message_style(broadcast_message)
style = ''
style = []
if broadcast_message.color.present?
style << "background-color: #{broadcast_message.color}"
style << '; ' if broadcast_message.font.present?
end
if broadcast_message.font.present?
style << "color: #{broadcast_message.font}"
end
style
style.join('; ')
end
def broadcast_message_status(broadcast_message)
......
# frozen_string_literal: true
module BuildsHelper
def build_summary(build, skip: false)
if build.has_trace?
......@@ -12,10 +14,10 @@ module BuildsHelper
end
def sidebar_build_class(build, current_build)
build_class = ''
build_class += ' active' if build.id === current_build.id
build_class += ' retried' if build.retried?
build_class
build_class = []
build_class << 'active' if build.id === current_build.id
build_class << 'retried' if build.retried?
build_class.join(' ')
end
def javascript_build_options
......
# frozen_string_literal: true
module ButtonHelper
# Output a "Copy to Clipboard" button
#
......
# frozen_string_literal: true
module CalendarHelper
def calendar_url_options
{ format: :ics,
......
# frozen_string_literal: true
##
# DEPRECATED
#
......
# frozen_string_literal: true
module ClustersHelper
def has_multiple_clusters?(project)
false
......
# frozen_string_literal: true
module CommitsHelper
# Returns a link to the commit author. If the author has a matching user and
# is a member of the current @project it will link to the team member page.
......
# frozen_string_literal: true
module CompareHelper
def create_mr_button?(from = params[:from], to = params[:to], project = @project)
from.present? &&
......
# frozen_string_literal: true
module ComponentsHelper
def gitlab_workhorse_version
if request.headers['Gitlab-Workhorse'].present?
......
# frozen_string_literal: true
module ConversationalDevelopmentIndexHelper
def score_level(score)
if score < 33.33
......
# frozen_string_literal: true
module CountHelper
def approximate_count_with_delimiters(count_data, model)
count = count_data[model]
......
# frozen_string_literal: true
module DashboardHelper
def assigned_issues_dashboard_path
issues_dashboard_path(assignee_id: current_user.id)
......
# frozen_string_literal: true
module DeferScriptTagHelper
# Override the default ActionView `javascript_include_tag` helper to support page specific deferred loading
def javascript_include_tag(*sources)
......
# frozen_string_literal: true
module DeployTokensHelper
def expand_deploy_tokens_section?(deploy_token)
deploy_token.persisted? ||
......
# frozen_string_literal: true
module DiffHelper
def mark_inline_diffs(old_line, new_line)
old_diffs, new_diffs = Gitlab::Diff::InlineDiff.new(old_line, new_line).inline_diffs
......@@ -39,7 +41,8 @@ module DiffHelper
line_num_class = %w[diff-line-num unfold js-unfold]
line_num_class << 'js-unfold-bottom' if bottom
html = ''
html = []
if old_pos
html << content_tag(:td, '...', class: [*line_num_class, 'old_line'], data: { linenumber: old_pos })
html << content_tag(:td, text, class: [*content_line_class, 'left-side']) if view == :parallel
......@@ -50,7 +53,7 @@ module DiffHelper
html << content_tag(:td, text, class: [*content_line_class, ('right-side' if view == :parallel)])
end
html.html_safe
html.join.html_safe
end
def diff_line_content(line)
......@@ -215,9 +218,7 @@ module DiffHelper
end
def toggle_whitespace_link(url, options)
options[:class] ||= ''
options[:class] << ' btn btn-default'
options[:class] = [*options[:class], 'btn btn-default'].join(' ')
link_to "#{hide_whitespace? ? 'Show' : 'Hide'} whitespace changes", url, class: options[:class]
end
......
# frozen_string_literal: true
module DropdownsHelper
def dropdown_tag(toggle_text, options: {}, &block)
content_tag :div, class: "dropdown #{options[:wrapper_class] if options.key?(:wrapper_class)}" do
......@@ -10,7 +12,7 @@ module DropdownsHelper
dropdown_output = dropdown_toggle(toggle_text, data_attr, options)
dropdown_output << content_tag(:div, class: "dropdown-menu dropdown-select #{options[:dropdown_class] if options.key?(:dropdown_class)}") do
output = ""
output = []
if options.key?(:title)
output << dropdown_title(options[:title])
......@@ -31,8 +33,7 @@ module DropdownsHelper
end
output << dropdown_loading
output.html_safe
output.join.html_safe
end
dropdown_output.html_safe
......@@ -50,7 +51,7 @@ module DropdownsHelper
def dropdown_title(title, options: {})
content_tag :div, class: "dropdown-title" do
title_output = ""
title_output = []
if options.fetch(:back, false)
title_output << content_tag(:button, class: "dropdown-title-button dropdown-menu-back", aria: { label: "Go back" }, type: "button") do
......@@ -66,7 +67,7 @@ module DropdownsHelper
end
end
title_output.html_safe
title_output.join.html_safe
end
end
......
# frozen_string_literal: true
module EmailsHelper
include AppearancesHelper
......@@ -49,8 +51,8 @@ module EmailsHelper
def reset_token_expire_message
link_tag = link_to('request a new one', new_user_password_url(user_email: @user.email))
msg = "This link is valid for #{password_reset_token_valid_time}. "
msg << "After it expires, you can #{link_tag}."
"This link is valid for #{password_reset_token_valid_time}. " \
"After it expires, you can #{link_tag}."
end
def header_logo
......
# frozen_string_literal: true
module EmojiHelper
def emoji_icon(*args)
raw Gitlab::Emoji.gl_emoji_tag(*args)
......
# frozen_string_literal: true
module EnvironmentHelper
def environment_for_build(project, build)
return unless build.environment
......
# frozen_string_literal: true
module EnvironmentsHelper
def environments_list_data
{
......
# frozen_string_literal: true
module EventsHelper
ICON_NAMES_BY_EVENT_TYPE = {
'pushed to' => 'commit',
......
# frozen_string_literal: true
module ExploreHelper
def filter_projects_path(options = {})
exist_opts = {
......
# frozen_string_literal: true
module ExternalWikiHelper
def get_project_wiki_path(project)
external_wiki_service = project.external_wiki
......
# frozen_string_literal: true
module FaviconHelper
def favicon_extension_whitelist
FaviconUploader::EXTENSION_WHITELIST
......
# frozen_string_literal: true
module FormHelper
def form_errors(model, type: 'form')
return unless model.errors.any?
......
# frozen_string_literal: true
module GitHelper
def strip_gpg_signature(text)
text.gsub(/-----BEGIN PGP SIGNATURE-----(.*)-----END PGP SIGNATURE-----/m, "")
......
# frozen_string_literal: true
# Shorter routing method for some project items
module GitlabRoutingHelper
extend ActiveSupport::Concern
......
# frozen_string_literal: true
module GraphHelper
def refs(repo, commit)
refs = commit.ref_names(repo).join(' ')
refs = [commit.ref_names(repo).join(' ')]
# append note count
notes_count = @graph.notes[commit.id]
refs << "[#{pluralize(notes_count, 'note')}]" if notes_count > 0
refs
refs.join
end
def parents_zip_spaces(parents, parent_spaces)
......
# frozen_string_literal: true
module GroupsHelper
def group_nav_link_paths
%w[groups#projects groups#edit badges#index ci_cd#show ldap_group_links#index hooks#index audit_events#index pipeline_quota#index]
......@@ -43,22 +45,22 @@ module GroupsHelper
def group_title(group, name = nil, url = nil)
@has_group_title = true
full_title = ''
full_title = []
group.ancestors.reverse.each_with_index do |parent, index|
if index > 0
add_to_breadcrumb_dropdown(group_title_link(parent, hidable: false, show_avatar: true, for_dropdown: true), location: :before)
else
full_title += breadcrumb_list_item group_title_link(parent, hidable: false)
full_title << breadcrumb_list_item(group_title_link(parent, hidable: false))
end
end
full_title += render "layouts/nav/breadcrumbs/collapsed_dropdown", location: :before, title: _("Show parent subgroups")
full_title << render("layouts/nav/breadcrumbs/collapsed_dropdown", location: :before, title: _("Show parent subgroups"))
full_title += breadcrumb_list_item group_title_link(group)
full_title += ' &middot; '.html_safe + link_to(simple_sanitize(name), url, class: 'group-path breadcrumb-item-text js-breadcrumb-item-text') if name
full_title << breadcrumb_list_item(group_title_link(group))
full_title << ' &middot; '.html_safe + link_to(simple_sanitize(name), url, class: 'group-path breadcrumb-item-text js-breadcrumb-item-text') if name
full_title.html_safe
full_title.join.html_safe
end
def projects_lfs_status(group)
......@@ -138,15 +140,8 @@ module GroupsHelper
def group_title_link(group, hidable: false, show_avatar: false, for_dropdown: false)
link_to(group_path(group), class: "group-path #{'breadcrumb-item-text' unless for_dropdown} js-breadcrumb-item-text #{'hidable' if hidable}") do
output =
if (group.try(:avatar_url) || show_avatar) && !Rails.env.test?
group_icon(group, class: "avatar-tile", width: 15, height: 15)
else
""
end
output << simple_sanitize(group.name)
output.html_safe
icon = group_icon(group, class: "avatar-tile", width: 15, height: 15) if (group.try(:avatar_url) || show_avatar) && !Rails.env.test?
[icon, simple_sanitize(group.name)].join.html_safe
end
end
......
# frozen_string_literal: true
module HooksHelper
def link_to_test_hook(hook, trigger)
path = case hook
......
# frozen_string_literal: true
require 'json'
module IconsHelper
......@@ -47,9 +49,10 @@ module IconsHelper
end
end
css_classes = size ? "s#{size}" : ""
css_classes << " #{css_class}" unless css_class.blank?
content_tag(:svg, content_tag(:use, "", { "xlink:href" => "#{sprite_icon_path}##{icon_name}" } ), class: css_classes.empty? ? nil : css_classes)
css_classes = []
css_classes << "s#{size}" if size
css_classes << "#{css_class}" unless css_class.blank?
content_tag(:svg, content_tag(:use, "", { "xlink:href" => "#{sprite_icon_path}##{icon_name}" } ), class: css_classes.empty? ? nil : css_classes.join(' '))
end
def external_snippet_icon(name)
......@@ -70,10 +73,10 @@ module IconsHelper
end
def spinner(text = nil, visible = false)
css_class = 'loading'
css_class << ' hide' unless visible
css_class = ['loading']
css_class << 'hide' unless visible
content_tag :div, class: css_class do
content_tag :div, class: css_class.join(' ') do
icon('spinner spin') + text
end
end
......@@ -97,9 +100,10 @@ module IconsHelper
'globe'
end
name << " fw" if fw
name = [name]
name << "fw" if fw
icon(name, options)
icon(name.join(' '), options)
end
def file_type_icon_class(type, mode, name)
......
# frozen_string_literal: true
module ImportHelper
include ::Gitlab::Utils::StrongMemoize
......
# frozen_string_literal: true
module InstanceConfigurationHelper
def instance_configuration_cell_html(value, &block)
return '-' unless value.to_s.presence
......
# frozen_string_literal: true
module IssuablesHelper
include GitlabRoutingHelper
......@@ -167,8 +169,9 @@ module IssuablesHelper
end
def issuable_meta(issuable, project, text)
output = ""
output = []
output << "Opened #{time_ago_with_tooltip(issuable.created_at)} by ".html_safe
output << content_tag(:strong) do
author_output = link_to_member(project, issuable.author, size: 24, mobile_classes: "d-none d-sm-inline", tooltip: true)
author_output << link_to_member(project, issuable.author, size: 24, by_username: true, avatar: false, mobile_classes: "d-block d-sm-none")
......@@ -185,7 +188,7 @@ module IssuablesHelper
output << content_tag(:span, (issuable.task_status if issuable.tasks?), id: "task_status", class: "d-none d-sm-none d-md-inline-block")
output << content_tag(:span, (issuable.task_status_short if issuable.tasks?), id: "task_status_short", class: "d-md-none")
output.html_safe
output.join.html_safe
end
def issuable_todo(issuable)
......
# frozen_string_literal: true
module IssuesHelper
def issue_css_classes(issue)
classes = "issue"
classes << " closed" if issue.closed?
classes << " today" if issue.today?
classes
classes = ["issue"]
classes << "closed" if issue.closed?
classes << "today" if issue.today?
classes.join(' ')
end
# Returns an OpenStruct object suitable for use by <tt>options_from_collection_for_select</tt>
......@@ -105,8 +107,8 @@ module IssuesHelper
end
def link_to_discussions_to_resolve(merge_request, single_discussion = nil)
link_text = merge_request.to_reference
link_text += " (discussion #{single_discussion.first_note.id})" if single_discussion
link_text = [merge_request.to_reference]
link_text << "(discussion #{single_discussion.first_note.id})" if single_discussion
path = if single_discussion
Gitlab::UrlBuilder.build(single_discussion.first_note)
......@@ -115,7 +117,7 @@ module IssuesHelper
project_merge_request_path(project, merge_request)
end
link_to link_text, path
link_to link_text.join(' '), path
end
def show_new_issue_link?(project)
......
# frozen_string_literal: true
module JavascriptHelper
def page_specific_javascript_tag(js)
javascript_include_tag asset_path(js)
......
# frozen_string_literal: true
module KerberosSpnegoHelper
def allow_basic_auth?
true # different behavior in GitLab Enterprise Edition
......
# frozen_string_literal: true
module LabelsHelper
extend self
include ActionView::Helpers::TagHelper
......
# frozen_string_literal: true
module LazyImageTagHelper
def placeholder_image
"data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
......@@ -11,9 +13,11 @@ module LazyImageTagHelper
options[:data] ||= {}
options[:data][:src] = path_to_image(source)
options[:class] ||= ""
options[:class] << " lazy"
# options[:class] can be either String or Array.
klass_opts = Array.wrap(options[:class])
klass_opts << "lazy"
options[:class] = klass_opts.join(' ')
source = placeholder_image
end
......
# frozen_string_literal: true
require 'nokogiri'
module MarkupHelper
......
# frozen_string_literal: true
module MattermostHelper
def mattermost_teams_options(teams)
teams.map do |team|
......
# frozen_string_literal: true
module MembersHelper
def remove_member_message(member, user: nil)
user = current_user if defined?(current_user)
text = 'Are you sure you want to'
text = 'Are you sure you want to '
action =
if member.request?
if member.user == user
......@@ -16,13 +18,12 @@ module MembersHelper
"remove #{member.user.name} from"
end
text << action << " the #{member.source.human_name} #{member.real_source_type.humanize(capitalize: false)}?"
"#{text} #{action} the #{member.source.human_name} #{member.real_source_type.humanize(capitalize: false)}?"
end
def remove_member_title(member)
text = " from #{member.real_source_type.humanize(capitalize: false)}"
text.prepend(member.request? ? 'Deny access request' : 'Remove user')
action = member.request? ? 'Deny access request' : 'Remove user'
"#{action} from #{member.real_source_type.humanize(capitalize: false)}"