Class: Klenod::Build::Graphviz

Inherits:
Object
  • Object
show all
Defined in:
lib/klenod/build/graphviz.rb

Constant Summary collapse

MODULE_STYLES =
{
  ".rb" => {fillcolor: "#d7ecff", color: "#3a77b5"},
  ".haml" => {fillcolor: "#f4dcff", color: "#9b52b8"},
  ".css" => {fillcolor: "#dcfce7", color: "#31a46a"},
  ".json" => {fillcolor: "#fff3bf", color: "#c28f00"},
  ".toml" => {fillcolor: "#fff3bf", color: "#c28f00"},
  ".yaml" => {fillcolor: "#fff3bf", color: "#c28f00"},
  ".yml" => {fillcolor: "#fff3bf", color: "#c28f00"}
}.freeze
VIRTUAL_STYLE =
{fillcolor: "#eceff4", color: "#667085"}.freeze
ASSET_STYLE =
{fillcolor: "#ffe4d6", color: "#e26d39"}.freeze
DEFAULT_MODULE_STYLE =
{fillcolor: "#f7f7f7", color: "#8a8a8a"}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bundle, include_assets: true) ⇒ Graphviz

Returns a new instance of Graphviz.



26
27
28
29
# File 'lib/klenod/build/graphviz.rb', line 26

def initialize(bundle, include_assets: true)
  @bundle = bundle
  @include_assets = include_assets
end

Class Method Details

.call(bundle, include_assets: true) ⇒ Object



22
23
24
# File 'lib/klenod/build/graphviz.rb', line 22

def self.call(bundle, include_assets: true)
  new(bundle, include_assets: include_assets).to_dot
end

Instance Method Details

#to_dotObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/klenod/build/graphviz.rb', line 31

def to_dot
  lines = [
    "digraph klenod {",
    "  graph [rankdir=LR, bgcolor=\"transparent\", pad=\"0.4\", nodesep=\"0.45\", ranksep=\"0.8\"];",
    "  node [shape=box, style=\"rounded,filled\", fontname=\"Menlo\", fontsize=10, margin=\"0.08,0.05\"];",
    "  edge [fontname=\"Menlo\", fontsize=9, color=\"#667085\", arrowsize=0.7];"
  ]

  module_ids.each { |id| lines << module_node(id) }
  lines.concat(asset_nodes) if @include_assets
  lines.concat(import_edges)
  lines.concat(asset_edges) if @include_assets
  lines << "}"
  "#{lines.join("\n")}\n"
end