Last active
August 9, 2016 19:32
-
-
Save kdiogenes/3d5d0ce1290c6d76d6abc8d2ef0575cd to your computer and use it in GitHub Desktop.
Rails: template handler example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| giving this themplate (action.mjml): | |
| <mj-text> | |
| action content | |
| </mj-text> | |
| rendered with this layout (mailer.mjml): | |
| <mjml> | |
| <mj-body> | |
| <mj-container> | |
| <mj-section> | |
| <mj-text> | |
| header | |
| </mj-text> | |
| </mj-section> | |
| <mj-section> | |
| <%= yield %> | |
| </mj-section> | |
| <mj-section> | |
| <mj-text> | |
| footer | |
| </mj-text> | |
| </mj-section> | |
| </mj-container> | |
| </mj-body> | |
| </mjml> | |
| Rails will proccess this in two phases. The first phase would produce the following result: | |
| <mjml> | |
| <mj-body> | |
| <mj-container> | |
| <mj-section> | |
| <mj-text> | |
| header | |
| </mj-text> | |
| </mj-section> | |
| <mj-section> | |
| <div style="cursor:auto;color:#000000;font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:22px;"> | |
| action content | |
| </div> | |
| </mj-section> | |
| <mj-section> | |
| <mj-text> | |
| footer | |
| </mj-text> | |
| </mj-section> | |
| </mj-container> | |
| </mj-body> | |
| </mjml> | |
| this result will be used as input in the second phase and generate the following output: | |
| <!doctype html> | |
| <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"> | |
| <head> | |
| <title></title> | |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
| <style type="text/css"> | |
| #outlook a { padding: 0; } | |
| .ReadMsgBody { width: 100%; } | |
| .ExternalClass { width: 100%; } | |
| .ExternalClass * { line-height:100%; } | |
| body { margin: 0; padding: 0; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; } | |
| table, td { border-collapse:collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; } | |
| img { border: 0; height: auto; line-height: 100%; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic; } | |
| p { display: block; margin: 13px 0; } | |
| </style> | |
| <!--[if !mso]><!--> | |
| <style type="text/css"> | |
| @media only screen and (max-width:480px) { | |
| @-ms-viewport { width:320px; } | |
| @viewport { width:320px; } | |
| } | |
| </style> | |
| <!--<![endif]--> | |
| <!--[if mso]> | |
| <xml> | |
| <o:OfficeDocumentSettings> | |
| <o:AllowPNG/> | |
| <o:PixelsPerInch>96</o:PixelsPerInch> | |
| </o:OfficeDocumentSettings> | |
| </xml> | |
| <![endif]--> | |
| <!--[if !mso]><!--> | |
| <link href="https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700" rel="stylesheet" type="text/css"> | |
| <style type="text/css"> | |
| @import url(https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700); | |
| </style> | |
| <!--<![endif]--></head> | |
| <body> | |
| <div><!--[if mso | IE]> | |
| <table border="0" cellpadding="0" cellspacing="0" width="600" align="center" style="width:600px;"> | |
| <tr> | |
| <td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"> | |
| <![endif]--><div style="margin:0 auto;max-width:600px;"><table cellpadding="0" cellspacing="0" style="font-size:0px;width:100%;" align="center" border="0"><tbody><tr><td style="text-align:center;vertical-align:top;font-size:0px;padding:20px 0px;"><!--[if mso | IE]> | |
| <table border="0" cellpadding="0" cellspacing="0"><tr><td style="vertical-align:undefined;width:600px;"> | |
| <![endif]--><div style="cursor:auto;color:#000000;font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:22px;"> | |
| header | |
| </div><!--[if mso | IE]> | |
| </td></tr></table> | |
| <![endif]--></td></tr></tbody></table></div><!--[if mso | IE]> | |
| </td></tr></table> | |
| <![endif]--> | |
| <!--[if mso | IE]> | |
| <table border="0" cellpadding="0" cellspacing="0" width="600" align="center" style="width:600px;"> | |
| <tr> | |
| <td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"> | |
| <![endif]--><div style="margin:0 auto;max-width:600px;"><table cellpadding="0" cellspacing="0" style="font-size:0px;width:100%;" align="center" border="0"><tbody><tr><td style="text-align:center;vertical-align:top;font-size:0px;padding:20px 0px;"><!--[if mso | IE]> | |
| <table border="0" cellpadding="0" cellspacing="0"><tr><td style="vertical-align:undefined;width:600px;"> | |
| <![endif]--><div style="cursor:auto;color:#000000;font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:22px;"> | |
| action content | |
| </div><!--[if mso | IE]> | |
| </td></tr></table> | |
| <![endif]--></td></tr></tbody></table></div><!--[if mso | IE]> | |
| </td></tr></table> | |
| <![endif]--> | |
| <!--[if mso | IE]> | |
| <table border="0" cellpadding="0" cellspacing="0" width="600" align="center" style="width:600px;"> | |
| <tr> | |
| <td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"> | |
| <![endif]--><div style="margin:0 auto;max-width:600px;"><table cellpadding="0" cellspacing="0" style="font-size:0px;width:100%;" align="center" border="0"><tbody><tr><td style="text-align:center;vertical-align:top;font-size:0px;padding:20px 0px;"><!--[if mso | IE]> | |
| <table border="0" cellpadding="0" cellspacing="0"><tr><td style="vertical-align:undefined;width:600px;"> | |
| <![endif]--><div style="cursor:auto;color:#000000;font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:22px;"> | |
| footer | |
| </div><!--[if mso | IE]> | |
| </td></tr></table> | |
| <![endif]--></td></tr></tbody></table></div><!--[if mso | IE]> | |
| </td></tr></table> | |
| <![endif]--></div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment