Class: Htmler

Inherits:
Object
  • Object
show all
Defined in:
lib/htmler.rb

Instance Method Summary collapse

Constructor Details

#initialize(summary, data, userChoice) ⇒ Htmler

Returns a new instance of Htmler.



2
3
4
5
6
# File 'lib/htmler.rb', line 2

def initialize summary, data, userChoice
  @data = JSON.parse(data)
  @summary = JSON.parse(summary)
  @userData = JSON.parse(userChoice)
end

Instance Method Details

#initsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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