From 6c0abe15e051344590029ccd3df77f73bbc656e7 Mon Sep 17 00:00:00 2001 From: Isaac Janzen <50783505+janzenisaac@users.noreply.github.com> Date: Mon, 11 Apr 2022 12:27:50 -0500 Subject: [PATCH] FEATURE: Add email dark mode (#16104) implement dark mode emails when `SiteSetting.dark_mode_emails_active` is active. --- app/helpers/email_helper.rb | 58 +++++++++++++++++++ app/views/email/default_template.html | 2 + app/views/user_notifications/digest.html.erb | 21 ++++--- config/site_settings.yml | 3 + lib/email/styles.rb | 11 ++++ public/images/emails/comment_dark.png | Bin 0 -> 492 bytes public/images/emails/heart_dark.png | Bin 0 -> 606 bytes public/images/emails/right_triangle_dark.png | Bin 0 -> 197 bytes spec/lib/email/styles_spec.rb | 17 ++++++ 9 files changed, 104 insertions(+), 8 deletions(-) create mode 100644 public/images/emails/comment_dark.png create mode 100644 public/images/emails/heart_dark.png create mode 100644 public/images/emails/right_triangle_dark.png diff --git a/app/helpers/email_helper.rb b/app/helpers/email_helper.rb index f738ac49737..ed24cb8ed1b 100644 --- a/app/helpers/email_helper.rb +++ b/app/helpers/email_helper.rb @@ -29,11 +29,69 @@ module EmailHelper EmailStyle.new.html .sub('%{email_content}') { capture { yield } } .gsub('%{html_lang}', html_lang) + .gsub('%{dark_mode_meta_tags}', SiteSetting.dark_mode_emails_active ? dark_mode_meta_tags : "") + .gsub('%{dark_mode_styles}', SiteSetting.dark_mode_emails_active ? dark_mode_styles : "") .html_safe end protected + def dark_mode_meta_tags + " + + + " + end + + def dark_mode_styles + " + + " + end + def extract_details(topic) if SiteSetting.private_email? [topic.slugless_url, private_topic_title(topic)] diff --git a/app/views/email/default_template.html b/app/views/email/default_template.html index 53e99ab184c..f660cc46fd4 100644 --- a/app/views/email/default_template.html +++ b/app/views/email/default_template.html @@ -10,6 +10,7 @@ name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" /> + %{dark_mode_meta_tags}