Docunext


Rake Quietly Supports Modification Time Checks

December 21st, 2009

I was hesitant to try Rake because it moved away from the XML style of modern make systems like and and phing.

I tried it anyway, and I really like it. I can still see XML being useful for specifying some tasks, but I appreciate how quickly I can write simple tasks for rake to process.

Here's a portion of the Rakefile I'm using for Regdel:

task :default do
    puts "hi"
end
task :publish_account_form => 'public/s/xhtml/account_form.html'
file 'public/s/xhtml/account_form.html' => ['data/accounting_data_model.xml', 'views/xsl/account_model_to_xhtml_form.xsl'] do
    xslt = ::XML::XSLT.new()
    xslt.xml = 'data/accounting_data_model.xml'
    xslt.xsl = 'views/xsl/account_model_to_xhtml_form.xsl'
    xslt.parameters = { 'account_submit' => '/account/submit' }
    html = xslt.serve
    File.open('public/s/xhtml/account_form.html', 'w') {|f| f.write(html) }
end

The first part is about as simple as a task can get, it just puts "hi".

The second and third tasks start to get more complicated and they introduce dependencies, though not obviously. The "file" keyword has build-in modification time checking (I love it!).

The publish_account_form task only depends on the account_form.html file, but doesn't do anything by itself. The account_form.html file task depends on two other files. If called upon as a dependency, the account_form.html task will check its dependencies and republish if either have changed since its own last modification time. If its dependencies have not changed since it has, the task will quickly complete without actually doing anything, simply because its work has already been done.

That, my friend, is awesome!

Yearly Indexes: 2003 2004 2006 2007 2008 2009 2010 2011 2012 2013 2015 2019 2020 2022