CSS Asset Tagger Rails Plugin

December 3rd, 2009

We’ve released a new plugin for Rails that adds asset timestamps to assets found in an apps stylesheets.

The plugin is available at http://github.com/redlinesoftware/css_asset_tagger

Simply install the plugin and it will tag any assets in your css files with asset timestamps. More information on asset timestamps can be found at http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html

We wrote a previous article on using asset timestamps with nginx, but similar usage applies to Apache as well for example.

The main purpose for writing this plugin is that stylesheets that use images for various things don’t get tagged with the asset timestamps when they’re written as plain old css files. These images can’t make use of expiration techniques very easily without the timestamps. So to make things work as they do with images in rails views, this plugin will add the same timestamps to assets in css files as they are in rails views.

Before…

#navigation_bar {
  background-image: url(/images/background-nav.png);
}
After…

#navigation_bar {
  background-image: url(/images/background-nav.png?1234567890);
}

If you’re using yslow and some decent expiration on the server and you don’t like seeing images from your css files being shown in your report card, this plugin should make those all go away and hopefully give you a better grade. :)

Plugins moved to Github

June 21st, 2009

We finally got around to moving our plugins from our old SVN machine into Github. Although we’ve been using Git for a long time, we were slow on moving our plugins for some reason.

github.com/redlinesoftware

This is my second tutorial covering the plugins that we’ve developed.

This tutorial covers the human attribute override plugin.

The plugin allows humanized versions of attributes to be overridden with custom strings to provide a better conversion than human_name may provide.

Why?

The main reason for creating this plugin is that Rails doesn’t always provide an acceptable “humanized” version of an attribute name.

Column.new('num_employees', ...).human_name # => 'Num employees'

You could argue that perhaps the attribute should be named number_of_employees..

Column.new('number_of_employees', ...).human_name # => 'Number of employees'
But this is hardly an acceptable solution for various reasons
  1. The attribute name is too wordy.
  2. Changing an attribute name for the sake of it’s humanized version reading better results in unneeded refactoring.
  3. You’re using a legacy database that uses a specific naming convention.
Read the rest of this entry

Conditional Cache Plugin Tutorial

November 26th, 2007

Update

This plugin has now been DEPRECATED for Rails 2.2+ in favour of the built in :if and :cache_path options.

The following changes can be made to use :cache_path instead of the :tag option.

  1. Change all instances of :tag to :cache_path
  2. If the :tag referred to a sybmol such as :tag => :standard_tag, you simply need to change the method name that the symbol refers to as standard_tag_url (just add _url to the end of the method name).
  3. The host name no longer prefixes the cache fragment when :cache_path uses anything other than a hash, so make sure to begin your cache_path with the string generated from request.url (includes protocol) or request.host + request.request_uri (no protocol) if your cache fragment keys depend on the host name.

Updated for Rails 2.1

This is my first of many tutorials to come covering the plugins that we’ve developed.

This tutorial covers the conditional cache plugin, which is actually the first plugin released by Redline.

Why?

By default, the caches_action method allows you to specify one or more actions to apply caching to.

class TestController < ApplicationController
  caches_action :index, :new

  def index
    ...
  end

  def new
    ...
  end
end

In the above example, action caching is being applied to the index and new action. Beyond that we have no additional control over when these actions should be cached or how these actions should be cached. It’s either all or nothing.

So to fix this “all or nothing” problem, the conditional cache plugin adds additonal functionality to the caches_action method by adding 2 additional parameter options that can be passed to the method along with the existing list of actions.

Read the rest of this entry

Conditional Cache updates

October 25th, 2007

I’ve recently fixed a bug in our conditional cache plugin that I introduced while making it compatible with Rails 1.2.4.

The bug has been fixed and the plugin also works with Rails 1.2.5.

The bug was causing the wrong cache paths to be created, so if you updated the plugin, update again ASAP.

The conditional cache plugin has been updated to be compatible with Rails 1.2.4. If you’re still using a previous version of Rails, there is no need to upgrade the plugin.

Update: Compatible with Rails 1.2.5 now

New in_place_editor plugin

July 23rd, 2007

I have just released a new plugin that can be found at http://agilewebdevelopment.com/plugins/improved_in_place_editor

This plugin allows all options of the Ajax.InPlaceEditor control to be set. This will also work with the new rewrite of the control, which is currently in the scriptaculous trunk.

This plugin replaces the current rails version of in_place_editor and is drop-in compatible.

Quick summary (more details at the url above)...

Missing options such as onFailure can now be specified…

<%= in_place_editor 'field_id', :on_failure => "function(transport) {alert(\"Error: \" + transport.responseText.stripTags());}" %>

Some options require quoting to be valid in the JS, such as :highlight_color.[1]

1 :highlight_color is the option name for the rewritten version of the control, :highlightcolor is the old name.

The 2 ways to specify the option are…

1) Manually quote the option
<%= in_place_editor 'field_id', :highlight_color => "’#000000’" %>
2) Use the :quoted option
<%= in_place_editor 'field_id', :quoted => {:highlight_color => ’#000000’} %>

Check out our other available plugins at http://agilewebdevelopment.com/plugins/owner/72

Updated conditional_cache plugin

February 20th, 2007

Just a quick note... I've updated our conditional_cache plugin (http://www.agilewebdevelopment.com/plugins/conditional_caching) to be more in sync with the current rails cache code that this plugin overrides.

Enjoy!