Added Setting to define custom HTML Email CSS font.

This commit is contained in:
Thorsten Eckel 2018-03-06 10:24:37 +01:00
parent 95e5eb57a8
commit 2ecc60f22a
3 changed files with 115 additions and 79 deletions

View file

@ -1,81 +1,83 @@
if ActiveRecord::Base.connection.table_exists?( Setting.table_name )
Rails.application.config.html_email_css_font = "font-family:'Helvetica Neue', Helvetica, Arial, Geneva, sans-serif; font-size: 12px;"
html_email_css_font = Setting.get('html_email_css_font')
Rails.application.config.html_email_body = <<~HERE
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<style type="text/css">
body {
#{Rails.application.config.html_email_css_font};
}
img {
outline: none;
text-decoration: none;
-ms-interpolation-mode: bicubic;
}
a img {
border: none;
}
table td {
border-collapse: collapse;
}
table {
border-collapse: collapse;
mso-table-lspace: 0pt;
mso-table-rspace: 0pt;
border: none;
table-layout: auto;
display: block;
width: 100%;
overflow: auto;
word-break: keep-all;
}
table,
pre,
blockquote {
margin: 0 0 16px;
}
td, th {
padding: 7px 12px;
border: 1px solid hsl(0,0%,87%);
}
th {
font-weight: bold;
text-align: center;
}
tbody tr:nth-child(even) {
background: hsl(0,0%,97%);
}
col {
width: auto;
}
p {
margin: 0;
}
code {
border: none;
background: hsl(0,0%,97%);
white-space: pre-wrap;
}
blockquote {
padding: 8px 12px;
border-left: 5px solid #eee;
}
pre {
padding: 12px 15px;
font-size: 13px;
line-height: 1.45;
background: hsl(0,0%,97%);
white-space: pre-wrap;
border-radius: 3px;
border: none;
overflow: auto;
}
</style>
</head>
<body style="#{Rails.application.config.html_email_css_font}">###html###</body>
</html>
HERE
Rails.application.config.html_email_body = <<~HERE
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<style type="text/css">
body {
#{html_email_css_font};
}
img {
outline: none;
text-decoration: none;
-ms-interpolation-mode: bicubic;
}
a img {
border: none;
}
table td {
border-collapse: collapse;
}
table {
border-collapse: collapse;
mso-table-lspace: 0pt;
mso-table-rspace: 0pt;
border: none;
table-layout: auto;
display: block;
width: 100%;
overflow: auto;
word-break: keep-all;
}
table,
pre,
blockquote {
margin: 0 0 16px;
}
td, th {
padding: 7px 12px;
border: 1px solid hsl(0,0%,87%);
}
th {
font-weight: bold;
text-align: center;
}
tbody tr:nth-child(even) {
background: hsl(0,0%,97%);
}
col {
width: auto;
}
p {
margin: 0;
}
code {
border: none;
background: hsl(0,0%,97%);
white-space: pre-wrap;
}
blockquote {
padding: 8px 12px;
border-left: 5px solid #eee;
}
pre {
padding: 12px 15px;
font-size: 13px;
line-height: 1.45;
background: hsl(0,0%,97%);
white-space: pre-wrap;
border-radius: 3px;
border: none;
overflow: auto;
}
</style>
</head>
<body style="#{html_email_css_font}">###html###</body>
</html>
HERE
end

View file

@ -0,0 +1,21 @@
class CustomHtmlEmailCssFont < ActiveRecord::Migration[5.1]
def change
# return if it's a new setup
return if !Setting.find_by(name: 'system_init_done')
Setting.create_if_not_exists(
title: 'HTML Email CSS Font',
name: 'html_email_css_font',
area: 'Core',
description: 'Defines the CSS font information for HTML Emails.',
options: {},
state: "font-family:'Helvetica Neue', Helvetica, Arial, Geneva, sans-serif; font-size: 12px;",
preferences: {
permission: ['admin'],
},
frontend: false
)
end
end

View file

@ -3739,3 +3739,16 @@ Setting.create_if_not_exists(
preferences: { online_service_disable: true },
frontend: false
)
Setting.create_if_not_exists(
title: 'HTML Email CSS Font',
name: 'html_email_css_font',
area: 'Core',
description: 'Defines the CSS font information for HTML Emails.',
options: {},
state: "font-family:'Helvetica Neue', Helvetica, Arial, Geneva, sans-serif; font-size: 12px;",
preferences: {
permission: ['admin'],
},
frontend: false
)