Just A Summary

Piers Cawley Practices Punditry

Typo Brain Dump 3

Posted by Piers Cawley Fri, 13 Apr 2007 17:51:00 GMT

In case anyone’s interested, I’ve written a list of some of the things I’m currently mulling doing with Typo below the fold.

Sorting out routes

I’ve mentioned this before I’m sure, but I’m not entirely happy with the current state of Rails’s routing. I’m not talking about the actual underlying code (which is scary enough), more about what it can do. The problem is that you have to know the specifics of what makes up a route in order to generate one. And you have to know it everywhere you use the route. You can make good enough guesses when you’ve got ‘simple’ routes – I wrote acts_as_resource to do just that, but it doesn’t work for Typo’s routes.

Consider the two sorts of things Typo can provide a feed of: articles and comments. In a perfect world we could use pretty much the same builder templates for everything and generate the routes simply by calling url_for(thing), which would generate a link to @/articles/2007/04/13/typo-brain-dump, or /articles/2007/04/13/typo-brain-dump#comment-212 as appropriate. It’s at its ugliest in the comment case. There you are, innocently generating a link to a comment and you’re required to know that its URL is generated from the broken down publication date of the original article and its ‘permalink’, and you have to remember what the parameters are called. Suddenly you’re writing code like:

	article = comment.article
	url_for \
	  :year => article.year, 
	  :month => article.month, 
	  :article.day => article.day,
	  :title => article.permalink,
	  :anchor => "comment-#{self.id}"

Even when you hide that behind a helper method it’s all kinds of ugly. We’ve cheated slightly and taken the view that, since we’re modelling webpages here, it makes sense that they would know their URLs1, so you find a comment’s URL by doing a_comment.permalink_url, which looks like:

	def permalink_url(anchor=:ignored, only_path=true)
	  self.article.permalink_url("comment-#{id}")
	end

But that tends to make people who still think that objects are data structures throw a bit of a wobbly.

My current thinking on how to reduce the pain here is to rejig Rails routing to allow it to multilevel keys, so the basic article URL would be specified as:

	/articles/:article[year]/:article[month]/:article[day]/:article[permalink]

In a perfect world, ‘articles’ would be inflected, so an article’s URL would be /article/2007/04/13/typo-brain-dump, but the URL for all the articles posted in April 2007 would be /articles/2007/04/, but I’ll worry about that. For now I can set up specific routes and have done.

I’ve started work on this, but it’s proving tricky… Ho hum, no reason to stop striving I suppose.

Atom Publishing Protocol

The Atom Publishing Protocol is just lovely. Typo should support it. That is all.

Canvas based rendering

I really don’t like RHTML templates. Or HAML ones. Builder’s okay, but it seems to me that Seaside has this dead right. We should be passing a canvas/builder object to a model’s #render_on method and then calling #to_html, #to_xml, #to_json or whatever on the object we passed in. There’s probably a whole series of posts around this idea, starting with how using such a mechanism would allow for some seriously potent filtering and other capabilities and working up to how we’d make theming work (I think it’s possible to support existing themes with some fancy footwork, but I need to experiment).

A question for the lazy web: Is anyone already doing canvas based rendering in Ruby?

Cruft

There’s too much code in Typo. It could stand to receive some serious pruning and refactoring. The problem with this is confidence in the test suite which manages to be large, fairly brittle and inadequate all at once.

And it’s at least as much my fault as it is anyone else’s. I need to go through the test and get some kind of handle on where it needs to be extended to cover what Typo actually does. And then I need to extend it. And fix the test names. And empty all those horrible YAML fixture files. And…

1 It’s not quite that simple (hah!). Articles and Comments don’t know their URLs, the Blog object is the repository of that knowledge, but they do know which of their attributes are important for building a URL. Comment#permalink_url delegates to Article#permalink_url, which in turn calls Blog#url_for, which mocks up an ActionController and delegates to that.

Comments

Leave a response

  1. Avatar
    Tim Connor 4 days later:

    I completely agree on the to_format/Seaside approach. I was blogging about it from the thinning down the controller angle. Since you can do to_xml, why not hook in to_rss directly to the model, and from there…

    When I posted my thoughts on the core list, the most common response I got was to try a presenter approach.

  2. Avatar
    proxy site 8 months later:

    “I really don’t like RHTML templates. Or HAML ones.”

    what rhtml and haml diffarent from html i never hear about it.

  3. Avatar
    Nadlan 12 months later:

    The fact there is no support for ATOM rss in typo is one of the facts I’m still using wordpress. I’m dying to move to typo, but gotta have ATOM! :)

Comments



Just A Summary