Skip to content

A platform for community discussion. Free, open, simple.

DEV: Breaks up core digest.text.erb for readability (#33637)

benjb6c1ec026421
diff --git a/app/views/user_notifications/digest.html.erb b/app/views/user_notifications/digest.html.erb
index 3b45047daf6..edb2434333c 100644
--- a/app/views/user_notifications/digest.html.erb
+++ b/app/views/user_notifications/digest.html.erb
@@ -50,6 +50,7 @@
<%= render partial: "user_notifications/digest/footer" %>
<%= digest_custom_html("below_footer") %>
</td>
+ <!-- Empty cells pad either side of the email content -->
<td></td>
</tr>
</table>
diff --git a/app/views/user_notifications/digest.text.erb b/app/views/user_notifications/digest.text.erb
index 4aa90877f6d..1719c094d7a 100644
--- a/app/views/user_notifications/digest.text.erb
+++ b/app/views/user_notifications/digest.text.erb
@@ -1,58 +1,9 @@
-<%- site_link = raw(@markdown_linker.create(@site_name, '/')) %>
-<%= raw(t 'user_notifications.digest.why', site_link: site_link, since: @since) %>
+<%= render partial: "user_notifications/digest/header" %>
-<%- @counts.each do |count| -%>
-<%= count[:value] -%> <%=t count[:label_key] %>
-<%- end -%>
+<%= render partial: "user_notifications/digest/popular_topics" %>
---------------------------------------------------------------------------------
+<%= render partial: "user_notifications/digest/popular_posts" %>
-<%- if @popular_topics.present? %>
-### <%=t 'user_notifications.digest.popular_topics' %>
+<%= render partial: "user_notifications/digest/other_new_topics" %>
-<%- @popular_topics.each_with_index do |t,i| %>
-<%= raw(@markdown_linker.create(t.title, t.url)) %>
-
-<%- if t.best_post.present? %>
- <%= raw(t.best_post.excerpt(1000, strip_links: true, text_entities: true, markdown_images: true)) %>
---------------------------------------------------------------------------------
-
-<%- end %>
-<%= digest_custom_text("below_post_#{i+1}") %>
-<%- end %>
-<%- end %>
-<%= digest_custom_text("above_popular_topics") %>
-
-<%- if @popular_posts.present? %>
-### <%=t 'user_notifications.digest.popular_posts' %>
-
-<%- @popular_posts.each_with_index do |post,i| %>
-<%= post.user.username -%> - <%= raw(@markdown_linker.create(post.topic.title, post.topic.url)) %>
-
- <%= raw(post.excerpt(1000, strip_links: true, text_entities: true, markdown_images: true)) %>
---------------------------------------------------------------------------------
-
-<%- end %>
-<%- end %>
-
-<%- if @other_new_for_you.present? %>
-**<%=t 'user_notifications.digest.more_new' %>**
-
-<%- @other_new_for_you.each do |t| %>
-* <%= raw(@markdown_linker.create(t.title, t.url)) %> - <%= t.posts_count %> - <%- if t.category %>[<%= t.category.name %>]<%- end %>
-<%- end -%>
-<%- 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,
- email_preferences_link: raw(@markdown_linker.create(t('user_notifications.digest.your_email_settings'), '/my/preferences/emails')),
- unsubscribe_link: raw(@markdown_linker.create(t('user_notifications.digest.click_here'), "/email/unsubscribe/#{@unsubscribe_key}"))) %>
-
-<%= raw(@markdown_linker.references) %>
-
-<%= digest_custom_text("below_footer") %>
+<%= render partial: "user_notifications/digest/footer" %>
diff --git a/app/views/user_notifications/digest/_custom_header.erb b/app/views/user_notifications/digest/_custom_header.erb
index f5fd154e9b6..1ef72a6b8e6 100644
--- a/app/views/user_notifications/digest/_custom_header.erb
+++ b/app/views/user_notifications/digest/_custom_header.erb
@@ -1,5 +1,6 @@
<table width="100%" class="digest-header logo-header" dir="<%= rtl? ? 'rtl' : 'ltr' %>" style="border-spacing:0;padding:0;">
<tr>
+ <!-- Empty cells pad either side of the email content -->
<td></td>
<td width="650" style="padding:0;">
<%= raw(t 'user_notifications.digest.custom.html.header') %>
diff --git a/app/views/user_notifications/digest/_footer.html.erb b/app/views/user_notifications/digest/_footer.html.erb
index b481fc06573..7ffc059023e 100644
--- a/app/views/user_notifications/digest/_footer.html.erb
+++ b/app/views/user_notifications/digest/_footer.html.erb
@@ -1,5 +1,6 @@
<table width="100%" class='summary-footer with-dir'>
<tr>
+ <!-- Empty cells pad either side of the email content -->
<td></td>
<td width="650" align="center">
<%=raw(t 'user_notifications.digest.unsubscribe',
diff --git a/app/views/user_notifications/digest/_footer.text.erb b/app/views/user_notifications/digest/_footer.text.erb
new file mode 100644
index 00000000000..2ed5b2cd364
--- /dev/null
+++ b/app/views/user_notifications/digest/_footer.text.erb
@@ -0,0 +1,15 @@
+<%- site_link = raw(@markdown_linker.create(@site_name, '/')) %>
+
+<%= 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,
+ email_preferences_link: raw(@markdown_linker.create(t('user_notifications.digest.your_email_settings'), '/my/preferences/emails')),
+ unsubscribe_link: raw(@markdown_linker.create(t('user_notifications.digest.click_here'), "/email/unsubscribe/#{@unsubscribe_key}"))) %>
+
+<%= raw(@markdown_linker.references) %>
+
+<%= digest_custom_text("below_footer") %>
\ No newline at end of file
diff --git a/app/views/user_notifications/digest/_header.html.erb b/app/views/user_notifications/digest/_header.html.erb
index 1b524c76da2..9b560223c2e 100644
--- a/app/views/user_notifications/digest/_header.html.erb
+++ b/app/views/user_notifications/digest/_header.html.erb
@@ -1,5 +1,6 @@
<table width="100%" class="digest-header text-header with-dir" style="background-color:#<%= @header_bgcolor -%>;">
<tr>
+ <!-- Empty cells pad either side of the email content -->
<td></td>
<td width="650" align="center" style="text-align: center;padding: 20px 0; font-family:Arial,sans-serif;">
<a href="<%= Discourse.base_url %>" style="color:#<%= @header_color -%>;font-size:22px;text-decoration:none;">
diff --git a/app/views/user_notifications/digest/_header.text.erb b/app/views/user_notifications/digest/_header.text.erb
new file mode 100644
index 00000000000..ffef7708372
--- /dev/null
+++ b/app/views/user_notifications/digest/_header.text.erb
@@ -0,0 +1,6 @@
+<%- site_link = raw(@markdown_linker.create(@site_name, '/')) %>
+<%= raw(t 'user_notifications.digest.why', site_link: site_link, since: @since) %>
+
+<%- @counts.each do |count| -%>
+<%= count[:value] -%> <%=t count[:label_key] %>
+<%- end -%>
\ No newline at end of file
diff --git a/app/views/user_notifications/digest/_other_new_topics.text.erb b/app/views/user_notifications/digest/_other_new_topics.text.erb
new file mode 100644
index 00000000000..bb1c598f840
--- /dev/null
+++ b/app/views/user_notifications/digest/_other_new_topics.text.erb
@@ -0,0 +1,7 @@
+<%- if @other_new_for_you.present? %>
+**<%=t 'user_notifications.digest.more_new' %>**
+
+<%- @other_new_for_you.each do |t| %>
+* <%= raw(@markdown_linker.create(t.title, t.url)) %> - <%= t.posts_count %> - <%- if t.category %>[<%= t.category.name %>]<%- end %>
+<%- end -%>
+<%- end %>
\ No newline at end of file
diff --git a/app/views/user_notifications/digest/_popular_posts.text.erb b/app/views/user_notifications/digest/_popular_posts.text.erb
new file mode 100644
index 00000000000..3340c37754a
--- /dev/null
+++ b/app/views/user_notifications/digest/_popular_posts.text.erb
@@ -0,0 +1,10 @@
+<%- if @popular_posts.present? %>
+### <%=t 'user_notifications.digest.popular_posts' %>
+
+<%- @popular_posts.each_with_index do |post,i| %>
+<%= post.user.username -%> - <%= raw(@markdown_linker.create(post.topic.title, post.topic.url)) %>
+
+ <%= raw(post.excerpt(1000, strip_links: true, text_entities: true, markdown_images: true)) %>
+
+<%- end %>
+<%- end %>
\ No newline at end of file
diff --git a/app/views/user_notifications/digest/_popular_topics.text.erb b/app/views/user_notifications/digest/_popular_topics.text.erb
new file mode 100644
index 00000000000..47888041504
--- /dev/null
+++ b/app/views/user_notifications/digest/_popular_topics.text.erb
@@ -0,0 +1,14 @@
+<%- if @popular_topics.present? %>
+### <%=t 'user_notifications.digest.popular_topics' %>
+
+<%- @popular_topics.each_with_index do |t,i| %>
+<%= raw(@markdown_linker.create(t.title, t.url)) %>
+
+<%- if t.best_post.present? %>
+ <%= raw(t.best_post.excerpt(1000, strip_links: true, text_entities: true, markdown_images: true)) %>
+
+<%- end %>
+<%= digest_custom_text("below_post_#{i+1}") %>
+<%- end %>
+<%- end %>
+<%= digest_custom_text("above_popular_topics") %>
\ No newline at end of file