class GraphToHtmlVisualiser

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

Public Instance Methods

generate(deps, file) click to toggle source
# 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

Private Instance Methods

resolve_file_path(path) click to toggle source
# File lib/cpp_dependency_graph/graph_to_html_visualiser.rb, line 22
def resolve_file_path(path)
  File.expand_path("../../../#{path}", __FILE__)
end