Use the header background color for a site in the digest email.

This commit is contained in:
Robin Ward 2014-07-17 12:31:37 -04:00
parent f06f8abedd
commit ede8f22971
4 changed files with 18 additions and 1 deletions

View file

@ -39,6 +39,7 @@ class UserNotifications < ActionMailer::Base
@site_name = SiteSetting.title
@header_color = ColorScheme.hex_for_name('header_background')
@last_seen_at = I18n.l(@user.last_seen_at || @user.created_at, format: :short)
# A list of topics to show the user

View file

@ -60,6 +60,10 @@ class ColorScheme < ActiveRecord::Base
new_color_scheme
end
def self.hex_for_name(name)
# Can't use `where` here because base doesn't allow it
(enabled || base).colors.find {|c| c.name == name }.try(:hex)
end
def colors=(arr)
@colors_by_name = nil

View file

@ -1,6 +1,6 @@
<table style="border: 1px solid #ddd;" cellspacing="0" cellpadding="0">
<tr>
<td style="padding: 10px 10px; background-color: #eee;">
<td style="padding: 10px 10px; background-color: #<%= @header_color %>;">
<a href="<%= Discourse.base_url %>">
<img src="<%= logo_url %>" style="max-height: 35px; min-height: 35px; height: 35px;" class='site-logo'></a>
</td>

View file

@ -40,6 +40,16 @@ describe ColorScheme do
second.hex.should == base_colors[:second_one]
third.hex.should == 'F00D33'
end
context "hex_for_name without anything enabled" do
it "returns nil for a missing attribute" do
described_class.hex_for_name('undefined').should be_nil
end
it "returns the base color for an attribute" do
described_class.hex_for_name('second_one').should == base_colors[:second_one]
end
end
end
describe "destroy" do
@ -59,8 +69,10 @@ describe ColorScheme do
end
it "returns the enabled color scheme" do
described_class.hex_for_name('$primary_background_color').should be_nil
c = described_class.create(valid_params.merge(enabled: true))
described_class.enabled.id.should == c.id
described_class.hex_for_name('$primary_background_color').should == "FFBB00"
end
end
end