Permalink
Browse files

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
  • Loading branch information...
1 parent 27169c2 commit ae616a3fff5d5e40ad29a6ddf2cadb6990fbab29 Daniel Martin committed Jun 16, 2011
@@ -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
@@ -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
@@ -1,4 +0,0 @@
-# desc "Explaining what the task does"
-# task :html_export do
-# # Task goes here
-# end
@@ -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
+
+

0 comments on commit ae616a3

Please sign in to comment.