Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rubocop offenses in app/helpers #6442

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/helpers/admin_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module AdminHelper
end
56 changes: 26 additions & 30 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ApplicationHelper
# returns true if user is logged in and has any of the roles given, as ['admin','moderator']
def logged_in_as(roles)
Expand All @@ -7,13 +9,13 @@ def logged_in_as(roles)
end

def emojify(content)
if content.present?
content.to_str.gsub(/:([\w+-]+):(?![^\[]*\])/) do |match|
if emoji = Emoji.find_by_alias(Regexp.last_match(1))
emoji.raw || %(<img class="emoji" alt="#{Regexp.last_match(1)}" src="#{image_path("emoji/#{emoji.image_filename}")}" style="vertical-align:middle" width="20" height="20" />)
else
match
end
return unless content.present?

content.to_str.gsub(/:([\w+-]+):(?![^\[]*\])/) do |match|
if (emoji = Emoji.find_by_alias(Regexp.last_match(1)))
emoji.raw || %(<img class="emoji" alt="#{Regexp.last_match(1)}" src="#{image_path("emoji/#{emoji.image_filename}")}" style="vertical-align:middle" width="20" height="20" />)
else
match
end
end
end
Expand All @@ -32,34 +34,30 @@ def emoji_names_list
end

def emoji_info
emoji_names = ["thumbs-up", "thumbs-down", "laugh", "hooray", "confused", "heart"]
emoji_names = %w(thumbs-up thumbs-down laugh hooray confused heart)
emoji_image_map = {
"thumbs-up" => "https://github.githubassets.com/images/icons/emoji/unicode/1f44d.png",
"thumbs-down" => "https://github.githubassets.com/images/icons/emoji/unicode/1f44e.png",
"laugh" => "https://github.githubassets.com/images/icons/emoji/unicode/1f604.png",
"hooray" => "https://github.githubassets.com/images/icons/emoji/unicode/1f389.png",
"confused" => "https://github.githubassets.com/images/icons/emoji/unicode/1f615.png",
"heart" => "https://github.githubassets.com/images/icons/emoji/unicode/2764.png"
'thumbs-up' => 'https://github.githubassets.com/images/icons/emoji/unicode/1f44d.png',
'thumbs-down' => 'https://github.githubassets.com/images/icons/emoji/unicode/1f44e.png',
'laugh' => 'https://github.githubassets.com/images/icons/emoji/unicode/1f604.png',
'hooray' => 'https://github.githubassets.com/images/icons/emoji/unicode/1f389.png',
'confused' => 'https://github.githubassets.com/images/icons/emoji/unicode/1f615.png',
'heart' => 'https://github.githubassets.com/images/icons/emoji/unicode/2764.png'
}
[emoji_names, emoji_image_map]
end

def feature(title)
features = Node.where(type: 'feature', title: title)
if !features.empty?
return features.last.body.to_s.html_safe
else
''
end
return features.last.body.to_s.html_safe unless features.empty?

''
end

def feature_node(title)
features = Node.where(type: 'feature', title: title)
if !features.empty?
return features.last
else
''
end
return features.last unless features.empty?

''
end

def locale_name_pairs
Expand Down Expand Up @@ -101,11 +99,11 @@ def render_top_map(lat, lon)
# we should move this to the Comment model:
# replaces inline title suggestion(e.g: {New Title}) with the required link to change the title
def title_suggestion(comment)
comment.body.gsub(/\[propose:title\](.*?)\[\/propose\]/) do
comment.body.gsub(%r{\[propose:title\](.*?)\[/propose\]}) do
a = ActionController::Base.new
is_creator = ((defined? current_user) && current_user == Node.find(comment.nid).author) == true
title = Regexp.last_match(1)
output = a.render_to_string(template: "notes/_title_suggestion",
output = a.render_to_string(template: 'notes/_title_suggestion',
layout: false,
locals: {
user: comment.user.name,
Expand All @@ -118,9 +116,7 @@ def title_suggestion(comment)
end

def filtered_comment_body(comment_body)
if contain_trimmed_body?(comment_body)
return comment_body.split(Comment::COMMENT_FILTER).first
end
return comment_body.split(Comment::COMMENT_FILTER).first if contain_trimmed_body?(comment_body)

comment_body
end
Expand All @@ -142,7 +138,7 @@ def translation(key, options = {})
options[:fallback] = false
translated_string2 = t(key, options)

if current_user&.has_tag('translation-helper') && translated_string2.include?("translation missing") && !translated_string.include?("<")
if current_user&.has_tag('translation-helper') && translated_string2.include?('translation missing') && !translated_string.include?('<')
%(<span>#{translated_string} <a href="https://www.transifex.com/publiclab/publiclaborg/translate/#de/$?q=text%3A#{translated_string}">
<i data-toggle='tooltip' data-placement='top' title='Needs translation? Click to help translate this text.' style='position:relative; right:2px; color:#bbb; font-size: 15px;' class='fa fa-globe'></i></a>
</span>)
Expand Down
12 changes: 6 additions & 6 deletions app/helpers/comment_helper.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# frozen_string_literal: true

module CommentHelper
class CommentError < ArgumentError
end

def create_comment(node, user, body)
@comment = node.add_comment(uid: user.uid, body: body)
if user && @comment.save
@comment.notify user
return @comment
else
raise CommentError
end
raise CommentError unless user && @comment.save

@comment.notify user
@comment
end
end
2 changes: 2 additions & 0 deletions app/helpers/csvfiles_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module CsvfilesHelper
end
2 changes: 2 additions & 0 deletions app/helpers/features_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module FeaturesHelper
end
2 changes: 2 additions & 0 deletions app/helpers/home_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module HomeHelper
end
2 changes: 2 additions & 0 deletions app/helpers/map_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module MapHelper
end
2 changes: 2 additions & 0 deletions app/helpers/notes_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module NotesHelper
end
2 changes: 2 additions & 0 deletions app/helpers/openid_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module OpenidHelper
def url_for_user
'/profile/' + current_user.username
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/redirect_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module RedirectHelper
end
26 changes: 14 additions & 12 deletions app/helpers/search_helper.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# frozen_string_literal: true

module SearchHelper
def create_nav_links(active_page, query)
links = [
{ section: "search-all", text: "Content", path: "/search/#{query}" },
{ section: "search-profiles", text: "People", path: "/search/profiles/#{query}" }
{ section: 'search-all', text: 'Content', path: "/search/#{query}" },
{ section: 'search-profiles', text: 'People', path: "/search/profiles/#{query}" }
]

result = ""
result = ''
links.each do |link|
active_link =
if active_page == link[:section]
"list-group-item list-group-item-action active"
'list-group-item list-group-item-action active'
else
"list-group-item list-group-item-action"
'list-group-item list-group-item-action'
end
result += " <li><a href='#{link[:path]}' class='#{active_link}'>#{link[:text]}</a> </li>"
end
Expand All @@ -20,19 +22,19 @@ def create_nav_links(active_page, query)

def create_nav_links_for_by_type(active_page, query)
links = [
{ section: "search-all", text: "All content types", path: "/search/content/#{query}" },
{ section: "search-questions", text: "Questions", path: "/search/questions/#{query}" },
{ section: "search-notes", text: "Notes", path: "/search/notes/#{query}" },
{ section: "search-wikis", text: "Wikis", path: "/search/wikis/#{query}" }
{ section: 'search-all', text: 'All content types', path: "/search/content/#{query}" },
{ section: 'search-questions', text: 'Questions', path: "/search/questions/#{query}" },
{ section: 'search-notes', text: 'Notes', path: "/search/notes/#{query}" },
{ section: 'search-wikis', text: 'Wikis', path: "/search/wikis/#{query}" }
]

result = ""
result = ''
links.each do |link|
active_link =
if active_page == link[:section]
"dropdown-item active"
'dropdown-item active'
else
"dropdown-item"
'dropdown-item'
end
result += " <a href='#{link[:path]}' class='#{active_link}'>#{link[:text]}</a>"
end
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/tag_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module TagHelper
end
6 changes: 3 additions & 3 deletions app/helpers/user_tags_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

module UserTagsHelper
def fetch_tags(uid, type)
tag_types = %w(skill gear role tool)
tags = []
if tag_types.include? type
tags = UserTag.where(uid: uid).where('value LIKE ?', type + ':' + '%')
end
tags = UserTag.where(uid: uid).where('value LIKE ?', type + ':' + '%') if tag_types.include? type
tags
end
end
2 changes: 2 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module UsersHelper
end
2 changes: 2 additions & 0 deletions app/helpers/wiki_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module WikiHelper
end