Rails 5  

David Heinemeier Hansson:

It’s taken hundreds of contributors and thousands of commits to get here, but what a destination: Rails 5.0 is without a doubt the best, most complete version of Rails yet.

Rails continues to be the gold standard for iterative improvement and community involvement.

Use Elixir in CodeRunner 2

Recently, I’ve been tinkering around with the Elixir language and have quite enjoyed it. It does offer a nice interactive environment named IEX which functions quite similarly to IRB in the Ruby world. While IEX is a great place to get started I prefer to tinker with code in CodeRunner. It’s a hybrid of a text editor and the Terminal wrapped in a nice GUI. Mac based developers will feel right at home in CodeRunner. Basically, you compose code in an editor pane, complete with customizable syntax highlighting, and can view the results in an adjacent pane as they would appear in the shell. This workflow is fast and elegant.

CodeRunner doesn’t include Elixir out of the box but adding a new language is very easy. We’ll need to enter a few Terminal commands to start with:

# Install Elixir on OS X if you don't already have it with Homebrew.

brew update
brew install elixir

# Download the TextMate language grammar for Elixir.
curl -O https://raw.githubusercontent.com/elixir-lang/elixir-tmbundle/master/Syntaxes/Elixir.tmLanguage

Then, in CodeRunner’s preferences visit the “Languages” tab and click the plus sign in the lower left. Name the new syntax “Elixir” and then in the “Syntax Mode” dropdown box select Other…. Navigate to where you saved the Elixir.tmLanguage file earlier and select it. You’re almost finished. The following two screenshots display the required configuration to start using Elixir:

CodeRunner Elixir Settings

CodeRunner Elixir Template

Once those settings are saved in CodeRunner you’ll have the option to start using Elixir. Just choose it in the dropdown box for a new file:

CodeRunner Elixir Example

Prevent Widows in Jekyll and Middleman

One of my major pet peeves while reading Internet publications is when article titles (normally wrapped in header tags) display line breaks that result in unfortunate widows. A widow is when a line break occurs and a single lonely word is bumped to the next line, left to poke me in eye.

Luckily, this can easily be avoided in both Jekyll and Middleman. The goal is to determine if the title is at least two words in length and then replace the last space in the title with an  . This non-breaking space will keep the last two words married together so that in the event of a line break they will always bump down to the next line together.

The following code is a Jekyll filter that is used in Liquid templates. Simply place this filter in a file named filters.rb and save it to the _plugins folder (create this file and folder if you don’t have them):

# filters.rb

module Jekyll
  module WidowFilter
    def no_widows(title)
      if title.strip.count(" ") >= 2
        title.split[0...-1].join(" ") + " #{title.split[-1]}"

<!-- In a Liquid template the filter is easily invoked. -->

<h1>{{ post.title | no_widows }}</h1>

The process is very similar in Middleman except it’s referred to as a helper instead of a filter. Place the following code in the config.rb file:

# config.rb

helpers do
  def no_widows(title)
    if title.strip.count(" ") >= 2
      title.split[0...-1].join(" ") + "&nbsp;#{title.split[-1]}"

Middleman supports both Haml and ERB. To use the helper in Haml:

%h1= no_widows(article.title)

Or in ERB:

<h1><%= no_widows(article.title) %></h1>

If you view the source code for this site you’ll see that I use the same technique for my titles. It’s a nice touch and the type of attention to detail that makes a better experience for the reader.

Byword Previews in Marked 2 with AppleScript

I’m a big fan of both Byword and Marked 2. The Sweet Setup recently declared Byword to be their favorite Markdown writing app and deservedly so. While Byword does offer a Markdown preview to quickly ensure everything is formatted correctly, its functionality is limited. Marked on the other hand is a Markdown processing powerhouse. It offers many advanced options to both preview and export HTML such as MultiMarkdown and GitHub Flavored Markdown. If you maintain a blog it’s the best $14 you’ll ever spend. I wrote an AppleScript that allows me to author posts in Byword and automatically preview them in Marked with a simple hotket. I use command + shift + m.

tell application "Byword"
    set the_document to document 1
    save the_document
    tell application "Marked 2"
        set the_file to the_document's file
        open the_file
    end tell
end tell

I use Keyboard Maestro to invoke the script but FastScripts and Alfred can both do the job. Conveniently, it will automatically prompt you to save the file in Byword if you’re working on a brand new document. Once saved, invoking the script again will provide the desired result. If you’re an iA Writer fan1 the same script will work by simply replacing the reference to Byword with iA Writer.

  1. Which I’m not, long story.