diff --git a/app/assets/stylesheets/style.css.scss b/app/assets/stylesheets/style.css.scss index 3710d87..f4239b9 100644 --- a/app/assets/stylesheets/style.css.scss +++ b/app/assets/stylesheets/style.css.scss @@ -408,7 +408,6 @@ blockquote p { a.role { display: inline-block; - color: #fff !important; font-weight: bold; padding: 4px 0.5em; border-radius: 3px; @@ -419,20 +418,7 @@ blockquote p { text-overflow: ellipsis; max-width: 27em; // works with the 30 character limit - &.superadmin, &.admin { - background: #d22 !important; - } - - &.mod { - background: #6af !important; - } - - &.normal { - background: #282 !important; - } - &.banned, &.disabled { - background: #ccc !important; text-decoration: line-through !important; color: #888 !important; } diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 90528fc..a147945 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -69,6 +69,19 @@ module ApplicationHelper render_youtube(md.render(content)) end + # calculate the foreground color + # either +dark+ or +light+, based on the +bgcolor+ + def fcolor(bgcolor = "#000", light = "#fff", dark = "#000") + bg = bgcolor.gsub(/[^0-9a-f]/i, "") + # convert 3 char to 6 char hex + bg.gsub!(/./, '\&\&') if bg.length == 3 + sum = 0 + [0, 2, 4].each do |i| + sum += bg[i..i+1].to_i(16) + end + return (sum/3 < 128) ? light : dark + end + private def render_youtube(content) diff --git a/app/models/label.rb b/app/models/label.rb index 863546d..ee2fb56 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -8,20 +8,6 @@ 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 diff --git a/app/models/role.rb b/app/models/role.rb index 47da692..708fb40 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -2,6 +2,8 @@ class Role < ActiveRecord::Base include Comparable has_many :users + validates :color, format: {with: /#[0-9a-f]{3,6}/i} + def to_s self.name diff --git a/app/views/labels/_label.html.erb b/app/views/labels/_label.html.erb index a13fba0..b1ace17 100644 --- a/app/views/labels/_label.html.erb +++ b/app/views/labels/_label.html.erb @@ -1,3 +1,3 @@ <% if label %> - <%= label %> + <%= label %> <% end %> \ No newline at end of file diff --git a/app/views/users/_username.html.erb b/app/views/users/_username.html.erb index 7045e73..474c3a0 100644 --- a/app/views/users/_username.html.erb +++ b/app/views/users/_username.html.erb @@ -1,4 +1,4 @@