views:

89

answers:

2

I’m looking for a solution to send DRY multipart emails in Rails. With DRY I mean that the content for the mail is only defined once.

I’ve thought about some possible solutions but haven’t found any existing implementations.

The solutions I’ve thought about are:

  • load the text from I18n and apply Markdown for the html mail and apply Markdown with a special output type for the text mail where
    • links are put in parenthesis after the link text
    • bold, italic and other formatting that doesn't make sense are removed
    • ordered and unordered lists are maintained
  • generate only the html mail and convert that to text according to the above conditions

Is there any available solution out there? Which one is probably the better way to do it?

A: 

I use Mylyn/Wikitext to write all our documentation in Mediawiki, and publish it in HTML and LaTeX afterwards (Had to write the LaTeX outputter for myself).

Daniel
+1  A: 

This is a PITA, but is the only way to DRY mail such that you can support both HTML (multipart) & plaintext:

Put the html email copy in a partial file in your ActionMailer view directory with the following extension: _action.html.erb

Replace "action" with whatever action name you are using.

Then create 2 more files in the same directory: action.text.html.erb and action.text.plain.erb

In the text.html partial:

<%= render "action.html", :locals => {:html => true} %>

In the text.plain partial:

<% content = render "action.html", :locals => {:html => false} %>
<%= strip_tags(content) %>

That works for me, though it certainly makes me want to pay the monthly service for madmimi

simianarmy