<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Paper Bits &#187; textmate</title>
	<atom:link href="http://metacarpal.net/blog/archives/tag/textmate/feed/" rel="self" type="application/rss+xml" />
	<link>http://metacarpal.net/blog</link>
	<description>digital, paper, notes and bits.</description>
	<lastBuildDate>Fri, 15 Oct 2010 17:36:51 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>HOWTO: configure MarsEdit or TextMate&#8217;s Blogging Bundle to work with Drupal</title>
		<link>http://metacarpal.net/blog/archives/2009/06/26/howto-configure-marsedit-or-textmates-blogging-bundle-to-work-with-drupal/</link>
		<comments>http://metacarpal.net/blog/archives/2009/06/26/howto-configure-marsedit-or-textmates-blogging-bundle-to-work-with-drupal/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 18:40:02 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[textmate]]></category>

		<guid isPermaLink="false">http://metacarpal.net/blog/?p=373</guid>
		<description><![CDATA[If you run a drupal site, and want to post to it via blogging software such as MarsEdit or the TextMate Blogging bundle, you may get some odd errors. Here is an explanation and workaround for these (and other) client software.]]></description>
			<content:encoded><![CDATA[<p>If you use third-party blogging software (such as <a href="http://www.red-sweater.com/marsedit/">MarsEdit</a>), you may have some trouble configuring that client to work out of the box with <a href="http://www.drupal.org/">Drupal</a>.</p>

<p>See, Drupal 6.12 comes with the handy &#8220;Blog API&#8221; module: it gives your Drupal site an XML-RPC interface. In english, that means that you can post content to a Drupal-based website using client software such as <a href="http://www.macromates.com/">TextMate</a> and <a href="http://www.red-sweater.com/marsedit/">MarsEdit</a>. This is nice.</p>

<p>So, assuming <code>http://example.com/</code> is your drupal install, you can feed an URL of <code>http://example.com/xmlrpc.php</code> to MarsEdit, and happily post and edit content to Drupal. And bunnies and squirrels will dance around the meadow in joy and fling flowers in the air.</p>

<p>Yes.</p>

<p>Well.</p>

<p>In theory, there should be no difference between theory and practice. In practice, there will be.</p>

<h3>HOWTO: make Drupal work with MarsEdit</h3>

<p>MarsEdit is pretty easy to set up, but there&#8217;s one minor hiccup, caused <a href="http://drupal.org/node/219818">by a bug in Drupal&#8217;s blogAPI module</a>. Here&#8217;s a quick run through the setup process:</p>

<p>Let&#8217;s add your blog to MarsEdit. Select <code>New Weblog...</code> from the <code>File</code> menu. A friendly window appears: &#8220;Tell us about your weblog&#8221;. Go ahead and plug in the base URL of your drupal site. If the autodiscovery bug I mentioned has not been patched, then you will get a dialog that says, in effect, &#8220;I am a stupid computer and cannot figure this out, so you will have to do it for me&#8221;. If you <em>don&#8217;t</em> get this message, then the bug has been fixed. Hooray!</p>

<p>Otherwise click <code>Edit Settings</code> and you will be presented with a dialog box like the following:</p>

<p><img src="http://metacarpal.net/blog/wp-content/uploads/2009/06/screen-capture-of-marsedit-dialog-box.png" alt="Screen capture of MarsEdit dialog box" /></p>

<p>I&#8217;ve selected most of the (likely) correct options in this box, but notice the field labeled <code>Blog ID:</code> (helpfully highlighted above). This is where you have to check your settings in Drupal, because you have to choose the <em>type</em> of content you will be submitting via your client.</p>

<p>Drupal allows the definition and creation of different <em>content types</em>. You get to them via the administrative menu, under <code>Administer &gt; Content management &gt; Content types</code>. (This should have the path of <code>http://example.com/admin/content/types</code> in your browser address bar.)</p>

<p>For example, you can see that my site currently has two content types: <em>blog</em> and <em>page</em>:</p>

<p><img src="http://metacarpal.net/blog/wp-content/uploads/2009/06/drupal-content-types.png" alt="Screen capture of drupal config showing the blog and page content types" /></p>

<p>You&#8217;ll notice that the <em>blog</em> type has the <em>Name</em> <code>Blog Entry</code>, and the <em>Type</em> <code>blog</code>.</p>

<p>The <em>type</em> is your <code>Blog ID</code> for MarsEdit.</p>

<p>If you want to create pages of that type with MarsEdit, you want to put <code>blog</code> in to the field marked <code>Blog ID</code>. If you created a custom content type named <code>Wiki Notes</code> with the type <code>wiki</code>, and you want to post those notes using MarsEdit, you want to enter <code>wiki</code> in that field.</p>

<p>And that should work.</p>

<p>Hooray.</p>

<h3>HOWTO: make Drupal work with TextMate</h3>

<p>The <a href="http://blog.macromates.com/2006/blogging-from-textmate/">TextMate Blogging Bundle</a> provides a sparse (but pleasant to use) interface for the creation and editing of blog entries directly inside the text editor. I&#8217;m using it right now to compose this post.</p>

<p>Sadly, when I tried to access the drupal blogAPI from it, Drupal threw an error: <q>Blog API module is not configured to support the 0 content type</q></p>

<p>Hmm.</p>

<p>Okay, so <em>content type</em> is basically the <code>blog_id</code> in XML-RPC terms. So I guessed that TextMate wasn&#8217;t specifying the blog ID, and was passing the default value (which I know from past, painful experience is 0). So I had to configure TextMate to specify that blog ID value somewhere. But where?</p>

<p>The TextMate Blogging Bundle invokes a ruby script, <code>[$TM_BUNDLE_PATH]/lib/blogging.rb</code>, which parses a file called <code>com.macromates.textmate.blogging.txt</code>. Here, with URLs obfuscated, is mine:</p>

<pre><code>  # List of Blogs
  #
  # Enter a blog name followed by the endpoint URL
  #
  # Blog Name         URL
  Paper Bits          http://some_path_to_wordpress_stuff
  Drupal Blog         http://www.example.com/xmlrpc.php#blog
</code></pre>

<p>See that bit on the end of the <code>Drupal Blog</code> line? The <code>#blog</code>? <em>That&#8217;s where the magic lives</em>.</p>

<p>Translation: To get TextMate working with Drupal&#8217;s blogAPI module, put a <code>#typename</code> at the end of the XML-RPC URL.</p>

<p>If your content type is <code>wiki</code>, then you want <code>http://www.example.com/xmlrpc.php#wiki</code> under URL.</p>

<p>And that&#8217;s it.</p>

<h3>What&#8217;s happening here?</h3>

<p>In case you care, I found this by digging into the <code>[$TM_BUNDLE_PATH]/lib/metaweblog.rb</code> and <code>[$TM_BUNDLE_PATH]/lib/blogging.rb</code> scripts.</p>

<p>In <code>metaweblog.rb</code> the methods all require a <code>blog_id</code> to be passed along with the method call. An example:</p>

<pre><code>  def get_recent_posts(blog_id, username, password, number)
    call("metaWeblog.getRecentPosts", "#{blog_id}", "#{username}", "#{password}", number)
  end
</code></pre>

<p>Okay, so, let&#8217;s do a search in <code>blogging.rb</code> for the variable <code>blog_id</code>. We find a method called <code>parse_endpoint</code> which features the following:</p>

<pre><code>  def parse_endpoint
    # we have an endpoint that looks like a URL
    [...]
    # guess the mode based on the endpoint path
    [...]

    if @endpoint =~ /#(.+)/
      @blog_id = $1
    else
      @blog_id = "0"
    end
  end
</code></pre>

<p>Aha. That&#8217;s a regular expression. It&#8217;s looking for <code>#something</code> at the end of the URL, and setting that as <code>blog_id</code>. And if it doesn&#8217;t? It sets &#8220;0&#8243;. Which is the offending element from my rogue error message.</p>

<p>So, I made a guess, and it worked.</p>

<p>Hot damn.</p>

<h3>Moral of the story</h3>

<p>This post began as a plea for help to the lazyweb. I had solved the MarsEdit problem (it was a simple matter of a single Google search), but couldn&#8217;t manage to get TextMate running.</p>

<p>In order to write this post, I had to explain my problem with TextMate in a clear and concise manner to an educated but unfamiliar audience. Which meant thinking along lines like, &#8220;well, they&#8217;re probably going to ask me if I looked to see if TextMate submits a blog ID like MarsEdit. I wonder where that would be kept?&#8221;</p>

<p>Eventually, I solved my own problem.</p>

<p>I hope that the next time someone else has the same problem, the great Google technical support repository pops this article up for them, and saves them some time and pain. If that&#8217;s you, then excellent.</p>

<p>If you&#8217;re still having trouble, try writing an email to the smartest person you know. You might end up solving it yourself.</p>

<p>Good luck.</p>
]]></content:encoded>
			<wfw:commentRss>http://metacarpal.net/blog/archives/2009/06/26/howto-configure-marsedit-or-textmates-blogging-bundle-to-work-with-drupal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

