[Rake-devel] Multi-part extensions in rules?...

Jim Weirich jim at weirichhouse.org
Mon Apr 2 22:08:05 EDT 2007


Stuart Hungerford wrote:
 > I'm using Rake to build various versions of some image files and
 > would like to setup a Rake rule like this:
 >
 > rule ".50.png" => [".tiff"] do |r|
 >     # do stuff with r
 > end
 >
 > The rest of the Rakefile sets up a bunch of file tasks where a
 > ".50.png" depends on a ".tiff" file.  However Rake doesn't seem
 > to recognize those rules for me and I'm not sure why, so I tried
 > a more general regex based rule:
 >
 >
 > rule(/\.50\.png$/ => [".tiff"]) do |r|
 >      # do stuff with r
 > end

The problem is that (by default), rake doesn't recognize ".50.png" as a 
file extension.  The second rule using a regexp addresses part of the 
problem, but it doesn't go far enough.  You also have to tell rake how 
to find the source file a match for the rule.  Given that it's trying to 
build 'xxx.50.png', it will try to find a 'xxx.50.tiff'.  If you want to 
drop the 50 part, you have to give rake a proc that convert from the 
.50.png to just .tiff.  Something like this:

   rule(/\.50\.png$/ => proc { |fn| fn.sub(/\.\d+\.png$/, '.tiff') }) do |r|
     cp r.source, r.name
   end

I hope I understood your problem correctly.  Does that help?

-- 
-- Jim Weirich      jim at weirichhouse.org     http://onestepback.org
-- In theory, practice and theory are the same.
-- In practice, they are different.



More information about the Rake-devel mailing list