lib/dnote/rake/dnotetask.rb in mvz-dnote-1.8.0 vs lib/dnote/rake/dnotetask.rb in mvz-dnote-1.9.0

- old
+ new

@@ -1,14 +1,14 @@ # frozen_string_literal: true -require 'rspec/core/rake_task' +require "rspec/core/rake_task" module DNote # = Developmer's Notes Rake Task # class RakeTask < Rake::TaskLib - require 'rake/clean' + require "rake/clean" # Default note labels to looked for in source code. DEFAULT_LABELS = %w(TODO FIXME OPTIMIZE DEPRECATE).freeze # File paths to search. @@ -36,65 +36,79 @@ def output=(path) @output = Pathname.new(path) end def init - require 'dnote' - require 'dnote/format' - @files = '**/*.rb' - @output = 'log/dnote' - @formats = ['index'] + require "dnote" + require "dnote/format" + @files = "**/*.rb" + @output = "log/dnote" + @formats = ["index"] @labels = nil end def define desc "Collect Developer's Notes" - task 'dnote' do + task "dnote" do document end - task 'dnote:clobber' do + task "dnote:clobber" do clean end - task clobber: ['dnote:clobber'] + 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| + session = new_session + + formats.each do |format| + generate_document_for_format(session, format) + end + end + + # Remove output files. + def clean + formats.each do |format| + clean_format format + end + end + + private + + def new_session + ::DNote::Session.new do |s| s.paths = files s.exclude = exclude s.ignore = ignore s.labels = labels s.title = title s.output = output s.dryrun = application.options.dryrun # trial? end + end - formats.each do |format| - if format == 'index' - session.format = 'html' - session.output = File.join(output, 'index.html') - else - session.format = format - end - session.run - report "Updated #{output.to_s.sub(Dir.pwd + '/', '')}" unless trial? + def generate_document_for_format(session, format) + if format == "index" + session.format = "html" + session.output = File.join(output, "index.html") + else + session.format = format end + session.run + report "Updated #{output.to_s.sub("#{Dir.pwd}/", '')}" unless trial? end - # Remove output files. - def clean - 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}" + def clean_format(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 end end