class Society::Formatter::Report::HTML
Attributes
json_data[R]
output_path[R]
Public Class Methods
new(json_data:, output_path: default_output_path)
click to toggle source
# File lib/society/formatter/report/html.rb, line 8 def initialize(json_data:, output_path: default_output_path) @json_data = json_data @output_path = output_path end
Public Instance Methods
write()
click to toggle source
# File lib/society/formatter/report/html.rb, line 13 def write prepare_output_directory write_html write_csv copy_assets write_json_data puts "Results written to #{self.output_path}." unless self.output_path.nil? end
Private Instance Methods
copy_assets()
click to toggle source
# File lib/society/formatter/report/html.rb, line 36 def copy_assets bower_dir = File.join(File.dirname(__FILE__), 'templates', 'components') FileUtils.cp( File.join(bower_dir, 'society-assets', 'society.css'), File.join(output_path, 'stylesheets', 'society.css') ) FileUtils.cp( File.join(bower_dir, 'society-assets', 'society.js'), File.join(output_path, 'javascripts', 'society.js') ) FileUtils.cp( File.join(bower_dir, 'd3', 'd3.min.js'), File.join(output_path, 'javascripts', 'd3.min.js') ) end
csv()
click to toggle source
# File lib/society/formatter/report/html.rb, line 58 def csv Haml::Engine.new(csv_template).render( Object.new, json_data: json_data ) end
csv_template()
click to toggle source
# File lib/society/formatter/report/html.rb, line 64 def csv_template path = File.join(File.dirname(__FILE__), 'templates', 'society.csv.haml') File.read(path) end
default_output_path()
click to toggle source
# File lib/society/formatter/report/html.rb, line 24 def default_output_path File.join(%w[doc society]) end
index()
click to toggle source
# File lib/society/formatter/report/html.rb, line 52 def index Haml::Engine.new(template).render( Object.new, json_data: json_data ) end
prepare_output_directory()
click to toggle source
# File lib/society/formatter/report/html.rb, line 78 def prepare_output_directory FileUtils.mkpath(File.join(output_path, 'stylesheets')) FileUtils.mkpath(File.join(output_path, 'javascripts')) end
template()
click to toggle source
# File lib/society/formatter/report/html.rb, line 69 def template path = File.join(File.dirname(__FILE__), 'templates', 'index.htm.haml') File.read(path) end
timestamp()
click to toggle source
# File lib/society/formatter/report/html.rb, line 74 def timestamp @timestamp ||= Time.now.strftime("%Y_%m_%d_%H_%M_%S") end
write_csv()
click to toggle source
# File lib/society/formatter/report/html.rb, line 32 def write_csv File.open(File.join(output_path, 'society.csv'), 'w') {|outfile| outfile.write(csv)} end
write_html()
click to toggle source
# File lib/society/formatter/report/html.rb, line 28 def write_html File.open(File.join(output_path, 'index.htm'), 'w') {|outfile| outfile.write(index)} end
write_json_data()
click to toggle source
# File lib/society/formatter/report/html.rb, line 83 def write_json_data json_path = File.join(output_path, 'data', timestamp, 'society_graph.json') Formatter::Report::Json.new(json_data: json_data, output_path: json_path).write end