Class: GraphToHtmlVisualiser

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

Overview

Outputs a ‘d3 force graph layout` equipped HTML representation of a dependency graph

Instance Method Summary collapse

Instance Method Details

#generate(deps, file) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/cpp_dependency_graph/graph_to_html_visualiser.rb', line 7

def generate(deps, file)
  connections = deps.flat_map do |_, links|
    links.map do |link|
      { source: link.source, dest: link.target }
    end
  end
  json_connections = JSON.pretty_generate(connections)
  template_file = resolve_file_path('views/index.html.template')
  template = File.read(template_file)
  contents = format(template, dependency_links: json_connections)
  File.write(file, contents)
end