Today I set out to develop a simple proof of concept: a Wiki developed in Ruby on Rails using Subversion as a repository.
Doing a very basic Wiki using RoR is a piece of cake, given the availability of RedCloth and BlueCloth. However, having it use Subversion instead of a relational database is something that needs more work.
Luckily, the latest Subversion release (1.3.2 at the time of this writing) includes full Ruby bindings using SWIG. Unluckily, the precompiled package for OS X that I was using (from the fine folks at Metissian) doesn’t come with the bindings, so I had to reinstall Subversion from the source: nothing really complicated here, but the options for getting it to work over HTTPS should be documented better.
Speaking of documentation, there is apparently none for the SVN Ruby bindings… which is a shame. I could only find something regarding installation thanks to PJ Hyett, why the lucky stiff and Garrett Rooney, but armed with the source, using BountySource’s bsSvnBrowser as a sample (read-only code though, while I need to read and write) and especially Garrett’s book Practical Subversion1, I managed to conjure up some code that, on the surface of it, seems to work.
Here’s a snippet that saves an ActiveRecord instance to the SVN repository:
def save(validate = true)
return false if (validate && ! valid?)
repo = Svn::Repos.open(REPO_PATH)
repo.fs.transaction { | txn |
txn.root.make_file(title)
stream = txn.root.apply_text(title)
stream.write(text)
stream.close
}
return true
end
I’m not sure this the correct way to implement save, but it works.
1. When I reviewed Garrett’s book, I wrote: “It’s written largely from the perspective of a repository administrator or a power user wanting to extend the system and develop new applications on top of it, as the long (73 pages) chapter on Subversion APIs demonstrates.” Finally that long chapter has been useful to me!


Hey there,
This project sounds cool. How far did you get?
Would you be willing to share the code? I’m going to be working with an SVN repo as the datastore for a Rails app, and would love to see some examples!
Thanks.
I didn’t get anywhere unfortunately. Not enough time.
I’m working on something like this for my company. We need a pretty generic version controlled repository for content - office documents, blogging, art assets and code. I’m trying to build everything on top of SVN, and I’m working on the blog portion now.
It’d be great if I could see what you did - of course I will contribute my work back to the community as it approaches usability. I’m trying to put together a high-level, Ruby friendly interface for Subversion.
This is a really cool idea, i was toying around with using Subversion as the data-store for a CMS. The only problem is, aren’t the reads from subversion rather slow? Especially if the repository is hosted on another server?
Anyway, i’d love to hear more about whether it worked efficiently.
I’m interested in this too. I have a CMS system cobbled together in Java that reads from a Subversion working copy that I would like to port to Rails. That bit is pretty easy because a commit hook updates the working copy and the system just reads from the file system. [Justin: that means we don’t have to worry about slow reads.] But my next step, to keep it simpler for my users (but not for me!) is to allow commits to the repository using an admin site. And that will need a bit more thought…
Just come across this:
http://www.oneofthewolves.com/2007/03/06/ruby-subversion-bindings-finally-some-documentation/
cool
I am also trying to use Subversion as the data-store for a CMS. but I am trying to use java instead of ruby