From TextMate to ExpressionEngine

Between writing code, documentation, and blog posts, I spend a lot of my time working in TextMate. It's an efficient text editor, but it becomes a bit of a headache when it's time to work on a new blog post. The real problem is my process:

  1. Open TextMate and start collecting my thoughts for a post in some cohesive fashion (optional)
  2. Finalize most of the content and basic formatting
  3. Copy the content into ExpressionEngine, tweak the formatting, add hyperlinks
  4. Preview the post and publish to the site

The reason for all this masochism is my dislike for editing content in a web-based form, WYSIWYG or otherwise. I love my editor enough that I'm willing to jump through some hoops in order to use it for the bulk of my editing work. But, there's a better way to do all this.

TextMate's Blogging Bundle

As part of the standard feature set, TextMate provides a blogging bundle to make most of this 4-step process much easier on me. The bundle supports blogging engines like WordPress and Drupal through the Metaweblog API.

While there is "official" support for a few blogging applications, ExpressionEngine didn't seem to make the list. Despite this, it's still possible to use TextMate with EE once you configure a few key settings. The screencast on the MacroMates site is a great resource for seeing what's possible with the blogging bundle. Check it out, I'll wait.

Configuring ExpressionEngine

Before you get started with the blogging bundle, you'll need to install and configure the Metaweblog API module for ExpressionEngine. Navigate to the 'Modules' section and click the 'Install' link for the Metaweblog API:

Metaweblog Module

Once the module is installed, you can start configuring the settings for your posts. From the 'Modules' page, drill down on the 'Metaweblog API' settings and add a new configuration (big green button):

Metaweblog API Settings

The settings shown are only slightly different from the defaults in a couple key areas:

  • Entry Status – This controls the default status of posts sent to ExpressionEngine. I set it to 'Closed' to do a final preview before I set a post live.
  • More Field – If you break long posts up (using the 'cut' tab trigger), you'll need to designate where the additional content will be stored.
  • Text Formatting Preference – This isn't required unless you're embedding pM code in your actual posts, so I turn this off.

Configure TextMate

Now that you have the API configured, it's time to sync TextMate with your ExpressionEngine site. Head back to the Module configuration screen and take a look at the URL that is displayed for our 'Developer-Friendly' configuration:

Metaweblog URL

In TextMate, navigate to 'Bundles -> Blogging -> Setup Blogs' and configure your blog:

example_blog http://username@www.example.com/?ACT=23&id=2 

Now it's time to see if everything is working, so go to 'Bundles -> Blogging -> Fetch Post' to get a list of the posts. If your site is configured like ours, you'll immediately receive an error after entering your password:

Error: No Entries Found (805) 

Oops! You'll need to make a slight change to your configuration (thanks, Mark) to make sure TextMate can connect to the correct blog. In ExpressionEngine, navigate to 'Admin -> Weblog Administration -> Weblog Management' To see the list of weblogs available:

Available Weblogs

In this case, we're interested in the weblog with id #1, so we just need to update our configuration in TextMate to append that ID to the endpoint URL:

example_blog http://username@www.example.com/?ACT=23&id=2#1 

Now you should be able to grab a list of available posts and create posts of your own.

Creating Posts

Not so fast. There are a few things to keep in mind before adding a post to your weblog. Since EE doesn't understand lighter-weight markup languages like Markdown or Textile, you'll need to make sure to compose your posts in HTML using the 'Blog - HTML' setting. While there is a module that allows you to use Markdown on your site, I have yet to try it out.

Before you get ready to publish that new post, make sure that the formatting is configured properly. Since EE runs all its content through the XHTML filter after a successful post, you'll end up with corrupted tags in your original post. Not fun. To fix this, make sure you have the appropriate setting in your headers when you create your post:

Textmate Formatting

The default setting for 'Format' is 'xhtml', setting it to 'none' will prevent EE from messing up your nicely-formatted post.

Additional Options

The Metaweblog API module provides an endpoint for a 'Default' configuration, but I find that creating a separate configuration that is friendlier to TextMate (and other posters) is a good idea. If, for example, you are more confident with your blogging abilities you may want to keep the default status at 'Open' – it's your call.

Note: This post was created and posted from within TextMate – the first of many.

Patrick is development director in Viget's Boulder, CO, office. He writes clean Ruby code and automates system infrastructure for clients such as Shure and Volunteers of America.

More posts by Patrick