问题
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