Class: Redmine::FieldFormat::LinkFormat

Inherits:
StringFormat show all
Defined in:
lib/redmine/field_format.rb

Instance Method Summary collapse

Methods inherited from Unbounded

#validate_single_value

Methods inherited from Base

#after_save_custom_value, #before_custom_field_save, #bulk_edit_tag, #cast_custom_value, #cast_single_value, #cast_value, #edit_tag, field_attributes, #formatted_custom_value, #group_statement, #join_for_order_statement, #label, #name, #order_statement, #possible_custom_value_options, #possible_values_options, #query_filter_options, #set_custom_field_value, #target_class, #validate_custom_field, #validate_custom_value, #validate_single_value, #value_from_keyword

Methods included from Helpers::URL

#uri_with_link_safe_scheme?, #uri_with_safe_scheme?

Methods included from I18n

#current_language, #day_letter, #day_name, #find_language, #format_date, #format_hours, #format_time, included, #l, #l_hours, #l_hours_short, #l_or_humanize, #languages_options, #ll, #lu, #month_name, #set_language_if_valid, #valid_languages

Instance Method Details

#formatted_value(view, custom_field, value, customized = nil, html = false) ⇒ Object



455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# File 'lib/redmine/field_format.rb', line 455

def formatted_value(view, custom_field, value, customized=nil, html=false)
  if html && value.present?
    if custom_field.url_pattern.present?
      url = url_from_pattern(custom_field, value, customized)
    else
      url = value.to_s
      unless %r{\A[a-z]+://}i.match?(url)
        # no protocol found, use http by default
        url = "http://" + url
      end
    end
    css_class = (/^https?:\/\//.match?(url)) ? 'external' : nil
    view.link_to value.to_s.truncate(40), url, :class => css_class
  else
    value.to_s
  end
end