动作邮件模板的优雅降级/渐进式增强?

时间:2022-12-08 08:15:47

Is there some gem or technique that will let us write only .html.erb templates for our Rails 3 mailers, and gracefully degrade them by stripping HTML tags for the text/plain version, rather than having to create each partial twice?

有没有什么宝石或技术可以让我们只写。html。为我们的Rails 3邮件提供erb模板,并通过剥离文本/纯文本版本的HTML标记来优雅地降低它们,而不是必须创建每个部分两次?

Google is seriously failing me, so I must be searching for the wrong terms.

谷歌严重地辜负了我,所以我一定是在寻找错误的术语。

2 个解决方案

#1


2  

take a look at premailer. It can generate text from html.

看看premailer。它可以从html生成文本。

In general, this is not an easy problem. It might be easier if we were able to write semantic html markup and then it'd be easier to detect intent and convert the html into reasonable looking plain text.

总的来说,这不是一个容易的问题。如果我们能够编写语义html标记,那么就更容易检测意图,并将html转换成看起来合理的纯文本。

But assuming your html emails are intended for a wide audience, it's full of all sorts of hacks that make the layout work in multiple email clients. This sort of dirty markup will make it harder to generate good looking plain text.

但是,假设你的html邮件是为广大用户准备的,它充满了各种各样的技巧,使布局在多个电子邮件客户端工作。这种肮脏的标记将使生成好看的纯文本变得更加困难。

Another issue are things that won't clearly translate into text. Links that say "click here", will look funny in text, for example.

另一个问题是那些不能很清楚地转化为文本的事情。比如,说“点击这里”的链接在文本中看起来很有趣。

#2


1  

Well, if your html e-mail is simple and can be expressed as Markdown syntax you can use Markerb. It allows you to render multipart e-mails from a single template.

如果html电子邮件很简单,可以用Markdown语法表示,那么可以使用Markerb。它允许您从单个模板中呈现多部分电子邮件。

#1


2  

take a look at premailer. It can generate text from html.

看看premailer。它可以从html生成文本。

In general, this is not an easy problem. It might be easier if we were able to write semantic html markup and then it'd be easier to detect intent and convert the html into reasonable looking plain text.

总的来说,这不是一个容易的问题。如果我们能够编写语义html标记,那么就更容易检测意图,并将html转换成看起来合理的纯文本。

But assuming your html emails are intended for a wide audience, it's full of all sorts of hacks that make the layout work in multiple email clients. This sort of dirty markup will make it harder to generate good looking plain text.

但是,假设你的html邮件是为广大用户准备的,它充满了各种各样的技巧,使布局在多个电子邮件客户端工作。这种肮脏的标记将使生成好看的纯文本变得更加困难。

Another issue are things that won't clearly translate into text. Links that say "click here", will look funny in text, for example.

另一个问题是那些不能很清楚地转化为文本的事情。比如,说“点击这里”的链接在文本中看起来很有趣。

#2


1  

Well, if your html e-mail is simple and can be expressed as Markdown syntax you can use Markerb. It allows you to render multipart e-mails from a single template.

如果html电子邮件很简单,可以用Markdown语法表示,那么可以使用Markerb。它允许您从单个模板中呈现多部分电子邮件。