From 252a605a6d99acff575f63c18ccedccf79e312cf Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Fri, 11 Dec 2020 14:17:35 +0000 Subject: [PATCH] shorten long line of ApplicationHelper git-svn-id: http://svn.redmine.org/redmine/trunk@20622 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/application_helper.rb | 178 ++++++++++++++++++++---------- 1 file changed, 118 insertions(+), 60 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 38cd405ae..394f9b666 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -44,7 +44,9 @@ module ApplicationHelper # @param [optional, Hash] html_options Options passed to link_to # @param [optional, Hash] parameters_for_method_reference Extra parameters for link_to def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference) - link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action]) + if authorize_for(options[:controller] || params[:controller], options[:action]) + link_to(name, options, html_options, *parameters_for_method_reference) + end end # Displays a link to user's account page if active @@ -194,16 +196,22 @@ module ApplicationHelper end RECORD_LINK = { - 'CustomValue' => ->(custom_value) {link_to_record(custom_value.customized)}, - 'Document' => ->(document) {link_to(document.title, document_path(document))}, - 'Group' => ->(group) {link_to(group.name, group_path(group))}, - 'Issue' => ->(issue) {link_to_issue(issue, :subject => false)}, - 'Message' => ->(message) {link_to_message(message)}, - 'News' => ->(news) {link_to(news.title, news_path(news))}, - 'Project' => ->(project) {link_to_project(project)}, - 'User' => ->(user) {link_to_user(user)}, - 'Version' => ->(version) {link_to_version(version)}, - 'WikiPage' => ->(wiki_page) {link_to(wiki_page.pretty_title, project_wiki_page_path(wiki_page.project, wiki_page.title))} + 'CustomValue' => lambda {|custom_value| link_to_record(custom_value.customized)}, + 'Document' => lambda {|document| link_to(document.title, document_path(document))}, + 'Group' => lambda {|group| link_to(group.name, group_path(group))}, + 'Issue' => lambda {|issue| link_to_issue(issue, :subject => false)}, + 'Message' => lambda {|message| link_to_message(message)}, + 'News' => lambda {|news| link_to(news.title, news_path(news))}, + 'Project' => lambda {|project| link_to_project(project)}, + 'User' => lambda {|user| link_to_user(user)}, + 'Version' => lambda {|version| link_to_version(version)}, + 'WikiPage' => + lambda do |wiki_page| + link_to( + wiki_page.pretty_title, + project_wiki_page_path(wiki_page.project, wiki_page.title) + ) + end } def link_to_record(record) @@ -215,8 +223,10 @@ module ApplicationHelper ATTACHMENT_CONTAINER_LINK = { # Custom list, since project/version attachments are listed in the files # view and not in the project/milestone view - 'Project' => ->(project) {link_to(l(:project_module_files), project_files_path(project))}, - 'Version' => ->(version) {link_to(l(:project_module_files), project_files_path(version.project))}, + 'Project' => + lambda {|project| link_to(l(:project_module_files), project_files_path(project))}, + 'Version' => + lambda {|version| link_to(l(:project_module_files), project_files_path(version.project))}, } def link_to_attachment_container(attachment_container) @@ -287,7 +297,8 @@ module ApplicationHelper end def wiki_page_path(page, options={}) - url_for({:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title}.merge(options)) + url_for({:controller => 'wiki', :action => 'show', :project_id => page.project, + :id => page.title}.merge(options)) end def thumbnail_tag(attachment) @@ -399,7 +410,7 @@ module ApplicationHelper # set the project environment to please macros. @project = project if ancestors.empty? || project.is_descendant_of?(ancestors.last) - s << "