Tech - September 2007 Archives

Collecting Recursively

Yesterday I was working with an acts_as_tree model and wanted to get all children of the current model as an array. Since there's no descendants method, this is what I came up with.

module Enumerable def rcollect(&block) self.map do |item| collection = block.call(item).compact rescue [] if collection && !collection.empty? [item, collection.rcollect(&block)] else item end end end end class Object def recurse_collecting(&block) [self, block.call(self).compact.rcollect(&block)] end end

Then when I want the model and all its children I do:

model.recurse_collecting(&:children)

May not be useful to everyone, but I found it to be a fun exercise.

Radiant's Near Future

I’ve recently been contracted to work with Digital Pulp on customizing Radiant for a BIG client of theirs. The bright side of this, besides getting paid to work on Radiant, is that much of the work will be released to the community when it’s finished and I’ll be able to contribute updates to the core along the way. Here’s a preview of what’s coming:

  • Facets-like UI mutability, packaged as an extension!
  • “Templates” that constrain the page UI and page parts (similar to the PageAttributes idea)
  • Separating the published versions from working copies, like #502

And much more! Radiant 0.6.3 will probably be released along the way as bugs are fixed, too. I’ll be announcing on my personal blog, on the mailing list, and the Radiant blog as things get released.