summaryrefslogtreecommitdiffstats
path: root/app/helpers/application_helper.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/helpers/application_helper.rb')
-rw-r--r--app/helpers/application_helper.rb64
1 files changed, 42 insertions, 22 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index fe250f7f3..ab418fb38 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -128,7 +128,7 @@ module ApplicationHelper
# * :download - Force download (default: false)
def link_to_attachment(attachment, options={})
text = options.delete(:text) || attachment.filename
- icon = options.fetch(:icon, false)
+ icon = options.delete(:icon)
if options.delete(:download)
route_method = :download_named_attachment_url
@@ -346,18 +346,18 @@ module ApplicationHelper
def thumbnail_tag(attachment)
thumbnail_size = Setting.thumbnails_size.to_i
thumbnail_path = thumbnail_path(attachment, :size => thumbnail_size * 2)
- link_to(
- image_tag(
- thumbnail_path,
- :srcset => "#{thumbnail_path} 2x",
- :style => "max-width: #{thumbnail_size}px; max-height: #{thumbnail_size}px;",
- :title => attachment.filename,
- :loading => "lazy"
- ),
- attachment_path(
- attachment
+ tag.div class: 'thumbnail', title: attachment.filename do
+ link_to(
+ image_tag(
+ thumbnail_path,
+ :srcset => "#{thumbnail_path} 2x",
+ :style => "max-width: #{thumbnail_size}px; max-height: #{thumbnail_size}px;",
+ :alt => attachment.filename,
+ :loading => "lazy"
+ ),
+ attachment_path(attachment)
)
- )
+ end
end
def toggle_link(name, id, options={})
@@ -414,8 +414,16 @@ module ApplicationHelper
end
def format_activity_description(text)
- h(text.to_s.truncate(120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...')).
- gsub(/[\r\n]+/, "<br />").html_safe
+ h(
+ # Limit input to avoid regex performance issues
+ text.to_s.slice(0, 10240)
+ # Abbreviate consecutive quoted lines as '> ...', keeping the first line
+ .gsub(%r{(^>.*?(?:\r?\n))(?:>.*?(?:\r?\n)+)+}m, "\\1> ...\n")
+ # Remove all content following the first <pre> or <code> tag
+ .sub(%r{[\r\n]*<(pre|code)>.*$}m, '')
+ # Truncate the description to a specified length and append '...'
+ .truncate(240)
+ ).gsub(/[\r\n]+/, "<br>").html_safe
end
def format_version_name(version)
@@ -428,7 +436,7 @@ module ApplicationHelper
def format_changeset_comments(changeset, options={})
method = options[:short] ? :short_comments : :comments
- textilizable changeset, method, :formatting => Setting.commit_logs_formatting?
+ textilizable changeset, method, project: changeset.project, formatting: Setting.commit_logs_formatting?
end
def due_date_distance_in_words(date)
@@ -510,7 +518,9 @@ module ApplicationHelper
def render_flash_messages
s = +''
flash.each do |k, v|
- s << content_tag('div', v.html_safe, :class => "flash #{k}", :id => "flash_#{k}")
+ next unless v.is_a?(String)
+
+ s << content_tag('div', notice_icon(k) + v.html_safe, :class => "flash #{k}", :id => "flash_#{k}")
end
s.html_safe
end
@@ -781,7 +791,7 @@ module ApplicationHelper
end
def other_formats_links(&)
- concat('<p class="other-formats">'.html_safe + l(:label_export_to))
+ concat('<p class="other-formats hide-when-print">'.html_safe + l(:label_export_to))
yield Redmine::Views::OtherFormatsBuilder.new(self)
concat('</p>'.html_safe)
end
@@ -1378,7 +1388,7 @@ module ApplicationHelper
<|
$)
}x
- HEADING_RE = /(<h(\d)( [^>]+)?>(.+?)<\/h(\d)>)/i unless const_defined?(:HEADING_RE)
+ HEADING_RE = /(<h(\d)( [^>]+)?>(.+?)<\/h(\d)>)/im unless const_defined?(:HEADING_RE)
def parse_sections(text, project, obj, attr, only_path, options)
return unless options[:edit_section_links]
@@ -1568,7 +1578,9 @@ module ApplicationHelper
def render_error_messages(errors)
html = +""
if errors.present?
- html << "<div id='errorExplanation'><ul>\n"
+ html << "<div id='errorExplanation'>\n"
+ html << notice_icon('error')
+ html << "<ul>\n"
errors.each do |error|
html << "<li>#{h error}</li>\n"
end
@@ -1597,7 +1609,7 @@ module ApplicationHelper
# Helper to render JSON in views
def raw_json(arg)
- arg.to_json.to_s.gsub('/', '\/').html_safe
+ arg.to_json.gsub('/', '\/').html_safe
end
def back_url_hidden_field_tag
@@ -1795,7 +1807,7 @@ module ApplicationHelper
if Setting.wiki_tablesort_enabled?
tags << javascript_include_tag('tablesort-5.2.1.min.js', 'tablesort-5.2.1.number.min.js')
end
- tags << javascript_include_tag('application', 'responsive')
+ tags << javascript_include_tag('application-legacy', 'responsive')
unless User.current.pref.warn_on_leaving_unsaved == '0'
warn_text = escape_javascript(l(:text_warn_on_leaving_unsaved))
tags <<
@@ -1907,6 +1919,14 @@ module ApplicationHelper
end
end
+ def heads_for_i18n
+ javascript_tag(
+ "rm = window.rm || {};" \
+ "rm.I18n = rm.I18n || {};" \
+ "rm.I18n = Object.freeze({buttonCopy: '#{l(:button_copy)}'});"
+ )
+ end
+
def heads_for_auto_complete(project)
data_sources = autocomplete_data_sources(project)
javascript_tag(
@@ -1924,7 +1944,7 @@ module ApplicationHelper
def copy_object_url_link(url)
link_to_function(
- sprite_icon('copy-link', l(:button_copy_link)), 'copyTextToClipboard(this);',
+ sprite_icon('copy-link', l(:button_copy_link)), 'copyDataClipboardTextToClipboard(this);',
class: 'icon icon-copy-link',
data: {'clipboard-text' => url}
)