end
def colour_preview(key, value)
- return nil unless (key =~ /^(|building:|ref:|roof:)colour$/ || key =~ /^(int_)?ref:colour(_(bg|tx))?$/) && !value.nil?
+ return nil unless key =~ /^(?>.+:)?colour$/ && !value.nil? # see discussion at https://github.com/openstreetmap/openstreetmap-website/pull/1779
# 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
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
+ colour = colour_preview("seamark:beacon_lateral:colour", "#f00")
+ assert_equal "#f00", colour
+
# negative tests:
- colour = colour_preview("color", "")
+ colour = colour_preview("colour", "")
assert_nil colour
- colour = colour_preview("color", " ")
+ colour = colour_preview("colour", " ")
assert_nil colour
- colour = colour_preview("color", nil)
+ colour = colour_preview("colour", nil)
assert_nil colour
# ignore US spelling variant