Graceful degradation/progressive enhancement for Action Mailer templates?

家住魔仙堡 提交于 2019-12-13 14:38:20

问题


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?

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


回答1:


take a look at premailer. It can generate text from 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.

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.

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




回答2:


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.



来源:https://stackoverflow.com/questions/8248790/graceful-degradation-progressive-enhancement-for-action-mailer-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!