diff --git a/app/assets/stylesheets/style.css.scss b/app/assets/stylesheets/style.css.scss index 312f599..fb383e3 100644 --- a/app/assets/stylesheets/style.css.scss +++ b/app/assets/stylesheets/style.css.scss @@ -987,10 +987,8 @@ nav.pagination { } .label { - background: #d40; + background: #333; padding: 0.1em 0.2em; border-radius: 0.2em; - color: #b20; - border: 1px solid #B20; - text-shadow: -1px -1px #e50, 1px 1px #a10; + text-shadow: none; } \ No newline at end of file diff --git a/app/models/label.rb b/app/models/label.rb index 0bcc7b9..e0cf98e 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -1,5 +1,6 @@ class Label < ActiveRecord::Base validates_presence_of :name + validate :color_valid belongs_to :role has_and_belongs_to_many :forums has_many :forumthreads @@ -8,4 +9,33 @@ class Label < ActiveRecord::Base name.upcase end + # calculate the foreground color + # either black or white, based on the bg color + def fcolor + bg = color.dup + # convert 3 char to 6 char hex + bg.gsub!(/./, '\&\&') if bg.length == 3 + [0, 2, 4].each do |i| + if bg[i..i+1] >= "7f" + return "000" + end + end + return "fff" + end + + private + + def color_valid + color.downcase! + unless [3, 6].include? color.length + errors.add(:color, "Must be 3 or 6 characters long") + end + valid_chars = ("0".."9").to_a + ("a".."f").to_a + color.split("").each do |c| + unless valid_chars.include? c + errors.add(:color, "Must be a valid HEX code") + return + end + end + end end \ No newline at end of file diff --git a/app/views/forums/show.html.erb b/app/views/forums/show.html.erb index d844fe7..7200c78 100644 --- a/app/views/forums/show.html.erb +++ b/app/views/forums/show.html.erb @@ -22,7 +22,7 @@