# = Developmer's Notes Rake Task # class DNoteTask < Rake::TaskLib require 'rake/clean' # Default note labels to looked for in source code. DEFAULT_LABELS = ['TODO', 'FIXME', 'OPTIMIZE', 'DEPRECATE'] # File paths to search. attr_accessor :files # Labels to document. Defaults are: TODO, FIXME, OPTIMIZE and DEPRECATE. attr_accessor :labels # Formats (xml, html, rdoc, rdoc/list and so on). attr_accessor :formats # Exclude paths. attr_accessor :exclude # Ignore paths based on any part of pathname. attr_accessor :ignore # Output directory to save notes file. Defaults to dnote/ under # the project log directory (eg. log/dnote/). attr_accessor :output # Title to use if temaplte can use it. attr_accessor :title # def output=(path) @output = Pathname.new(path) end # def init require 'dnote' require 'dnote/format' @files = "**/*.rb" @output = 'log/dnote' @formats = ['index'] @labels = nil #DEFAULT_LABELS end # def define desc "Collect Developer's Notes" task 'dnote' do document end task 'dnote:clobber' do clean end task :clobber => ['dnote:clobber'] end # Generate notes document(s). def document abort "dnote: #{output} is not a directory" unless output.directory? session = ::DNote::Session.new do |s| s.paths = files s.exclude = exclude s.ignore = ignore s.labels = labels #|| DEFAULT_LABELS s.title = title s.output = output s.dryrun = application.options.dryrun #trial? end formats.each do |format| if format == 'index' session.format = 'html' session.output = File.join(self.output, 'index.html') else session.format = format end session.run report "Updated #{output.to_s.sub(Dir.pwd+'/','')}" unless trial? end end # Reset output directory, marking it as out-of-date. def reset #if File.directory?(output) File.utime(0,0,output) unless $NOOP puts "Marked #{output} as out-of-date" #end end # Remove output files. def clean #if File.directory?(output) formats.each do |format| if format == 'index' file = (output + "index.html").to_s else ext = ::DNote::Format::EXTENSIONS[format] || format file = (output + "notes.#{ext}").to_s end rm(file) report "Removed #{output}" end #else # rm(output) # report "Removed #{output}" #end end end