UPDATE:
There is now a version 0.9 available (download).

The bundled_resource Plugin

Hot on the heels of my previous announcement, there is now a bundled_resource plugin that takes advantage of all of my previous work in this area at syncPEOPLE, plus some (download).

What’s it for?

If your development is in any way similar to mine, there are a number of useful resources out there that make web applications shine beautifully. For example, there’s the Dynarch calendar and the textarea tools. There are a number of others—too many, in fact. The problem is that as a web developer, it sometimes takes some real surgery to put each one of these in to an application. And then when you create a new page that uses these resources (even within the same app), you have to figure out which pieces to cut and paste to get it functional. Take the Dynarch calendar, for instance. There are 4 javascript files, 1 CSS file (among several to choose from), 2 images, several helper methods, and a controller method that you’ll need in order to get it to work with Rails. Sometimes it’s easier just to ignore the calendar bit because it’s such a pain to set up.

How does BundledResource help?

But what if it weren’t a pain? What if you could write this at the top of your page:

<% require_bundle :dynarch_calendar %>

And your dynarch calendar would just work? That’s what bundled_resource does. Now you can use this method:

dynarch_date_select 'post', 'publish_date'

anywhere on the page, and it’ll work. Easy :)

So it looks easy… what’s going on?

What the bundled_resource plugin does is it keeps all of your resources (javascripts, stylesheets, images) within the plugin’s directory structure and copies them in to the public folder whenever your app starts. This is very similar to James Adam’s technique that he uses with Rails Engines. The advantage, of course, is that you don’t have to worry about copying and pasting files all over the place whenever you want a new bundled_resource. They all belong together in one little folder inside the plugin.

Pre-packaged Bundles

Included with this release (0.7) are three bundles: the Dynarch Calendar, Textarea Tools and qForms. Setting up an app to use them is simple:

  1. Install bundled_resource
  2. Add the following two lines to your layout (just like the RequireResourceHelper):
    <%= stylesheet_auto_link_tags %>
    <%= javascript_auto_include_tags %>
  3. Add a require_bundle :[bundle name] at the top of your view file.
  4. For example:

    require_bundle :qforms

And that’s it! Welcome to Easier Resource Management for Rails.