Trac tools for TextMate

I'm using Trac on a fairly large project, one of the main obstacles for usage is having to use the Web interface to write tickets, wiki-pages so on...

The majority of the 30+ strong team haven't used Trac before, and with all tools, uptake is the most important factor. A large proportion of the team are all Mac based so I'm initially creating tools on that platform.

TextMate a very popular text editor, a favourite of Ruby on Rails developers world-wide, has a bundle (or in regulo-speak, a plugin) for Trac wiki text.

I'm using this a starting point and adding some helper utilities to make the process of using Trac less of a bother.

The first one is the simplest, generate an HTML preview of wiki text from TextMate

If you have TextMate installed and have added the Trac Wiki bundle you can open the Bundle editor and add a New Command (call it Preview, if you like).

Insert the following ruby code :

#!/usr/bin/env ruby

##################################################
# Trac Wiki Previewer for TextMate
# (Uses Trac XMLRPC method 'wiki.wikiToHtml')
##################################################
# jason@mentalaxis.com - Released under MIT Licence
##################################################

$LOAD_PATH << "#{ENV["TM_SUPPORT_PATH"]}/lib"
require 'xmlrpc/client'
                                                   
##################################################
# In TextMate preferences setup the following vars...
# 
# TM_TRACURL : Typically 'http://your_trac_env_url/xmlrpc'
# TM_TRACUSER : trac username
# TM_TRACPASSWORD : trac password
#

tracServer = XMLRPC::Client.new2(ENV["TM_TRACURL"])
tracServer.user = ENV["TM_TRACUSER"]
tracServer.password = ENV["TM_TRACPASSWORD"]       

puts tracServer.call("wiki.wikiToHtml", STDIN.read)

As you'll notice in the code, you need to setup 3 environment vars to make the script work. You'll also need web access to a Trac environment

  • TM_TRACURL : Typically 'http://your_trac_env_url/xmlrpc'
  • TM_TRACUSER : trac username
  • TM_TRACPASSWORD : trac password

Set the command options for Selected Text or Document and output to HTML

You can now view your Trac wiki text as plain HTML from within TextMate

Add comment July 23rd, 2007