Asset Management with Ruby DSLs
Post by Peter Cooper
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 ‘62×62‘, :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




Del.icio.us
Cosmos








