Asset Management with Ruby DSLs

In Miscellaneous

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

Vaguely Related Posts (Usually)

Comments are closed.