class Htmler
Public Class Methods
new(summary, data, userChoice)
click to toggle source
# File lib/htmler.rb, line 2 def initialize summary, data, userChoice @data = JSON.parse(data) @summary = JSON.parse(summary) @userData = JSON.parse(userChoice) end
Public Instance Methods
inits()
click to toggle source
# File lib/htmler.rb, line 8 def inits # User Choice Data to be used. footer = @userData['footerMessage'] # Footer Message. outPath = @userData['outPath'] # Path where to keep the generated report. documentation = @userData['documentation'] # whether or not show the exceptions in console. # User Data Ends --------------------------------------------------------------------------- # Variables to be used in HTML page. currentTime = Time.now.strftime("%A, %b %d %Y %r %z") # Time when the report is generated. summary = @summary # Summary to be shown in header. suits = @data # All groups data. groupNames = @data.collect{|x| x['grpName']} # All unique group Names # Variables end ---------------------------------------------------------------------------- path = 'rsReports' # location where the report will be generated. if(outPath != '') path = outPath end #create folders where the report will be placed. Dir.mkdir(path) unless File.exists?(path) Dir.mkdir(path + '/refs') unless File.exists?(path + '/refs') # Read CSS + JS Files from source cssFile = File.expand_path(File.dirname(__FILE__)) + "/refs/main.min.css" jsFile = File.expand_path(File.dirname(__FILE__)) + "/refs/main.min.js" # Write CSS file to the destination folder. File.open path + "/refs/main.min.css", "w" do |c| c << IO.read(cssFile) end # Write JS file to the destination folder. File.open path + "/refs/main.min.js", "w" do |c| c << IO.read(jsFile) end # Write HTML file to the destination folder. templateFile = File.expand_path(File.dirname(__FILE__)) + "/index.erb" File.open path + "/index.html", "w" do |f| f << ERB.new(IO.read(templateFile), nil, '>', 'output').result(binding) end # Write summary to a file in the destination folder. File.open path + "/summary.json", "w" do |f| f.write summary.to_json end end