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|
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?
Cheers,
Martin
[...]
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
···
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,
Stefan
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
SRC.each {|src|
rhtml = src.ext('rhtml')
plogic = src.ext('plogic')
file src => [rhtml, plogic] do |t|
// Niklas
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
-----------------------------------------------------------------
"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)
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|
[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, '
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
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
SRC.each {|src|
rhtml = src.ext('rhtml')
plogic = src.ext('plogic')
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
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|
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: