Skip to content
This repository was archived by the owner on Jan 22, 2021. It is now read-only.

Commit 960d29a

Browse files
author
Satya van Heummen
committed
automatically create plain-text version from html template
depends on Node html-to-text, can be overrided by changing settings.
1 parent b89cfee commit 960d29a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Diff for: emails.coffee

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
TAG = 'mailer'
99

10+
# used to make plain-text version from html version
11+
htmlToText = Npm.require 'html-to-text'
12+
1013
# ## Setup
1114

1215
# Main exported symbol with some initial settings:
@@ -27,6 +30,7 @@ Mailer =
2730
disabled: false
2831
addRoutes: process.env.NODE_ENV is 'development'
2932
language: 'html'
33+
plainText: true
3034

3135
juiceOpts:
3236
preserveMediaQueries: true
@@ -226,6 +230,14 @@ MailerClass = (options) ->
226230
# Render HTML with optional data context.
227231
try
228232
opts.html = render options.template, options.data
233+
234+
# create plain-text version from html
235+
if settings.plainText
236+
try
237+
opts.text = htmlToText.fromString opts.html
238+
catch ex
239+
Utils.Logger.error "Could not make plain-text version from html: " + ex.message
240+
229241
catch ex
230242
Utils.Logger.error 'Could not render email before sending: ' + ex.message, TAG
231243
return false

Diff for: package.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ var where = 'server';
33
Package.describe({
44
name: 'lookback:emails',
55
summary: 'Send HTML emails with server side Blaze templates. Preview and debug in the browser.',
6-
version: '0.5.1',
6+
version: '0.6.0',
77
git: 'https://github.com/lookback/meteor-emails.git'
88
});
99

10+
Npm.depends({
11+
"html-to-text": "1.3.0"
12+
});
13+
1014
Package.onUse(function(api) {
1115

1216
api.versionsFrom('1.0.4');

0 commit comments

Comments
 (0)