Class: Attractor::HtmlReporter

Inherits:
BaseReporter show all
Defined in:
lib/attractor/reporters/html_reporter.rb

Overview

HTML reporter

Instance Attribute Summary

Attributes inherited from BaseReporter

#file_prefix, #types, #values

Instance Method Summary collapse

Methods inherited from BaseReporter

#initialize, #suggestions

Constructor Details

This class inherits a constructor from Attractor::BaseReporter

Instance Method Details

#cssObject



57
58
59
# File 'lib/attractor/reporters/html_reporter.rb', line 57

def css
  File.read(File.expand_path("../../../app/assets/stylesheets/main.css", __dir__))
end

#faviconObject



53
54
55
# File 'lib/attractor/reporters/html_reporter.rb', line 53

def favicon
  File.read(File.expand_path("../../../app/assets/images/attractor_favicon.png", __dir__))
end

#javascriptObject



65
66
67
68
# File 'lib/attractor/reporters/html_reporter.rb', line 65

def javascript
  template = Tilt.new(File.expand_path("../../../app/assets/javascripts/index.js.erb", __dir__))
  template.render self
end

#javascript_packObject



61
62
63
# File 'lib/attractor/reporters/html_reporter.rb', line 61

def javascript_pack
  File.read(File.expand_path("../../../app/assets/javascripts/index.pack.js", __dir__))
end

#logoObject



49
50
51
# File 'lib/attractor/reporters/html_reporter.rb', line 49

def 
  File.read(File.expand_path("../../../app/assets/images/attractor_logo.svg", __dir__))
end

#renderObject



70
71
72
73
# File 'lib/attractor/reporters/html_reporter.rb', line 70

def render
  template = Tilt.new(File.expand_path("../../../app/views/index.html.erb", __dir__))
  template.render self
end

#reportObject



6
7
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
# File 'lib/attractor/reporters/html_reporter.rb', line 6

def report
  super

  puts "Generating an HTML report"
  @serve_static = true

  FileUtils.mkdir_p "./attractor_output"
  FileUtils.mkdir_p "./attractor_output/stylesheets"
  FileUtils.mkdir_p "./attractor_output/images"
  FileUtils.mkdir_p "./attractor_output/javascripts"

  File.write("./attractor_output/images/attractor_logo.svg", )
  File.write("./attractor_output/images/attractor_favicon.png", favicon)
  File.write("./attractor_output/stylesheets/main.css", css)
  File.write("./attractor_output/javascripts/index.pack.js", javascript_pack)

  if @calculators.size > 1
    @calculators.each do |calc|
      @short_type = calc.first
      suggester = Suggester.new(values(type: @short_type))
      @suggestions = suggester.suggest

      File.write("./attractor_output/javascripts/index.#{@short_type}.js", javascript)
      File.write("./attractor_output/index.#{@short_type}.html", render)
      puts "Generated HTML report at #{File.expand_path "./attractor_output/"}/index.#{@short_type}.html"
    end

    if @open_browser
      Launchy.open(File.expand_path("./attractor_output/index.#{@calculators.first.first}.html"))
      puts "Opening browser window..."
    end
  else
    File.write("./attractor_output/javascripts/index.js", javascript)
    File.write("./attractor_output/index.html", render)
    puts "Generated HTML report at #{File.expand_path "./attractor_output/index.html"}"

    if @open_browser
      Launchy.open(File.expand_path("./attractor_output/index.html"))
      puts "Opening browser window..."
    end
  end
end