# Rake: multiple prerequisites in rule?

**URL:** <https://rubytalk.org/t/rake-multiple-prerequisites-in-rule/20575>\
**Category:** ruby-talk\
**Created:** [2 September 2005 14:42 UTC](https://rubytalk.org/t/rake-multiple-prerequisites-in-rule/20575 "2005-09-02T14:42:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_Honermeyer](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@Martin\_Honermeyer](https://rubytalk.org/u/Martin_Honermeyer)\
**Post date:** [2 September 2005 14:42 UTC](https://rubytalk.org/t/rake-multiple-prerequisites-in-rule/20575/1 "2005-09-02T14:42:06Z")

</div>

Hello,

I am using Kwartz as a templating engine for my Rails project. Kwartz  
compiles an .rhtml (ERB) file from an .html and a .plogic file.

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|  
&nbsp;&nbsp;sh "kwartz -Rails -e -p #{t.source.ext('plogic')} --extract=content  
#{t.source} \> #{[t.name](http://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?

Cheers,  
Martin

---

<div class="post-metadata">

**Author:** ![Stefan\_Lang](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Stefan\_Lang](https://rubytalk.org/u/Stefan_Lang)\
**Post date:** [2 September 2005 18:10 UTC](https://rubytalk.org/t/rake-multiple-prerequisites-in-rule/20575/2 "2005-09-02T18:10:13Z")

</div>

[...]

> 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|  
> &nbsp;&nbsp;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|  
&nbsp;&nbsp;&nbsp;&nbsp;[target.sub\_ext("html"), target.sub\_ext("plogic")]  
}  
gen Rule, '.rhtml' =\> rhtml\_sources do |t|  
&nbsp;&nbsp;&nbsp;&nbsp;sys "kwartz -Rails -e -p #{t.prerequisites[1]} --extract=content  
#{t.prerequisites[0]} \> #{t.name}"  
end

> **···**
>
> On Friday 02 September 2005 16:42, Martin Honermeyer wrote:  
> ####################################################################
> 
> To convert the Rakefile to an Rantfile I've:  
> \* replaced calls to `ext' with calls to `sub\_ext'  
> \* replaced `rule' with `gen Rule, '
> 
> HTH,  
> &nbsp;&nbsp;Stefan

---

<div class="post-metadata">

**Author:** ![Niklas\_Frykholm](https://avatars.discourse-cdn.com/v4/letter/n/9dc877/32.png) [@Niklas\_Frykholm](https://rubytalk.org/u/Niklas_Frykholm)\
**Post date:** [5 September 2005 12:44 UTC](https://rubytalk.org/t/rake-multiple-prerequisites-in-rule/20575/3 "2005-09-05T12:44:27Z")

</div>

Martin Honermeyer wrote:

> 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?

Not as elegant as using a rule perhaps, but you could write

&nbsp;&nbsp;&nbsp;&nbsp;SRC.each {|src|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rhtml = src.ext('rhtml')  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;plogic = src.ext('plogic')  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file src =\> [rhtml, plogic] do |t|

// Niklas

---

<div class="post-metadata">

**Author:** ![Jim\_Weirich1](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Jim\_Weirich1](https://rubytalk.org/u/Jim_Weirich1)\
**Post date:** [6 September 2005 03:57 UTC](https://rubytalk.org/t/rake-multiple-prerequisites-in-rule/20575/4 "2005-09-06T03:57:46Z")

</div>

Rake 0.6.0 (just released) now supports multiple prerequisites in a rule.

> **···**
>
> On Friday 02 September 2005 10:42 am, Martin Honermeyer wrote:
> 
> > Apparently, it's not possible to have multiple prerequisites for a rule.  
> > Does anyone have a hint on this?
> 
> --  
> -- Jim Weirich jim@weirichhouse.org [http://onestepback.org](http://onestepback.org)  
> -----------------------------------------------------------------  
> "Beware of bugs in the above code; I have only proved it correct,  
> not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)

---

<div class="post-metadata">

**Author:** ![Martin\_Honermeyer](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@Martin\_Honermeyer](https://rubytalk.org/u/Martin_Honermeyer)\
**Post date:** [5 September 2005 09:51 UTC](https://rubytalk.org/t/rake-multiple-prerequisites-in-rule/20575/5 "2005-09-05T09:51:08Z")

</div>

Stefan Lang wrote:

> 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|  
> &nbsp;&nbsp;&nbsp;&nbsp;[target.sub\_ext("html"), target.sub\_ext("plogic")]  
> }  
> gen Rule, '.rhtml' =\> rhtml\_sources do |t|  
> &nbsp;&nbsp;&nbsp;&nbsp;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, '

Thanks Stefan!

So there is no solution using Rake? Would have been nice since Rails comes  
preinstalled with Rake. That means all devs will have to install Rant, too.  
Okay, if there is no other way..

Greetings,  
Martin

---

<div class="post-metadata">

**Author:** ![Martin\_Honermeyer](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@Martin\_Honermeyer](https://rubytalk.org/u/Martin_Honermeyer)\
**Post date:** [5 September 2005 13:02 UTC](https://rubytalk.org/t/rake-multiple-prerequisites-in-rule/20575/6 "2005-09-05T13:02:29Z")

</div>

Niklas Frykholm wrote:

> > Apparently, it's not possible to have multiple prerequisites for a rule.  
> > Does anyone have a hint on this?
> 
> Not as elegant as using a rule perhaps, but you could write
> 
> &nbsp;&nbsp;&nbsp;&nbsp;SRC.each {|src|  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rhtml = src.ext('rhtml')  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;plogic = src.ext('plogic')  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file src =\> [rhtml, plogic] do |t|

Thanks, that does it! So that means there will be one definition (in memory)  
for every file. Have to see whether this scales for many templates.

Greetz,  
Martin

---

<div class="post-metadata">

**Author:** ![Martin\_Honermeyer](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@Martin\_Honermeyer](https://rubytalk.org/u/Martin_Honermeyer)\
**Post date:** [6 September 2005 10:23 UTC](https://rubytalk.org/t/rake-multiple-prerequisites-in-rule/20575/7 "2005-09-06T10:23:26Z")

</div>

Jim Weirich wrote:

> > Apparently, it's not possible to have multiple prerequisites for a rule.  
> > Does anyone have a hint on this?
> 
> Rake 0.6.0 (just released) now supports multiple prerequisites in a rule.

Great! Now this works as it should:

rule '.rhtml' =\> ['.html', '.plogic'] do |t|  
&nbsp;&nbsp;sh "kwartz -Rails -e -p #{t.source.ext('plogic')} --extract=content  
#{t.source} \> #{t.name}"  
end

Greetz,  
Martin

> **···**
>
> > On Friday 02 September 2005 10:42 am, Martin Honermeyer wrote:
