mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 15:54:05 +08:00
9656a21fdb
This feature adds the ability to customize the HTML part of all emails using a custom HTML template and optionally some CSS to style it. The CSS will be parsed and converted into inline styles because CSS is poorly supported by email clients. When writing the custom HTML and CSS, be aware of what email clients support. Keep customizations very simple. Customizations can be added and edited in Admin > Customize > Email Style. Since the summary email is already heavily styled, there is a setting to disable custom styles for summary emails called "apply custom styles to digest" found in Admin > Settings > Email. As part of this work, RTL locales are now rendered correctly for all emails.
47 lines
1.5 KiB
Ruby
47 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
describe EmailStyleUpdater do
|
|
fab!(:admin) { Fabricate(:admin) }
|
|
let(:default_html) { File.read("#{Rails.root}/app/views/email/default_template.html") }
|
|
let(:updater) { EmailStyleUpdater.new(admin) }
|
|
|
|
describe 'update' do
|
|
it 'can change the settings' do
|
|
expect(
|
|
updater.update(
|
|
html: 'For you: %{email_content}',
|
|
css: 'h1 { color: blue; }'
|
|
)
|
|
).to eq(true)
|
|
expect(SiteSetting.email_custom_template).to eq('For you: %{email_content}')
|
|
expect(SiteSetting.email_custom_css).to eq('h1 { color: blue; }')
|
|
end
|
|
|
|
it 'will not store defaults' do
|
|
updater.update(html: default_html, css: '')
|
|
expect(SiteSetting.email_custom_template).to_not be_present
|
|
expect(SiteSetting.email_custom_css).to_not be_present
|
|
end
|
|
|
|
it 'can clear settings if defaults given' do
|
|
SiteSetting.email_custom_template = 'For you: %{email_content}'
|
|
SiteSetting.email_custom_css = 'h1 { color: blue; }'
|
|
updater.update(html: default_html, css: '')
|
|
expect(SiteSetting.email_custom_template).to_not be_present
|
|
expect(SiteSetting.email_custom_css).to_not be_present
|
|
end
|
|
|
|
it 'fails if html is missing email_content' do
|
|
expect(updater.update(html: 'No email content', css: '')).to eq(false)
|
|
expect(updater.errors).to include(
|
|
I18n.t(
|
|
'email_style.html_missing_placeholder',
|
|
placeholder: '%{email_content}'
|
|
)
|
|
)
|
|
end
|
|
end
|
|
end
|