Feature #39997 » 0001-Refactor-ApplicationHelper-format_object-to-support-.patch
| app/helpers/application_helper.rb | ||
|---|---|---|
|
end
|
||
|
# Helper that formats object for html or text rendering
|
||
|
def format_object(object, html=true, &block)
|
||
|
# Options:
|
||
|
# * :html - If true, format the object as HTML (default: true)
|
||
|
def format_object(object, *args, &block)
|
||
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
||
|
html =
|
||
|
if args[0].nil?
|
||
|
options.fetch(:html, true)
|
||
|
else
|
||
|
# Still supports the deprecated syntax `format_object(object, true/false)`
|
||
|
# TODO: Remove this in the future version
|
||
|
ActiveSupport::Deprecation.warn(
|
||
|
'The old syntax `format_object(object, true/false)` will be removed in Redmine 7.0.' \
|
||
|
'Use `format_object(object, html: true/false)` instead.'
|
||
|
)
|
||
|
args[0]
|
||
|
end
|
||
|
if block
|
||
|
object = yield object
|
||
|
end
|
||
|
case object
|
||
|
when Array
|
||
|
formatted_objects = object.map {|o| format_object(o, html)}
|
||
|
formatted_objects = object.map {|o| format_object(o, html: html)}
|
||
|
html ? safe_join(formatted_objects, ', ') : formatted_objects.join(', ')
|
||
|
when Time, ActiveSupport::TimeWithZone
|
||
|
format_time(object)
|
||
| ... | ... | |
|
if f.nil? || f.is_a?(String)
|
||
|
f
|
||
|
else
|
||
|
format_object(f, html, &block)
|
||
|
format_object(f, html: html, &block)
|
||
|
end
|
||
|
else
|
||
|
object.value.to_s
|
||
| app/helpers/custom_fields_helper.rb | ||
|---|---|---|
|
# Return a string used to display a custom value
|
||
|
def show_value(custom_value, html=true)
|
||
|
format_object(custom_value, html)
|
||
|
format_object(custom_value, html: html)
|
||
|
end
|
||
|
# Return a string used to display a custom value
|
||
|
def format_value(value, custom_field)
|
||
|
format_object(custom_field.format.formatted_value(self, custom_field, value, false), false)
|
||
|
format_object(custom_field.format.formatted_value(self, custom_field, value, false), html: false)
|
||
|
end
|
||
|
# Return an array of custom field formats which can be used in select_tag
|
||
| app/helpers/queries_helper.rb | ||
|---|---|---|
|
when :watcher_users
|
||
|
value.to_a.join("\n")
|
||
|
else
|
||
|
format_object(value, false) do |value|
|
||
|
format_object(value, html: false) do |value|
|
||
|
case value.class.name
|
||
|
when 'Float'
|
||
|
sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator))
|
||
| app/helpers/roles_helper.rb | ||
|---|---|---|
|
]
|
||
|
fields = names + roles.collect do |role|
|
||
|
if role.setable_permissions.include?(p)
|
||
|
format_object(role.permissions.include?(p.name), false)
|
||
|
format_object(role.permissions.include?(p.name), html: false)
|
||
|
else
|
||
|
''
|
||
|
end
|
||
| app/helpers/timelog_helper.rb | ||
|---|---|---|
|
"##{obj.id}"
|
||
|
end
|
||
|
else
|
||
|
format_object(obj, html)
|
||
|
format_object(obj, html: html)
|
||
|
end
|
||
|
elsif cf = criteria_options[:custom_field]
|
||
|
format_value(value, cf)
|
||
| lib/redmine/field_format.rb | ||
|---|---|---|
|
casted = cast_value(custom_field, value, customized)
|
||
|
if html && custom_field.url_pattern.present?
|
||
|
texts_and_urls = Array.wrap(casted).map do |single_value|
|
||
|
text = view.format_object(single_value, false).to_s
|
||
|
text = view.format_object(single_value, html: false).to_s
|
||
|
url = url_from_pattern(custom_field, single_value, customized)
|
||
|
[text, url]
|
||
|
end
|
||
| test/unit/lib/redmine/field_format/numeric_format_test.rb | ||
|---|---|---|
|
to_test = {'en' => '1234.56', 'de' => '1234,56'}
|
||
|
to_test.each do |locale, expected|
|
||
|
with_locale locale do
|
||
|
assert_equal expected, format_object(issue.reload.custom_field_values.last, false)
|
||
|
assert_equal expected, format_object(issue.reload.custom_field_values.last, html: false)
|
||
|
end
|
||
|
end
|
||
|
end
|
||