This week on mokacoding we are going to keep Xcode closed, the iPhones in our pockets, and look at the automated workflow that we use to create "mokacoding weekly", the newsletter that every week reaches your inbox with the latest articles from the blog and other interesting links from the testing, automation, productivity, and software development world.

At the end of March 2015 "mokacoding weekly" issue 1 was sent to 49 subscribers.

The newsletter is sent with MailChimp, which has a WYSIWYG/HTML editor for the email content.

Issue number 2 was sent out by duplicating the campaign made for the previous one, and by changing the content.

That wasn't a fun experience, the format kept changing for no reason, and it was hard to set it back to the original one. Even after discovering that you can write raw HTML in the editor, the situation didn't improve. After working with haml or jade old school HTML is too cumbersome.

A good automation rule of thumb is "three strikes and you automate", if you have to do something that you already did two times, automate it. And that's why before it was time to send out issue number 3 an automated workflow was put in place. You can have a look at it on GitHub.

Taking care of the layout being the bigger pain point at the time, that's the first issue that this automate workflow tries to solve, or at least smooth. The question was how can we avoid writing HTML, but still have good formatting?

The answer was easy, it'd be great to write in Markdown the same way I can do forthis blog.

The redcarpet gem allows you to parse .md files in valid HTML ones, and it also comes with a command line interface.

redcarpet mokacoding-weekly-003.md mokacoding-weekly-003.html

To keep the amount of editing as little as possible I extracted the header and footer common to every issue in two files. These can be appended and prepended to the one with the real content, which is the only one that changes.

redcarpet header.md mokacoding-weekly-003.mdfooter.md

To avoid typing that long command every week there is a Rake task, rake build, that does it for us.

Now to we can simply write the new issue content with the comfort of the markdown syntax, type rake build, and paste the output into MailChimp.

Even more automation

This workflow is already better that doing everything manually... but it can still be improved!

One point that can could be talked is the copy-paste of the content. Why should one select and copy the generated HTML output manually? Let's make it automatic.