Class: Giblish::GraphBuilderGraphviz

Inherits:
Object
  • Object
show all
Defined in:
lib/giblish/buildgraph.rb

Overview

Builds an asciidoc page with an svg image with a digraph showing how documents reference each other.

Graphviz is used as the graph generator and must be available as a valid engine via asciidoctor-diagram for this class to work.

Direct Known Subclasses

GitGraphBuilderGraphviz

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(processed_docs, paths, deployment_info, options = {}) ⇒ GraphBuilderGraphviz

Supported options: :extension - file extension for URL links (default is .html)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/giblish/buildgraph.rb', line 15

def initialize(processed_docs, paths, deployment_info, options = {})
  # this class relies on graphwiz (dot), make sure we can access that
  raise "Could not find the 'dot' tool needed to generate a dependency graph!" unless GraphBuilderGraphviz.supported

  # require asciidoctor module needed for generating diagrams
  require "asciidoctor-diagram/graphviz"

  @noid_docs = {}
  @next_id = 0
  @processed_docs = processed_docs
  @paths = paths
  @deployment_info = deployment_info
  @converter_options = options.dup
  @extension = @converter_options.key?(:extension) ? options[:extension] : "html"
  @docid_cache = DocidCollector.docid_cache
  @docid_deps =  DocidCollector.docid_deps
  @dep_graph = build_dep_graph
  @search_opts = {
    web_assets_top: @deployment_info.web_path,
    search_assets_top: @deployment_info.search_assets_path
  }
end

Class Method Details

.supportedObject

the dependency graph relies on graphwiz (dot), check if we can access that


9
10
11
# File 'lib/giblish/buildgraph.rb', line 9

def self.supported
  !Giblish.which("dot").nil?
end

Instance Method Details

#cleanupObject


51
52
53
54
55
56
57
58
# File 'lib/giblish/buildgraph.rb', line 51

def cleanup
  # remove cache dir and svg image created by asciidoctor-diagram
  # when creating the document dependency graph
  adoc_diag_cache = @paths.dst_root_abs.join(".asciidoctor")
  FileUtils.remove_dir(adoc_diag_cache) if adoc_diag_cache.directory?
  Giblog.logger.info { "Removing cached files at: #{@paths.dst_root_abs.join('docdeps.svg')}" }
  @paths.dst_root_abs.join("docdeps.svg").delete
end

#source(make_searchable: false) ⇒ Object

get the asciidoc source for the document.


39
40
41
42
43
44
45
46
47
48
49
# File 'lib/giblish/buildgraph.rb', line 39

def source(make_searchable: false)
  s = <<~DOC_STR
    #{generate_header}
    #{add_search_box if make_searchable}
    #{generate_graph_header}
    #{generate_labels}
    #{generate_deps}
    #{generate_footer}
  DOC_STR
  s
end