Typo 2.5.8

Well, that was fun. Typo 2.5.7 lasted 80 minutes, only to be replaced by 2.5.8.

This is a security release, fixing a bug that has been in Typo since at least 2.5.0. All Typo users should upgrade to either 2.5.8 or the current Subversion trunk.

Posted by Scott Laird Wed, 09 Nov 2005 01:44:36 GMT


Typo theme engine

Typo has had theme support since before Typo 2.5.0 was released, but the first version of Typo’s theme engine didn’t include the ability for themes to change any of the HTML generated by Typo’s views. Themes could change CSS, graphics, and the top-level layout that generated the HTML for the site, but individual HTML blocks, like comments or article bodies, couldn’t easily be changed.

The latest release, Typo 2.5.7, fixes this shortcoming. It’s now possible for themes to completely override any bit of HTML or XML that Typo generates. Here’s how it works:

Like all Rails apps, Typo stores all of its HTML views in app/views/<controller>/<viewname>. For example, the view that generates individual article pages is app/views/articles/read.rhtml. The theme system in Typo 2.5.7 and newer lets themes override views by putting a replacement file into themes/<themename>/views/<controller>/<viewname>. So if I created a new theme called scottstuff and wanted to override the read.rhtml view from above, I’d put the new view into themes/scottstuff/views/articles/read.rhtml. Typo would then read this view from the theme instead of app/views.

It’s also possible to replace the HTML generated by sidebar plugins; just put the replacement view into themes/<themename>/views/plugins/sidebars/<sidebarname>/content.rhtml.

Typo should pick up on the new views immediately, even in production mode, but you’ll have to flush the page cache before the views really take effect.

Posted by Scott Laird Wed, 09 Nov 2005 00:46:00 GMT


Typo 2.5.7 is available

I just released Typo 2.5.7. This is a relatively minor upgrade over 2.5.6, but it adds two important features:

  1. Support for Rails 0.14.x. Due to one little change, Typo 2.5.6 worked fine with Postgres and the new Rails, but MySQL failed horribly. This should now be fixed.
  2. Support for overriding views from within themes. The theme contest folks really want this, and it’s been available in the trunk for months, so I backported it.

Posted by Scott Laird Wed, 09 Nov 2005 00:22:12 GMT


Typo 2.5.7: testers wanted

I’d love to release Typo 2.5.7 today, but I’d like a few people to verify that the current 2.5.x Subversion repository actually works correctly in their environment first. If you’re interested, please grab it from svn://leetsoft.com/typo/branches/branch_2_5_x and kick the tires. I’ll take feedback any way I can get it–via IRC, direct mail, the Typo mailing list, or comments here. I’d prefer not to clutter up the Typo trac with this, though, as there’s no good way to say that the report is about the 2.5.x SVN tree.

Posted by Scott Laird Tue, 08 Nov 2005 17:11:00 GMT


Typo 2.5.7 developments

I’m just about to start in on Typo 2.5.7 development. I have two goals for this update to Typo 2.5.6:

  1. Make Typo work correctly with Rails 0.14.x.
  2. Backport the new theme updates from the Typo trunk to the 2.5 series so Typo Theme Contest developers can use them.

I’d like to have this on RubyForge before I leave for the airport on Wednesday.

Posted by Scott Laird Tue, 08 Nov 2005 04:42:18 GMT


Mind Camp, in one thousand words or less

Posted by Scott Laird Tue, 08 Nov 2005 04:22:11 GMT


Electric cars have lots of torque

Ouch!

This is the Tango electric car that Commuter Cars was showing off at Mind Camp. Apparently they had a little mishap getting it out of the lobby of the building, and now they slammed the little thing into the fence.

It’s an amazingly small car, but it’s a lot tougher then it looks. The center of gravity on that thing is only a few inches off the ground, thanks to 2,000 lbs of batteries, and the body is carbon fiber. There’s no way that I can afford what they’re asking, but it’d be a great commuting car.

Posted by Scott Laird Tue, 08 Nov 2005 04:16:23 GMT


Travelling to the Bay Area

I’m going to be in Sunnyvale for a while later this week, and I’m completely free on Thursday evening. Does anyone have any suggestions?

Posted by Scott Laird Tue, 08 Nov 2005 03:47:52 GMT


Counting RSS users

One of the great problems with RSS is that it’s really hard to know how many readers you have. Feedburner is supposed to be able to help with that, but I’m reluctant to outsource my RSS feeds to them–I’m not really sure how I’d get them back if I decided to can Feedburner. So, while I know that I’m averaging around 1,300 JavaScript-enabled page hits per day on my blog, I have *no* idea how many people are reading via RSS. On one level, it doesn’t really matter, but I find that I’m more willing to write when I know that people are reading, and the more readers I have, the more time I’m willing to spend writing.

The problem is that there isn’t a 1:1 correspondence between RSS downloads and readers, like there is for normal web pages (modulo caching and a few other issues). Bloglines is helpful enough to tell me that it has around 60 subscribers, and I know that I’ve served up around 24,000 RSS and Atom feeds so far this month, but I have no easy way to know if that’s 1,000 people with a slow refresh set or 11 people refreshing every 5 minutes, or even 50,000 people all reading via a portal. Plus, there are at least three “planet” sites syndicating one feed or another (PlanetRubyOnRails, PlanetTypo, and Planet Foo), and I have no clue how many readers they have, either via HTML or RSS.

I’ve been tempted to integrate a 1-pixel “web bug” into Typo’s RSS feeds more then once, but I don’t really like the privacy implications. Fortunately or unfortunately, I get the same effect any time I post an image here. The Flickr montage that I posted almost 8 hours ago has resulted in 347 image hits. Of those, 150 have no referrer, so they’re probably from standalone RSS readers, like NetNewsWire. Another 95 are from scottstuff.net, followed by 42 from Planet Ruby On Rails, then 24 from Bloglines, 16 from Planet Typo, 3 from Planet Foo, 3 from Google Reader, and a couple that are either comment spammers or internal feeds from stealth companies.

Does anyone have any good leads on how to track this sort of thing on a more regular basis? While we’re at it, does Feedburner just play session cookie games, or are they doing something clever? Finally, it seems clear that embedding images into RSS feeds works most of the time, but I’ve never heard of anyone using web bugs with RSS–did I just miss the discussion, or are people avoiding them?

Posted by Scott Laird Tue, 08 Nov 2005 03:43:42 GMT


Typo Theme Contest, again

As a reminder, the Typo Theme Contest is still running. The deadline for entry is November 28th, so there’s still time to start, but you don’t want to wait much longer. The prize pool has grown again–the top prizes are a new 15” PowerBook, a 12” iBook, an iPod Nano, and a year’s free hosting. Although it pales in comparison to a new PowerBook, I’d love to bundle the top couple themes with future Typo releases, so you can count on thousands of Typo users enjoying your work.

Posted by Scott Laird Tue, 08 Nov 2005 02:53:16 GMT


Flickr montages

I’ve been working on a cool new toy–a Ruby script that sucks up all of the images from a Flickr photo set and turns them into a random montage. The results are surprisingly pleasing, at least to me:

Once we’ve pushed the next Typo release out the door, I have a few ideas for cool and useful things to add to Typo, but you’ll have to wait to see what they are.

Posted by Scott Laird Mon, 07 Nov 2005 19:28:45 GMT


Seattle MindCamp

I’m spending the day at the Seattle Mind Camp. The network has been a bit flaky for most of the day, but I think it’s finally under control, so I’m taking the chance to upload a couple dozen shots to Flickr.

I’m kind of overwhelmed with content right now, and I’m not sure that I’ve been making the right choices when it comes to which sessions to attend, but I’m enjoying myself one way or another. On the cool hardware front, I finally had a chance to try out a head-mounted display from Microvision. Cool, but the model that I tried was a bit old and hard to read. I think I would have had a nasty headache if I’d used it for more then 5 minutes, but the owner said that he’d felt the same way at first and was able to use it for 5 hours without ill effect. I also got to drive the Titan Robotics Club’s robot a bit. I’m still waiting to use the Segway.

Later tonight, I’m going to run a “what do you wish that you could do with your blog that you can’t right now” session. If you’re here and you’re able to get enough connectivity to read this, then please stop by at 11:00 tonight. I’d love to find new ideas to snarf into Typo, although I’m really more interested in getting a better grip on how people use blogs and where we’re heading. I’ve talked with several people who are interested in discussing various aspects of Typo and directed one towards the Typo Theme Contest.

Posted by Scott Laird Sun, 06 Nov 2005 02:21:12 GMT


Typo moves to Rails 0.14.2

As of this morning, the Typo trunk requires Rails 0.14.2. I ran rails . and then spent a couple hours cleaning up Rakefile and environment.rb, and then updated all of the tests to work without instantiated fixtures. As advertised, this makes tests run quite a bit quicker; since Typo’s test suite had been flirting with the 5 minute mark on my laptop, anything that we can do to speed up tests is welcome.

Now that we’re safely requiring 0.14.x versions of Rails, I’ve started adding session :off all over the place. My sessions table for scottstuff.net has around 70,000 sessions in it right now, and I doubt that more then 15 or 20 of them were ever useful. We use sessions for user authentication, but that really only matters for admin pages plus a few other cases, like comment posting. In essence, any page that can be cached will never need access to a session. So, I made a little change to the Article controller. Instead of

class ArticlesController < ApplicationController
  caches_page :index, :read, :permalink, :category, 
    :find_by_date, :archives, :view_page, :tag

  ...
end

I’m now using

class ArticlesController < ApplicationController
  cached_pages = [:index, :read, :permalink, :category, 
    :find_by_date, :archives, :view_page, :tag]
  caches_page *cached_pages
  session :off, :only => cached_pages

  ...
end

This is a really common pattern, because pages that can use the page cache really shouldn’t depend on the session in any way. If I was doing this in more then one place, I’d probably want to extract it into a nice little plugin, but I’m just not feeling the motivation right now.

Posted by Scott Laird Fri, 04 Nov 2005 19:06:20 GMT


to_proc

Dave Thomas just pointed out a great little hack from the Ruby Extensions Project. They added this little snippet to Object:

def to_proc
  proc { |obj, *args| obj.send(self, *args) }
end

and now instead of writing this:

result = names.map {|name| name.upcase}

you can write this:

result = names.map(&:upcase)

The “wave this method over all objects in a collection” idiom is very common in Ruby, and Ruby’s native block syntax isn’t too bad for this use, but it’s not as clean as Python’s list comprehension syntax would be:

result = [n.upper() for n in names]

With the to_proc hack in place, Ruby’s code is a bit cleaner, at the cost of using a non-standard extension to the language. Personally, I’d prefer to see map extended to take an optional symbol, then we could ditch the ugly & when we’re using a single method with no parameters.

Posted by Scott Laird Thu, 03 Nov 2005 23:02:49 GMT


Migrating in two dimensions

This seems to be the season for talking about Rails migrations. A lot of people are finally discovering them and finding that they’re very useful for maintaining your database schema over time. I’m a big fan of Rails migrations; we’ve been using them with Typo since the middle of July, when they were all new and shiny. We’re currently up to 24 migrations in the Typo source tree. We’re even using migrations to create our initial database, via my Schema Generator. I haven’t done a formal survey, but I suspect that Typo is the biggest open-source user of migrations, and may actually be the biggest user overall.

The big problem is that we’ve been using migrations wrong the whole time, and we just realized it.

There are probably a dozen bugs in Typo’s bug tracker that boil down to “I fell behind the trunk and now rake migrate throws exceptions and I can’t upgrade anymore.” The problem is that migrations are designed to run against an earlier version of your database, but they use the current version of your code. The first time that this caused problems was with the migration from Typo 2.0 to 2.5–we’d added two new fields to articles. Migration number 7 added the permalink field and a before_save hook to make sure that all saved articles have permalinks. Then migration number 9 added GUIDs and a second before_save hook to fill the guid field. Both migrations did Articles.find(:all).each { |a| a.save } to update each Article and populate the new fields.

This worked great for developers who frequently upgraded. A few days after the GUID migration went in, though, we started getting weird bug reports–users who tried to do both upgrades at the same time found that migration number 7 was dying. What was happening was that migration number 7 added the new permalink field to articles, but when it went to run the save loop both before_save hooks ran, and Typo tried to add a GUID to each article. However, the guid field didn’t exist yet, so the migration threw a bunch of exceptions and died.

This caused a bunch of grumbling on the Typo IRC channel. We threw around a bunch of possible fixes. Our favorite was separating migrations into two parts–a schema change part and a data change part. First we’d run all of the schema changes, and then update all of the data. As a work-around, we added a hack that checked the current schema version and disabled specific before_save filters for older versions.

We managed to keep this little bandaid working until a couple weeks ago, when a huge set of new migrations went it; they renamed the articles table and merged several other tables into the new contents table using STI. And, again, we found that older migrations broke when users tried to upgrade from Typo 2.5.6 to the current dev tree. Unlink the permalink/guid case, this time there was no simple workaround. We couldn’t just add a couple if statements in a filter and make it all go away.

The fundamental problem is that we were using the wrong mental model for migrations. I saw migrations as a one-dimensional thing–a list of steps for migrating old data into the new format. In this view, the migration for going from schema version 6 to schema version 7 is constant–once it’s been written, the only reason to change it is if a bug turns up in the logic for that migration. Otherwise, the migration code should remain unchanged over time.

And that’s the problem–migrations aren’t one-dimensional. They are (and need to be) two dimensional–the schema version is one dimension and the code version is the other. Individual migrations exist to migrate from a specific old schema version to the current version, using the current code. Each migration should change over time to adapt to the changes in the code. So, the right fix for the permalink migration that caused so many problems wasn’t to add a bunch of logic to before_save. Instead, we should have deleted the entire save loop from the migration, and trusted the GUID migration to update both fields. If that wasn’t good enough, then we should have added a new migration at the end to do permalink cleanup after the GUIDs were added.

Once I came to grips with this, the migration changes needed to allow 2.5.x users to upgrade to the current trunk were pretty simple, and took about 5 minutes to write and test.

Or was I the only person in the Rails universe who thought about migrations this way?

Posted by Scott Laird Mon, 31 Oct 2005 16:32:42 GMT