add-external-class-to-cf-link-v2.diff

Go MAEDA, 2017-11-28 17:09

Download (9.45 KB)

View differences:

lib/redmine/field_format.rb (working copy)
248 248
            url = url_from_pattern(custom_field, single_value, customized)
249 249
            [text, url]
250 250
          end
251
          links = texts_and_urls.sort_by(&:first).map {|text, url| view.link_to_if uri_with_safe_scheme?(url), text, url}
251
          links = texts_and_urls.sort_by(&:first).map do |text, url|
252
            css_class = (url =~ /^https?:\/\//) ? 'external' : nil
253
            view.link_to_if uri_with_safe_scheme?(url), text, url, :class => css_class
254
          end
252 255
          links.join(', ').html_safe
253 256
        else
254 257
          casted
......
442 445
              url = "http://" + url
443 446
            end
444 447
          end
445
          view.link_to value.to_s.truncate(40), url
448
          css_class = (url =~ /^https?:\/\//) ? 'external' : nil
449
          view.link_to value.to_s.truncate(40), url, :class => css_class
446 450
        else
447 451
          value.to_s
448 452
        end
test/unit/lib/redmine/field_format/field_format_test.rb (working copy)
72 72
    custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "bar")
73 73

  
74 74
    assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
75
    assert_equal '<a href="http://foo/bar">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
75
    assert_equal '<a class="external" href="http://foo/bar">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
76 76
  end
77 77

  
78 78
  def test_text_field_with_url_pattern_and_value_containing_a_space_should_format_as_link
......
80 80
    custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "foo bar")
81 81

  
82 82
    assert_equal "foo bar", field.format.formatted_custom_value(self, custom_value, false)
83
    assert_equal '<a href="http://foo/foo%20bar">foo bar</a>', field.format.formatted_custom_value(self, custom_value, true)
83
    assert_equal '<a class="external" href="http://foo/foo%20bar">foo bar</a>', field.format.formatted_custom_value(self, custom_value, true)
84 84
  end
85 85

  
86 86
  def test_text_field_with_url_pattern_should_not_encode_url_pattern
......
88 88
    custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "1")
89 89

  
90 90
    assert_equal "1", field.format.formatted_custom_value(self, custom_value, false)
91
    assert_equal '<a href="http://foo/bar#anchor">1</a>', field.format.formatted_custom_value(self, custom_value, true)
91
    assert_equal '<a class="external" href="http://foo/bar#anchor">1</a>', field.format.formatted_custom_value(self, custom_value, true)
92 92
  end
93 93

  
94 94
  def test_text_field_with_url_pattern_should_encode_values
......
96 96
    custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "foo bar")
97 97

  
98 98
    assert_equal "foo bar", field.format.formatted_custom_value(self, custom_value, false)
99
    assert_equal '<a href="http://foo/foo%20bar#anchor">foo bar</a>', field.format.formatted_custom_value(self, custom_value, true)
99
    assert_equal '<a class="external" href="http://foo/foo%20bar#anchor">foo bar</a>', field.format.formatted_custom_value(self, custom_value, true)
100 100
  end
101 101
end
test/unit/lib/redmine/field_format/link_format_test.rb (working copy)
24 24
    custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "bar")
25 25

  
26 26
    assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
27
    assert_equal '<a href="http://foo/bar">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
27
    assert_equal '<a class="external" href="http://foo/bar">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
28 28
  end
29 29

  
30 30
  def test_link_field_should_substitute_object_id_in_url
......
35 35
    custom_value = CustomValue.new(:custom_field => field, :customized => object, :value => "bar")
36 36

  
37 37
    assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
38
    assert_equal '<a href="http://foo/10">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
38
    assert_equal '<a class="external" href="http://foo/10">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
39 39
  end
40 40

  
41 41
  def test_link_field_should_substitute_project_id_in_url
......
48 48
    custom_value = CustomValue.new(:custom_field => field, :customized => object, :value => "bar")
49 49

  
50 50
    assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
51
    assert_equal '<a href="http://foo/52">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
51
    assert_equal '<a class="external" href="http://foo/52">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
52 52
  end
53 53

  
54 54
  def test_link_field_should_substitute_project_identifier_in_url
......
61 61
    custom_value = CustomValue.new(:custom_field => field, :customized => object, :value => "bar")
62 62

  
63 63
    assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
64
    assert_equal '<a href="http://foo/foo_project-00">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
64
    assert_equal '<a class="external" href="http://foo/foo_project-00">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
65 65
  end
66 66

  
67 67
  def test_link_field_should_substitute_regexp_groups
......
69 69
    custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "56-142")
70 70

  
71 71
    assert_equal "56-142", field.format.formatted_custom_value(self, custom_value, false)
72
    assert_equal '<a href="http://foo/142/56">56-142</a>', field.format.formatted_custom_value(self, custom_value, true)
72
    assert_equal '<a class="external" href="http://foo/142/56">56-142</a>', field.format.formatted_custom_value(self, custom_value, true)
73 73
  end
74 74

  
75 75
  def test_link_field_without_url_pattern_should_link_to_value
......
77 77
    custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "http://foo/bar")
78 78

  
79 79
    assert_equal "http://foo/bar", field.format.formatted_custom_value(self, custom_value, false)
80
    assert_equal '<a href="http://foo/bar">http://foo/bar</a>', field.format.formatted_custom_value(self, custom_value, true)
80
    assert_equal '<a class="external" href="http://foo/bar">http://foo/bar</a>', field.format.formatted_custom_value(self, custom_value, true)
81 81
  end
82 82

  
83 83
  def test_link_field_without_url_pattern_should_link_to_value_with_http_by_default
......
85 85
    custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "foo.bar")
86 86

  
87 87
    assert_equal "foo.bar", field.format.formatted_custom_value(self, custom_value, false)
88
    assert_equal '<a href="http://foo.bar">foo.bar</a>', field.format.formatted_custom_value(self, custom_value, true)
88
    assert_equal '<a class="external" href="http://foo.bar">foo.bar</a>', field.format.formatted_custom_value(self, custom_value, true)
89 89
  end
90 90
end
test/unit/lib/redmine/field_format/list_format_test.rb (working copy)
131 131
  def test_field_with_url_pattern_should_link_value
132 132
    field = IssueCustomField.new(:field_format => 'list', :url_pattern => 'http://localhost/%value%')
133 133
    formatted = field.format.formatted_value(self, field, 'foo', Issue.new, true)
134
    assert_equal '<a href="http://localhost/foo">foo</a>', formatted
134
    assert_equal '<a class="external" href="http://localhost/foo">foo</a>', formatted
135 135
    assert formatted.html_safe?
136 136
  end
137 137

  
138 138
  def test_field_with_url_pattern_and_multiple_values_should_link_values
139 139
    field = IssueCustomField.new(:field_format => 'list', :url_pattern => 'http://localhost/%value%')
140 140
    formatted = field.format.formatted_value(self, field, ['foo', 'bar'], Issue.new, true)
141
    assert_equal '<a href="http://localhost/bar">bar</a>, <a href="http://localhost/foo">foo</a>', formatted
141
    assert_equal '<a class="external" href="http://localhost/bar">bar</a>, <a class="external" href="http://localhost/foo">foo</a>', formatted
142 142
    assert formatted.html_safe?
143 143
  end
144 144

  
test/unit/lib/redmine/field_format/numeric_format_test.rb (working copy)
26 26
    custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "3")
27 27

  
28 28
    assert_equal 3, field.format.formatted_custom_value(self, custom_value, false)
29
    assert_equal '<a href="http://foo/3">3</a>', field.format.formatted_custom_value(self, custom_value, true)
29
    assert_equal '<a class="external" href="http://foo/3">3</a>', field.format.formatted_custom_value(self, custom_value, true)
30 30
  end
31 31
end