From 2f68be2c5c138bf401d36de8dbd9c7bc68ea63cf Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Tue, 23 Aug 2016 16:06:02 -0400 Subject: [PATCH] FEATURE: custom html and text can be added to summary emails --- app/helpers/user_notifications_helper.rb | 12 +++++++++++ app/views/user_notifications/digest.html.erb | 16 ++++++++++++++ app/views/user_notifications/digest.text.erb | 11 ++++++---- config/locales/server.en.yml | 22 ++++++++++++++++++++ 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/app/helpers/user_notifications_helper.rb b/app/helpers/user_notifications_helper.rb index 4c088836d11..84b5204f841 100644 --- a/app/helpers/user_notifications_helper.rb +++ b/app/helpers/user_notifications_helper.rb @@ -70,4 +70,16 @@ module UserNotificationsHelper PrettyText.format_for_email(html, post).html_safe end + def digest_custom_html(position_key) + digest_custom "user_notifications.digest.custom.html.#{position_key}" + end + + def digest_custom_text(position_key) + digest_custom "user_notifications.digest.custom.text.#{position_key}" + end + + def digest_custom(i18n_key) + PrettyText.format_for_email(I18n.t(i18n_key)).html_safe + end + end diff --git a/app/views/user_notifications/digest.html.erb b/app/views/user_notifications/digest.html.erb index d70c1189c6b..d8b7faf7bd1 100644 --- a/app/views/user_notifications/digest.html.erb +++ b/app/views/user_notifications/digest.html.erb @@ -1,5 +1,10 @@ + <%- if I18n.t('user_notifications.digest.custom.html.header').present? %> + + <%- else %> + <%- end %>
+ <%= raw(t 'user_notifications.digest.custom.html.header') %> + <%- if logo_url.blank? %> @@ -9,6 +14,7 @@ <%- end %>
@@ -32,11 +38,15 @@ <%- end %> + <%= digest_custom_html("below_post_#{i+1}") %> + <%- if i < @featured_topics.size - 1 %><% end %> <%- end %> <%- end %> + <%= digest_custom_html("above_popular_topics") %> + <%- if @new_topics.present? %>

<%=t 'user_notifications.digest.other_new_topics' %>

@@ -53,6 +63,8 @@ <%- end -%> + <%= digest_custom_html("below_popular_topics") %> + <%- if @new_topics_since_seen > 0 %> <%- if @new_by_category.present? %>

<%= t('user_notifications.digest.more_topics_category', last_seen_at: @last_seen_at, new_topics_since_seen: @new_topics_since_seen) %>

@@ -71,8 +83,12 @@
+<%= digest_custom_html("above_footer") %> + + +<%= digest_custom_html("below_footer") %> diff --git a/app/views/user_notifications/digest.text.erb b/app/views/user_notifications/digest.text.erb index 3091e529a6d..07d5c4870e4 100644 --- a/app/views/user_notifications/digest.text.erb +++ b/app/views/user_notifications/digest.text.erb @@ -6,7 +6,7 @@ <%- if @featured_topics.present? %> ### <%=t 'user_notifications.digest.top_topics' %> -<%- @featured_topics.each do |t| %> +<%- @featured_topics.each_with_index do |t,i| %> <%= raw(@markdown_linker.create(t.title, t.relative_url)) %> <%- if t.best_post.present? %> @@ -14,10 +14,10 @@ -------------------------------------------------------------------------------- <%- end %> - +<%= digest_custom_text("below_post_#{i+1}") %> <%- end %> <%- end %> - +<%= digest_custom_text("above_popular_topics") %> <%- if @new_topics.present? %> **<%=t 'user_notifications.digest.other_new_topics' %>** @@ -27,12 +27,15 @@ <%- end -%> - +<%= digest_custom_text("below_popular_topics") %> <%= raw(@markdown_linker.references) %> +<%= digest_custom_text("above_footer") %> <%=raw(t :'user_notifications.digest.unsubscribe', site_link: site_link, unsubscribe_link: raw(@markdown_linker.create(t('user_notifications.digest.click_here'), email_unsubscribe_url(key: @unsubscribe_key, only_path: true)))) %> <%= raw(@markdown_linker.references) %> + +<%= digest_custom_text("below_footer") %> \ No newline at end of file diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 4208612d55e..98f614eb611 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -2412,6 +2412,28 @@ en: read_more: "Read More" more_topics: "There were %{new_topics_since_seen} other new topics." more_topics_category: "More new topics:" + custom: + html: + header: '' + below_post_1: '' + below_post_2: '' + below_post_3: '' + below_post_4: '' + below_post_5: '' + above_popular_topics: '' + below_popular_topics: '' + above_footer: '' + below_footer: '' + text: + below_post_1: '' + below_post_2: '' + below_post_3: '' + below_post_4: '' + below_post_5: '' + above_popular_topics: '' + below_popular_topics: '' + above_footer: '' + below_footer: '' mailing_list: why: "All activity on %{site_link} for %{date}"