RSS Valid
XHTML Valid
CSS Valid

Blogging with TextMate

Saturday, April 12th, 2008

I’d bet that the majority of TextMate users are super savvy, but did you know that you can blog from TextMate? Most major blogging services/installations use XML-RPC for posting content from locations other than your blogging admin tools (such as Flickr’s “post to blog” feature) and TextMate’s Blogging bundle uses a Ruby library (written and maintained by Brad Choate) to leverage this. Here’s a short how-to on how to set up the Blogging bundle to be able to post, edit, and perform a few other simple actions on your blog - all while writing your markup/post in TextMate.

1. Set up your blogs

In TextMate, go to Bundles > Blogging > Set up blogs. This will open up a a text file where you can define your blogs and the endpoint URL (where the XML-RPC code lives). For example, I use wordpress, so I add a line like so:

# Blog Name      URL
TypeOneError	 http://typeoneerror.com/xmlrpc.php

2. Write your post

Now you can create a new file (probably an empty one) and select “Blog – HTML” or one of the other blogging bundle languages or snippets. Posting to your blog is as easy as Bundles > Blogging > Post to Blog. Type up some text or HTML and select that menu option or just hit Control+Command+p. This will show a few windows allowing you to select which blog to post to and enter your username and password and post. It should open a browser window and show you your published post.

The file you were editing then re-populates with some meta-data at the top. You can edit these to change the blog post. One thing to note is that you can use any of these meta tags before posting. For example I could type “Blog: TypeOneError” and it would bypass the blog selection popup and auto-post to my TypeOneError XML-RPC endpoint (as defined in the blog setup). They are under Bundles > Headers as a series of tab triggers.

3. Activate “Status” and “Slug” for wordpress

There are loads of undocumented header tags as well. You’d have to look at the blogging.rb source file to get all of them (including moveable type and other blog-specific headers). The only ones I felt were necessary for me in using wordpress were these:

Status: draft
Slug: post-slug

Both of these will effect the post, but when the post reloads, they will not be shown. Status accepts either “publish” or “draft” and the Slug is the pretty url slug (part of the final post url). I added a few lines to the blogging.rb file so that changes to these two header metas were reloaded when the post is saved:

#added at line 405 to post_to_document function
#hack
doc += "Status: draft\n" if !self.publish
doc += "Status: publish\n" if self.publish
doc += "Slug: #{self.post['wp_slug']}\n”
#/hack

I just directly went into the TextMate application folder by right clicking and selecting “Show package contents.” If TextMate is installed in /Applications, The full path to Blogging.rb is /Applications/TextMate/Contents/SharedSupport/Bundles/Blogging.tmbundle/Support/lib/blogging.rb. You may want to create a duplicate of the Blogging bundle. I just decided to mod the original.

One thing I really like about this is that you don’t have to worry about wordpress effing up your perfect markup or other code. Also, definitely check out the bad-ass documentation for the Blogging tool under Bundles > Blogging > Help. It provides an excellent overview of using the tools.

2 Responses to "Blogging with TextMate"

  1. Mark Eagleton says:
    April 15th, 2008 at 11:18 am

  2. Daniel says:
    May 24th, 2008 at 9:01 pm

Leave a Reply

Availability

Ben is currently employed as the Development Director at BKWLD in Seattle, Washington and is also available for freelance gigs. Please see the services and contact sections for more information or for work inquiries.