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, html: false).to_s
|
|
253 |
text = custom_field.value_mask.present? ? value_from_pattern(custom_field, single_value) : 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
|
... | ... | |
258 |
258 |
view.link_to text, url
|
259 |
259 |
end
|
260 |
260 |
sanitize_html links.join(', ')
|
|
261 |
elsif html && custom_field.value_mask.present?
|
|
262 |
value_from_pattern(custom_field, single_value)
|
261 |
263 |
else
|
262 |
264 |
casted
|
263 |
265 |
end
|
... | ... | |
267 |
269 |
Redmine::WikiFormatting::HtmlSanitizer.call(html).html_safe
|
268 |
270 |
end
|
269 |
271 |
|
|
272 |
# Returns a value generated with the custom field Regex pattern
|
|
273 |
# %m1%, %m2%... => capture groups matches of the custom field regexp if defined
|
|
274 |
def value_from_pattern(custom_field, value)
|
|
275 |
val = custom_field.value_mask.to_s.dup
|
|
276 |
if custom_field.regexp.present?
|
|
277 |
val.gsub!(%r{%m(\d+)%}) do
|
|
278 |
m = $1.to_i
|
|
279 |
if matches ||= value.to_s.match(Regexp.new(custom_field.regexp))
|
|
280 |
val = matches[m].to_s
|
|
281 |
end
|
|
282 |
end
|
|
283 |
end
|
|
284 |
val
|
|
285 |
end
|
|
286 |
protected :value_from_pattern
|
|
287 |
|
270 |
288 |
# Returns an URL generated with the custom field URL pattern
|
271 |
289 |
# and variables substitution:
|
272 |
290 |
# %value% => the custom field value
|
... | ... | |
396 |
414 |
add 'string'
|
397 |
415 |
self.searchable_supported = true
|
398 |
416 |
self.form_partial = 'custom_fields/formats/string'
|
399 |
|
field_attributes :text_formatting
|
|
417 |
field_attributes :text_formatting, :value_mask
|
400 |
418 |
|
401 |
419 |
def formatted_value(view, custom_field, value, customized=nil, html=false)
|
402 |
420 |
if html
|
403 |
|
if custom_field.url_pattern.present?
|
|
421 |
if custom_field.url_pattern.present? || custom_field.value_mask.present?
|
404 |
422 |
super
|
405 |
423 |
elsif custom_field.text_formatting == 'full'
|
406 |
424 |
view.textilizable(value, :object => customized)
|