Skip to content

Commit

Permalink
Refactor the HTMLExport plugin
Browse files Browse the repository at this point in the history
* 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
Daniel Martin committed Jun 16, 2011
1 parent 27169c2 commit ae616a3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
13 changes: 2 additions & 11 deletions vendor/plugins/html_export/lib/html_export/actions.rb
Expand Up @@ -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
15 changes: 15 additions & 0 deletions 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
4 changes: 0 additions & 4 deletions vendor/plugins/html_export/lib/tasks/html_export_tasks.rake

This file was deleted.

27 changes: 27 additions & 0 deletions 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


0 comments on commit ae616a3

Please sign in to comment.