summaryrefslogtreecommitdiff
path: root/app/helpers/application_helper.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2016-06-20 18:57:10 +0200
committerDouwe Maan <douwe@selenight.nl>2016-07-06 18:50:59 -0400
commit375193455aa5cb752f1035a6cc69160170a58477 (patch)
treee54ec42a455c02ab61ead34268841ef19ae339b4 /app/helpers/application_helper.rb
parent4c1bf77c7fd3e62be4b9f6fd54520db0f7fc346b (diff)
downloadgitlab-ce-375193455aa5cb752f1035a6cc69160170a58477.tar.gz
Style diff and blob file headers the same way
Diffstat (limited to 'app/helpers/application_helper.rb')
-rw-r--r--app/helpers/application_helper.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 62d13a4b4f3..03495cf5ec4 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -306,4 +306,15 @@ module ApplicationHelper
def truncate_first_line(message, length = 50)
truncate(message.each_line.first.chomp, length: length) if message
end
+
+ # While similarly named to Rails's `link_to_if`, this method behaves quite differently.
+ # If `condition` is truthy, a link will be returned with the result of the block
+ # as its body. If `condition` is falsy, only the result of the block will be returned.
+ def conditional_link_to(condition, options, html_options = {}, &block)
+ if condition
+ link_to options, html_options, &block
+ else
+ capture(&block)
+ end
+ end
end