Sha256: f9c22bfb4f177f1ef0373483d33e8007e3645262e53f7d8fe9bb93cf33c814f1
Contents?: true
Size: 1.41 KB
Versions: 2
Compression:
Stored size: 1.41 KB
Contents
require 'erb' module Swoop class ChartRenderer < Renderer attr_reader :filename def initialize(reports, title, filename = "index.html") super(reports, title) @filename = filename end def class_count_data rows = [] rows << ['Date', 'Swift Class', 'Objective-C Class'] rows += reports.map { |r| [ "#{r.name}\n(#{r.date})", r.swift_classes_count, r.objc_classes_count] } rows.to_s end def class_percentage_data rows = [] rows << ['Date', 'Swift Class (%)', 'Objective-C Class (%)'] rows += reports.map { |r| [ "#{r.name}\n(#{r.date})", r.swift_classes_percentage, r.objc_classes_percentage] } rows.to_s end def render empty_target_dir html_path = render_html `open #{html_path}` end private def template_path @template_path ||= File.join(File.dirname(__dir__), "renderer/chart_renderer/chart.html.erb") end def target_dir @target_dir ||= File.expand_path("./html") end def empty_target_dir FileUtils.rm_rf(target_dir) if Dir.exist?(target_dir) FileUtils.mkdir_p(target_dir) end def render_html template = ERB.new(File.read(template_path)) html_content = template.result(binding) html_path = File.join(target_dir, filename) File.open(html_path, "w") do |file| file.puts html_content end html_path end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
swoop_report-0.3.1 | lib/swoop/renderer/chart_renderer.rb |
swoop_report-0.3 | lib/swoop/renderer/chart_renderer.rb |