proper color support for labels
This commit is contained in:
@@ -987,10 +987,8 @@ nav.pagination {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.label {
|
.label {
|
||||||
background: #d40;
|
background: #333;
|
||||||
padding: 0.1em 0.2em;
|
padding: 0.1em 0.2em;
|
||||||
border-radius: 0.2em;
|
border-radius: 0.2em;
|
||||||
color: #b20;
|
text-shadow: none;
|
||||||
border: 1px solid #B20;
|
|
||||||
text-shadow: -1px -1px #e50, 1px 1px #a10;
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
class Label < ActiveRecord::Base
|
class Label < ActiveRecord::Base
|
||||||
validates_presence_of :name
|
validates_presence_of :name
|
||||||
|
validate :color_valid
|
||||||
belongs_to :role
|
belongs_to :role
|
||||||
has_and_belongs_to_many :forums
|
has_and_belongs_to_many :forums
|
||||||
has_many :forumthreads
|
has_many :forumthreads
|
||||||
@@ -8,4 +9,33 @@ class Label < ActiveRecord::Base
|
|||||||
name.upcase
|
name.upcase
|
||||||
end
|
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
|
end
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="items bold">
|
<div class="items bold">
|
||||||
<div class="item <%= "#{"locked" if thread.locked}#{"sticky" if thread.sticky}" %>">
|
<div class="item <%= "#{"locked" if thread.locked}#{"sticky" if thread.sticky}" %>">
|
||||||
<%= link_to truncate(thread.title, length: 60, omission: " …"), forumthread_path(thread), title: thread.title %>
|
<%= render partial: "labels/label", locals: {label: thread.label} %><%= link_to truncate(thread.title, length: 60, omission: " …"), forumthread_path(thread), title: thread.title %>
|
||||||
<div class="item-info">
|
<div class="item-info">
|
||||||
<% if rpl = thread.replies.last %>
|
<% if rpl = thread.replies.last %>
|
||||||
<%= rpl.author.name %>
|
<%= rpl.author.name %>
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
<% if label %>
|
<% if label %>
|
||||||
<span class="label label-<%= label.name.downcase %>"><%= label %></span>
|
<span class="label label-<%= label.name.downcase %>" style="color: #<%= label.fcolor %>;background-color: #<%= label.color %>"><%= label %></span>
|
||||||
<% end %>
|
<% end %>
|
||||||
5
db/migrate/20150117134404_add_color_to_label.rb
Normal file
5
db/migrate/20150117134404_add_color_to_label.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
class AddColorToLabel < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :labels, :color, :string
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20141120202853) do
|
ActiveRecord::Schema.define(version: 20150117134404) do
|
||||||
|
|
||||||
create_table "blogposts", force: true do |t|
|
create_table "blogposts", force: true do |t|
|
||||||
t.string "title"
|
t.string "title"
|
||||||
@@ -72,6 +72,7 @@ ActiveRecord::Schema.define(version: 20141120202853) do
|
|||||||
create_table "labels", force: true do |t|
|
create_table "labels", force: true do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.integer "role_id"
|
t.integer "role_id"
|
||||||
|
t.string "color"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "register_tokens", force: true do |t|
|
create_table "register_tokens", force: true do |t|
|
||||||
|
|||||||
Reference in New Issue
Block a user