Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

Asset Management with Ruby DSLs

By Peter Cooper / May 27, 2006

Jeremy Voorhis has written an interesting, and seemingly overlooked, article about asset management in Ruby and Rails. Firstly he talks about using rake to build a basic asset compiler, and then demonstrates a basic DSL (Domain Specific Language) he created to manipulate image assets in only a few lines of code. An example:

define_image_transformation 'thumbnailize' do
  crop_to '62x62', :north
end

define_image_transformation 'bronze' do
  greyscale
  lighten
  #    r     g     b     tint
  tint 0.25, 0.25, 0.25, '#706000'
end

image_task 'bronze_thumbnail' do
  from images 'images/*.jpg'
  to   build 'greyscale_thumbnail'
  remote_dirs << REMOTE_DIR[:greyscale_thumbnail]
  transformation do
    bronze
    thumbnailize
  end
end

Other Posts to Enjoy

Twitter Mentions