The If Works This dirt was a building before

Archive for 2007

Announcement: JS.Class

After mentioning Prototype’s inheritance model the other day, one rather important thing struck me about it. I was going to borrow their model for some of my own work when I realised that, if you use Prototype’s $super feature, your code will break if you compress it using a variable-shrinking algorithm (all the decent compressors [...]

Prototype’s Function#wrap

So Prototype 1.6 has finally hit the streets, and it looks to be a very nice piece of work. Though I’m no longer using Prototype at my day job (we use YUI, plus a layer of syntactic sugar that I’m in the process of writing), I’m interested to see what is possible with the JavaScript [...]

Asynchronous function chaining in JavaScript

Update, 25 February 2008: This class is now available as part of JS.Class (it’s called MethodChain now). It also forms a key part of Ojay, an expressive wrapper for YUI. Update, 12 Dec 2007: Another implementation change. A blank ChainCollector instance now has the following properties: then, and, ____ (formerly __enqueue) and fire. The method [...]

Emulating JavaScript’s String#replace in Ruby

Update: turns out this is a lot easier than the method presented below: see Christoffer Sawicki’s implementation. Consider my method an example of what happens when you’re trying to port features from one language to another and end up looking in all the wrong places for a solution. I know what you’re thinking: we already [...]

Announcing PackR

I’ve no idea who may have done this already, but I certainly coundn’t find anyone who had in five minutes of searching. I’ve written a Ruby port of Dean Edwards’ Packer, and released it as a Rails plugin. It includes a rake task for batch-processing the scripts in your application. Install like so: ruby script/plugin [...]

Why freeze when you can symlink

Just a quick thought: for a while now, I’ve been putting this in my Capistrano recipe, in the :after_update_code task: run “cd #{release_path} && rake rails:freeze:edge TAG=rel_1-2-4″ But what’s the point in exporting the same 5Mb of files every time you deploy? Instead, let’s do this: run “ln -s #{release_path}/../../shared/rails/1.2.4 #{release_path}/vendor/rails” cd into your Capitrano [...]

Reiterate 1.2: operators are (kind of) methods now!

You know how, in Ruby, + is a method? Well guess what: // Count members within a range numbers.findAll({‘>’: 4, ‘<=’: 27}).length // Remove items of a specific type collection.reject(['instanceof', String]) // Assign default values to a collection [27, 0, 'prototype', '', true, false].map({‘||’: ‘foo’}) // -> [27, "foo", "prototype", "foo", true, "foo"] How’s about [...]

LabelHelper is now part of Rails core

It’s official — as of changeset 7541, I’m a Rails Contributor. Hurrah! and so forth. LabelHelper, my plugin for DRY-ing up label tags in forms, is now in Rails core and will presumably be part of Rails 2.0 when it comes out. Now how’s about we get some of these committed as well? Oh, and [...]

Announcing Reiterate

Following on from yesterday’s post, I went a little crazy and expanded the idea of #toFunction to Array and Hash. The end result is Reiterate, which gives you a stack of neat ways to make your JavaScript code more concise and expressive. For example: var strings = array.map(‘toLowerCase.toArray’); var divs = someDivs.findAll({hasClassName: ‘myClass’, visible: true}); [...]

String#toFunction for Prototype

As everybody is no doubt aware, there are new rules for getting a patch into Rails. With that in mind, I thought I’d share some of my patches here in the hopes that one of my army of readers (ha!) will find something I wrote interesting enough to try out for themselves. I’ve got a [...]

← Before After →