From c9fc2e9aa86d6ef109b1ce31bf9a4adfef3489fa Mon Sep 17 00:00:00 2001 From: fatkodima Date: Thu, 10 Oct 2024 15:52:32 +0300 Subject: [PATCH] Truncate long file names in web ui --- lib/coverband/utils/html_formatter.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/coverband/utils/html_formatter.rb b/lib/coverband/utils/html_formatter.rb index 7e5bedb1..562337b5 100644 --- a/lib/coverband/utils/html_formatter.rb +++ b/lib/coverband/utils/html_formatter.rb @@ -169,7 +169,16 @@ def shortened_filename(source_file) def link_to_source_file(source_file) data_loader_url = "#{base_path}load_file_details?filename=#{source_file.filename}" - %(#{shortened_filename source_file}) + %(#{truncate(shortened_filename(source_file))}) + end + + def truncate(text, length: 50) + if text.length <= length + text + else + omission = "..." + "#{text[0, length - omission.length]}#{omission}" + end end end end