# # File 'clean.rb' created on 14 apr 2008 at 16:04:19. # # See 'dokkit.rb' or +LICENSE+ for licence information. # # (C) 2008 Andrea Fazzi (and contributors). # module Dokkit module TaskLib # The Clean task library is a collection of rake tasks devoted to # the cleaning of the documentation environment. The library # defines a clean:output that remove the generated output folder # (if exists). It defines also a clean:cache task that remove the # cache folder (if exists). class Clean attr_reader :output_dir, :cache_dir # Initialize the library with the logger instance, an optional # namespace and configuration hash. def initialize(logger, configuration, namespace = 'clean') @namespace = namespace @logger = logger @configuration = configuration @output_dir = configuration[:output_dir] @cache_dir = configuration[:cache_dir] define_tasks end private # Define library tasks under the given namespace. def define_tasks namespace @namespace do define_output_task define_cache_task define_clean_all_task end end # Define a task to remove output directory. def define_output_task desc "Remove the generated output." task :output do remove_dir(output_dir) end end # Define a task to remove cache directory. def define_cache_task desc "Remove cache directory." task :cache do remove_dir(cache_dir) end end def remove_dir(dir) if File.exists?(dir) @logger.info("Removing directory '#{dir}'.") rm_rf dir unless dir == '.' end end # Define a task that clean the documentation environment # removing both output and cache directory. def define_clean_all_task desc "Clean the documentation environment." task :all => ["#{@namespace}:output", "#{@namespace}:cache"] end end end end