Book Image

Rake Task Management Essentials

By : Andrey Koleshko
Book Image

Rake Task Management Essentials

By: Andrey Koleshko

Overview of this book

Table of Contents (18 chapters)
Rake Task Management Essentials
Credits
About the Author
Acknowledgements
About the Reviewers
www.PacktPub.com
Preface
Index

Using a rule to get rid of the duplicated file tasks


To get rid of duplicated file tasks, there is a special rake task called rule. This is a general rake task, but it has one peculiarity. It allows us to define a mask for a task rather than the exact name. We will postpone the whole explanation of this, and for now, we will only see how to do this with the rule method. The following is our fixed Rakefile with a rule method:

require_relative 'blog_generator'

articles = Rake::FileList.new('**/*.md',
                 '**/*.markdown') do |files|
             files.exclude('~*')
             files.exclude(/^temp.+\//)
             files.exclude do |file|
               File.zero?(file)
             end
           end
task :default => 'blog.html'

rule '.html' => '.md' do |t|
  sh "pandoc -s #{t.source} -o #{t.name}"
end

rule '.html' => '.markdown' do |t|
  sh "pandoc -s #{t.source} -o #{t.name}"
end

FileUtils.rm('blog.html', force: true)

file 'blog.html' => articles.ext('.html...