Add categories to the first topics in the email digest

This commit is contained in:
Robin Ward 2014-04-17 14:40:30 -04:00
parent b2cb4b27a1
commit 2341118570
3 changed files with 18 additions and 7 deletions

View File

@ -68,4 +68,15 @@ module UserNotificationsHelper
def cooked_post_for_email(post)
PrettyText.format_for_email(post.cooked).html_safe
end
def email_category(category)
return "" if category.blank? || category.uncategorized?
result = ""
if category.parent_category.present?
result << "<span style='background-color: ##{category.parent_category.color}; font-size: 12px; padding: 4px 2px; font-weight: bold; margin: 0; width: 2px;'>&nbsp;</span>"
end
result << "<span style='background-color: ##{category.color}; color: ##{category.text_color}; font-size: 12px; padding: 4px 6px; font-weight: bold; margin: 0;'>#{category.name}</span>"
result.html_safe
end
end

View File

@ -13,7 +13,10 @@
<h3><%=t 'user_notifications.digest.top_topics' %></h3>
<%- @featured_topics.each_with_index do |t, i| %>
<%= link_to t.title, "#{Discourse.base_url}#{t.relative_url}" %>
<div class='featured-topic'>
<%= link_to t.title, "#{Discourse.base_url}#{t.relative_url}" %>
<%= email_category(t.category) %>
</div>
<%- if t.best_post.present? %>
<div class='digest-post'>
@ -33,12 +36,8 @@
<ul>
<li>
<%= link_to t.title, "#{Discourse.base_url}#{t.relative_url}" %>
<span class='post-count'><%= t('user_notifications.digest.posts', count: t.posts_count) %></span>
<%- if t.category && !t.category.uncategorized? %>
<%- if t.category.parent_category %><span style='background-color: #<%= t.category.parent_category.color %>; font-size: 12px; padding: 4px 2px; font-weight: bold; margin: 0; width: 2px;'>&nbsp;</span><%- end %><span style='background-color: #<%= t.category.color %>; color: #<%= t.category.text_color %>; font-size: 12px; padding: 4px 6px; font-weight: bold; margin: 0;'><%= t.category.name %></span>
<%- end %>
<%= email_category(t.category) %>
</li>
</ul>
<%- end -%>

View File

@ -53,7 +53,7 @@ module Email
def format_html
style('h3', 'margin: 15px 0 20px 0; border-bottom: 1px solid #ddd;')
style('hr', 'background-color: #ddd; height: 1px; border: 1px;')
style('a',' text-decoration: none; font-weight: bold; color: #006699;')
style('a', 'text-decoration: none; font-weight: bold; color: #006699;')
style('ul', 'margin: 0 0 0 10px; padding: 0 0 0 20px;')
style('li', 'padding-bottom: 10px')
style('div.digest-post', 'margin-left: 15px; margin-top: 20px; max-width: 694px;')
@ -63,6 +63,7 @@ module Email
style('pre', 'word-wrap: break-word; max-width: 694px;')
style('code', 'background-color: #f1f1ff; padding: 2px 5px;')
style('pre code', 'display: block; background-color: #f1f1ff; padding: 5px;')
style('.featured-topic a', 'text-decoration: none; font-weight: bold; color: #006699; margin-right: 5px')
# Links to other topics
style('aside.quote', 'border-left: 5px solid #bebebe; background-color: #f1f1f1; padding: 12px;')