Feature #39997 » 0001-Refactor-ApplicationHelper-format_object-to-support-.patch
app/helpers/application_helper.rb | ||
---|---|---|
251 | 251 |
end |
252 | 252 | |
253 | 253 |
# Helper that formats object for html or text rendering |
254 |
def format_object(object, html=true, &block) |
|
254 |
# Options: |
|
255 |
# * :html - If true, format the object as HTML (default: true) |
|
256 |
def format_object(object, *args, &block) |
|
257 |
options = args.last.is_a?(Hash) ? args.pop : {} |
|
258 |
html = |
|
259 |
if args[0].nil? |
|
260 |
options.fetch(:html, true) |
|
261 |
else |
|
262 |
# Still supports the deprecated syntax `format_object(object, true/false)` |
|
263 |
# TODO: Remove this in the future version |
|
264 |
ActiveSupport::Deprecation.warn( |
|
265 |
'The old syntax `format_object(object, true/false)` will be removed in Redmine 7.0.' \ |
|
266 |
'Use `format_object(object, html: true/false)` instead.' |
|
267 |
) |
|
268 |
args[0] |
|
269 |
end |
|
270 | ||
255 | 271 |
if block |
256 | 272 |
object = yield object |
257 | 273 |
end |
258 | 274 |
case object |
259 | 275 |
when Array |
260 |
formatted_objects = object.map {|o| format_object(o, html)} |
|
276 |
formatted_objects = object.map {|o| format_object(o, html: html)}
|
|
261 | 277 |
html ? safe_join(formatted_objects, ', ') : formatted_objects.join(', ') |
262 | 278 |
when Time, ActiveSupport::TimeWithZone |
263 | 279 |
format_time(object) |
... | ... | |
302 | 318 |
if f.nil? || f.is_a?(String) |
303 | 319 |
f |
304 | 320 |
else |
305 |
format_object(f, html, &block) |
|
321 |
format_object(f, html: html, &block)
|
|
306 | 322 |
end |
307 | 323 |
else |
308 | 324 |
object.value.to_s |
app/helpers/custom_fields_helper.rb | ||
---|---|---|
164 | 164 | |
165 | 165 |
# Return a string used to display a custom value |
166 | 166 |
def show_value(custom_value, html=true) |
167 |
format_object(custom_value, html) |
|
167 |
format_object(custom_value, html: html)
|
|
168 | 168 |
end |
169 | 169 | |
170 | 170 |
# Return a string used to display a custom value |
171 | 171 |
def format_value(value, custom_field) |
172 |
format_object(custom_field.format.formatted_value(self, custom_field, value, false), false) |
|
172 |
format_object(custom_field.format.formatted_value(self, custom_field, value, false), html: false)
|
|
173 | 173 |
end |
174 | 174 | |
175 | 175 |
# Return an array of custom field formats which can be used in select_tag |
app/helpers/queries_helper.rb | ||
---|---|---|
305 | 305 |
when :watcher_users |
306 | 306 |
value.to_a.join("\n") |
307 | 307 |
else |
308 |
format_object(value, false) do |value| |
|
308 |
format_object(value, html: false) do |value|
|
|
309 | 309 |
case value.class.name |
310 | 310 |
when 'Float' |
311 | 311 |
sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator)) |
app/helpers/roles_helper.rb | ||
---|---|---|
35 | 35 |
] |
36 | 36 |
fields = names + roles.collect do |role| |
37 | 37 |
if role.setable_permissions.include?(p) |
38 |
format_object(role.permissions.include?(p.name), false) |
|
38 |
format_object(role.permissions.include?(p.name), html: false)
|
|
39 | 39 |
else |
40 | 40 |
'' |
41 | 41 |
end |
app/helpers/timelog_helper.rb | ||
---|---|---|
84 | 84 |
"##{obj.id}" |
85 | 85 |
end |
86 | 86 |
else |
87 |
format_object(obj, html) |
|
87 |
format_object(obj, html: html)
|
|
88 | 88 |
end |
89 | 89 |
elsif cf = criteria_options[:custom_field] |
90 | 90 |
format_value(value, cf) |
lib/redmine/field_format.rb | ||
---|---|---|
250 | 250 |
casted = cast_value(custom_field, value, customized) |
251 | 251 |
if html && custom_field.url_pattern.present? |
252 | 252 |
texts_and_urls = Array.wrap(casted).map do |single_value| |
253 |
text = view.format_object(single_value, false).to_s |
|
253 |
text = view.format_object(single_value, html: false).to_s
|
|
254 | 254 |
url = url_from_pattern(custom_field, single_value, customized) |
255 | 255 |
[text, url] |
256 | 256 |
end |
test/unit/lib/redmine/field_format/numeric_format_test.rb | ||
---|---|---|
56 | 56 |
to_test = {'en' => '1234.56', 'de' => '1234,56'} |
57 | 57 |
to_test.each do |locale, expected| |
58 | 58 |
with_locale locale do |
59 |
assert_equal expected, format_object(issue.reload.custom_field_values.last, false) |
|
59 |
assert_equal expected, format_object(issue.reload.custom_field_values.last, html: false)
|
|
60 | 60 |
end |
61 | 61 |
end |
62 | 62 |
end |