]> git.openstreetmap.org Git - rails.git/commitdiff
Added support for int_ref and _bg, _tx colours for all ref keys
authorŠtefan Baebler <stefan.baebler@gmail.com>
Tue, 6 Mar 2018 08:23:43 +0000 (09:23 +0100)
committerŠtefan Baebler <stefan.baebler@gmail.com>
Tue, 6 Mar 2018 08:23:43 +0000 (09:23 +0100)
Improves #1779

app/helpers/browse_helper.rb
test/helpers/browse_helper_test.rb

index 802858f74b7170e2d175bcb2f6f5e593526cd79f..8e0c7648f62c4b530b3794e7bf986c3135478dac 100644 (file)
@@ -192,7 +192,7 @@ module BrowseHelper
   end
 
   def colour_preview(key, value)
-    return nil unless key =~ /^(|building:|ref:|roof:)colour$/ && !value.nil?
+    return nil unless (key =~ /^(|building:|ref:|roof:)colour$/ || key =~ /^(int_)?ref:colour(_(bg|tx))?$/) && !value.nil?
     # does value look like a colour? ( 3 or 6 digit hex code or w3c colour name)
     w3c_colors =
       %w[aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue blueviolet brown burlywood cadetblue chartreuse chocolate coral cornflowerblue cornsilk crimson cyan darkblue darkcyan darkgoldenrod darkgray darkgrey darkgreen darkkhaki darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray
index 27e0e77095487854e6ff28c7bb296374f0750dc2..0c4f2b20302e7ea1d042eb6487168233d777ad5f 100644 (file)
@@ -375,6 +375,21 @@ class BrowseHelperTest < ActionView::TestCase
     colour = colour_preview("ref:colour", "#f00")
     assert_equal "#f00", colour
 
+    colour = colour_preview("ref:colour_bg", "#fF0")
+    assert_equal "#fF0", colour
+
+    colour = colour_preview("ref:colour_tx", "#fa0")
+    assert_equal "#fa0", colour
+
+    colour = colour_preview("int_ref:colour", "green")
+    assert_equal "green", colour
+
+    colour = colour_preview("int_ref:colour_bg", "#00f")
+    assert_equal "#00f", colour
+
+    colour = colour_preview("int_ref:colour_tx", "WHITE")
+    assert_equal "WHITE", colour
+
     colour = colour_preview("roof:colour", "#f00")
     assert_equal "#f00", colour
 
@@ -396,6 +411,15 @@ class BrowseHelperTest < ActionView::TestCase
     colour = colour_preview("building", "red")
     assert_nil colour
 
+    colour = colour_preview("ref:colour_no", "red")
+    assert_nil colour
+
+    colour = colour_preview("ref:colour-bg", "red")
+    assert_nil colour
+
+    colour = colour_preview("int_ref", "red")
+    assert_nil colour
+
     # invalid hex codes
     colour = colour_preview("colour", "#")
     assert_nil colour