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
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("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