From: Stefan Lang Date: 2005-09-03T03:10:13+09:00 Subject: Re: Rake: multiple prerequisites in rule? On Friday 02 September 2005 16:42, Martin Honermeyer wrote: [...] > I tried writing a Rake task which should automagically recompile > each template upon changing either the .html or the .plogic file. > I've come up with the following: > > desc "Make ERB templates from Kwartz html and plogic files" > SRC = FileList['app/views/**/*.html'] > OBJ = SRC.ext('rhtml') > task :templates => [OBJ] > > rule '.rhtml' => ['.html'] do |t| > sh "kwartz -Rails -e -p #{t.source.ext('plogic')} > --extract=content #{t.source} > #{t.name}" > end > > > This works. The problem is that the .rhtml is only regenerated when > the .html changes. I tried adding the .plogic file as another > prerequisite: > > rule '.rhtml' => ['.html', '.plogic'] do |t| > > That makes Rake say > > Too many dependents specified in rule .rhtml: [".html", ".plogic"] > > > Apparently, it's not possible to have multiple prerequisites for a > rule. Does anyone have a hint on this? Rant allows you to give a block to create the prerequisite name(s) on the fly. The following works with Rant: ############## Rantfile ############################################ desc "Make ERB templates from Kwartz html and plogic files" SRC = FileList['app/views/**/*.html'] OBJ = SRC.sub_ext('rhtml') task :templates => OBJ rhtml_sources = lambda { |target| [target.sub_ext("html"), target.sub_ext("plogic")] } gen Rule, '.rhtml' => rhtml_sources do |t| sys "kwartz -Rails -e -p #{t.prerequisites[1]} --extract=content #{t.prerequisites[0]} > #{t.name}" end #################################################################### To convert the Rakefile to an Rantfile I've: * replaced calls to `ext' with calls to `sub_ext' * replaced `rule' with `gen Rule, ' HTH, Stefan