From ae616a3fff5d5e40ad29a6ddf2cadb6990fbab29 Mon Sep 17 00:00:00 2001 From: Daniel Martin Date: Thu, 16 Jun 2011 17:16:57 +0100 Subject: [PATCH] Refactor the HTMLExport plugin * Move the code that generates the report into a separate HTMLExport::Processor class * Replace the (empty) Rake tasks file with a new thorfile.rb * Implement the dradis:export:html Thor task to generate HTML reports from the command line This commit referencess #15 --- .../html_export/lib/html_export/actions.rb | 13 ++------- .../html_export/lib/html_export/processor.rb | 15 +++++++++++ .../lib/tasks/html_export_tasks.rake | 4 --- .../plugins/html_export/lib/tasks/thorfile.rb | 27 +++++++++++++++++++ 4 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 vendor/plugins/html_export/lib/html_export/processor.rb delete mode 100644 vendor/plugins/html_export/lib/tasks/html_export_tasks.rake create mode 100644 vendor/plugins/html_export/lib/tasks/thorfile.rb diff --git a/vendor/plugins/html_export/lib/html_export/actions.rb b/vendor/plugins/html_export/lib/html_export/actions.rb index d3608103..9b5acfeb 100644 --- a/vendor/plugins/html_export/lib/html_export/actions.rb +++ b/vendor/plugins/html_export/lib/html_export/actions.rb @@ -6,17 +6,8 @@ module Actions # # It uses the template at: ./vendor/plugins/html_export/template.html.erb def to_html(params={}) - category_name = params.fetch(:category_name, Configuration.category) - reporting_cat = Category.find_by_name(category_name) - reporting_notes_num = Note.count(:all, :conditions => {:category_id => reporting_cat}) - - title = "Dradis Framework - v#{Core::VERSION::STRING}" - notes = Note.find( :all, :conditions => {:category_id => reporting_cat} ) - erb = ERB.new( File.read(Configuration.template) ) - #send( erb.result(), :filename => 'report.html', :type => 'text/html') - render :type => 'text/html', - :text => erb.result( binding ) - + doc = Processor.generate(params) + render :type => 'text/html', :text => doc end end end diff --git a/vendor/plugins/html_export/lib/html_export/processor.rb b/vendor/plugins/html_export/lib/html_export/processor.rb new file mode 100644 index 00000000..6ad3d241 --- /dev/null +++ b/vendor/plugins/html_export/lib/html_export/processor.rb @@ -0,0 +1,15 @@ +module HTMLExport + class Processor + def self.generate(params={}) + category_name = params.fetch(:category_name, Configuration.category) + reporting_cat = Category.find_by_name(category_name) + reporting_notes_num = Note.count(:all, :conditions => {:category_id => reporting_cat}) + title = "Dradis Framework - v#{Core::VERSION::STRING}" + notes = Note.find( :all, :conditions => {:category_id => reporting_cat} ) + + erb = ERB.new( File.read(Configuration.template) ) + + erb.result( binding ) + end + end +end diff --git a/vendor/plugins/html_export/lib/tasks/html_export_tasks.rake b/vendor/plugins/html_export/lib/tasks/html_export_tasks.rake deleted file mode 100644 index 8a094ada..00000000 --- a/vendor/plugins/html_export/lib/tasks/html_export_tasks.rake +++ /dev/null @@ -1,4 +0,0 @@ -# desc "Explaining what the task does" -# task :html_export do -# # Task goes here -# end diff --git a/vendor/plugins/html_export/lib/tasks/thorfile.rb b/vendor/plugins/html_export/lib/tasks/thorfile.rb new file mode 100644 index 00000000..68ba50e0 --- /dev/null +++ b/vendor/plugins/html_export/lib/tasks/thorfile.rb @@ -0,0 +1,27 @@ +class DradisTasks < Thor + class Export < Thor + namespace "dradis:export" + + desc 'html', 'export the current repository structure as an HTML document' + method_option :file, :type => :string, :desc => 'the report file to create' + def html + require 'config/environment' + + output_file = options.file || Rails.root.join('report.html') + + STDOUT.sync = true + logger = Logger.new(STDOUT) + logger.level = Logger::DEBUG + + doc = HTMLExport::Processor.generate(:logger => logger) + File.open(output_file, 'w') do |f| + f << doc + end + + logger.info{ "Report file created at:\n\t#{output_file}" } + logger.close + end + end +end + +