Class: HtmlGenerator

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

Direct Known Subclasses

HtmlReportConfig, Stitcher

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#file_systemObject

Returns the value of attribute file_system.



4
5
6
# File 'lib/jirametrics/html_generator.rb', line 4

def file_system
  @file_system
end

#settingsObject

Returns the value of attribute settings.



4
5
6
# File 'lib/jirametrics/html_generator.rb', line 4

def settings
  @settings
end

Instance Method Details

#color_paletteObject

Charts allocate colours while they run, which happens before create_html is reached, so the palette cannot wait for the CSS that create_html loads. It reads the files directly instead. Deliberately not going through file_system: the shipped stylesheet is part of the gem rather than user data, and the palette only needs to count slots in it.



19
20
21
# File 'lib/jirametrics/html_generator.rb', line 19

def color_palette
  @color_palette ||= ColorPalette.new css: palette_css
end

#create_html(output_filename:, settings:, project_name: '') ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/jirametrics/html_generator.rb', line 6

def create_html output_filename:, settings:, project_name: ''
  @settings = settings
  project_name = project_name.to_s
  css = load_css html_directory: html_directory
  javascript = file_system.load(File.join(html_directory, 'index.js'))
  erb = ERB.new file_system.load(File.join(html_directory, 'index.erb'))
  file_system.save_file content: erb.result(binding), filename: output_filename
end

#html_directoryObject



31
32
33
# File 'lib/jirametrics/html_generator.rb', line 31

def html_directory
  "#{Pathname.new(File.realpath(__FILE__)).dirname}/html"
end

#load_css(html_directory:) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/jirametrics/html_generator.rb', line 35

def load_css html_directory:
  base_css_filename = File.join(html_directory, 'index.css')
  base_css = file_system.load(base_css_filename)

  extra_css_filename = settings['include_css']
  if extra_css_filename
    if File.exist?(extra_css_filename)
      base_css << "\n\n" << file_system.load(extra_css_filename)
      log("Loaded CSS:  #{extra_css_filename}")
    else
      log("Unable to find specified CSS file: #{extra_css_filename}")
    end
  end

  base_css
end

#palette_cssObject



23
24
25
26
27
28
29
# File 'lib/jirametrics/html_generator.rb', line 23

def palette_css
  base = File.read File.join(html_directory, 'index.css')
  extra = settings && settings['include_css']
  return base unless extra && File.exist?(extra)

  "#{base}\n\n#{File.read extra}"
end