Close and Go BackBack to Viget

From TextMate to ExpressionEngine

Patrick Reagan
Patrick Reagan, Development Director, May 01, 2008 10

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.

Andy said on 05/06 at 01:28 PM

Any tips or pointers on how to get this set up on a Rails blog (or whether Mephisto/Typo/Simplelog supports this?).  It would be really cool to build a blog with Rails, and compose posts, all from TextMate.

Patrick Reagan said on 05/12 at 08:18 AM

@Andy: Typo is one of the blogging engines that is “officially” supported by the TextMate blogging bundle.  For the others, they may support the Metaweblog API out of the box and be able to handle posting from TM quite easily.  If you want to roll your own, check out ActionWebService for Rails and this post from Patrick Lenz on how he got it working with Typo.  That said, getting ActionWebService working with Rails 2.x may be the bigger challenge.

Jacob Fentress said on 05/13 at 01:11 PM

@Patrick: Nice work. For what it’s worth, I don’t consider any install of ExpressionEngine complete until the Markdown and SmartyPants plugins are installed. In fact, I install Mark Huot’s MarkyPants plugin that combines Markdown and SmartyPants. This can then be set as the default formatting for any weblog field. It sure beats the snot out of EE’s xhtml formatting.

As a side note, I like to use the Comment Text Formatting Extension to apply (in my case) Markdown to comments posted on the site.

Patrick Reagan said on 05/14 at 08:35 AM

@Jacob: Thanks.  We’re planning to do some more upgrades to our blogs in the near future.  I don’t immediately have a need for Smarty support, but I plan to check out the Markdown plugin.  Based on my experience with EE so far, I’m assuming that I’ll just need to add “Format: markdown” (or similar) to my posts in TM to have it “just work.”

Jacob Fentress said on 05/14 at 08:51 AM

@Patrick: Yeah, I don’t see why that wouldn’t work in TextMate once you have markdown set as a formatting option for that field.

No SmartyPants!? Well, I thought that too when I first started playing with it, but I’ve become a much bigger fan of web typography over the last year or two. I love SmartyPants simply for converting straight quotes to curly quotes in entries - especially on installs where I am not posting everything myself. The conversions for em and en dashes are especially helpful too. I can never remember the proper html entities (not to mention the pain of typing them) for those characters.

Patrick Reagan said on 05/14 at 09:01 AM

@Jacob: Ah - I misunderstood.  I saw “Smarty” and immediately thought of the templating engine for PHP.  I’ll take a look at both, then.  Thanks!

Ian said on 06/09 at 04:35 AM

This is quite a useful post. I hadn’t explored TextMate’s blogging bundle until now and being an EE user I think this is how I’ll be blogging from now on.

One slight problem though.  I set the blog up fine but when I tell it to Fetch Posts it returns the list of headers as expected but when I select one only the header information is shown and not the article text.  Any idea why this is happening?

Thanks Patrick.

Patrick Reagan said on 06/12 at 07:23 AM

@Ian: I personally haven’t seen this behavior.  What happens when you create a new post in TextMate (as a test) and then publish it to ExpressionEngine?  Does the text show up when previewing the post in EE?  Can you re-retrieve the test post and view the body?

Ian said on 06/23 at 05:27 AM

@Patrick: I managed to get it sorted in the end. It was more of a silly mistake by not checking which field was selected to get the output from. It was on extended rather than body so changing this got it fixed. :)

Thanks.

btw, do you use the default captcha on your site or is it a plugin?

Doug Avery said on 06/24 at 01:20 PM

Ian, that’s EE’s default Captcha. We tried a more accessible (question/answer-based) one, but had issues with it filling up server memory, so we’re sticking with this one for now.

Name:

Email:

URL:

Not a robot? Prove it by entering the word below.


Remember my personal information

Notify me of follow-up comments?

A Development Community for Viget Labs and Beyond

Every team member here at Viget Labs strives to be an innovator. We members of the development team are no different - that's why we're constantly engaging in community discussions and exploring the unknown that is the next generation of open-source web applications.

Viget Is Hiring!

Viget has job openings for Ruby Developers, Interns, and Front-End Developers. Learn More »

Recent Comments

In my quick testing of this it does still work if you chain items after the cache name:

Category.top_level.other_scope

But important to note is this will still make a call to the database, it will not take advantage of the cache. Of course the actual scope, in this case find_top_level is unchanged and so you can still do any chaining with that, which also of course won’t use the cache.

As a final note though if you’re needing to do much chaining, caching in this way may not be best for your particular situation. The idea of the cache is if you need to retrieve the exact same result set over and over again, and it rarely changes you shouldn’t have to hit the database.