Class: BlobViewer::Graph

Inherits:
Base
  • Object
show all
Includes:
Rich, ServerSide
Defined in:
app/models/blob_viewer/graph.rb

Constant Summary collapse

INTERNAL_EXTENSIONS =
%w[mermaid].freeze
PLANTUML_EXTENSIONS =
%w[plantuml pu puml iuml].freeze
KROKI_EXTENSIONS =
%w[d2 dot gv noml plantuml pu puml iuml vg vl].freeze

Constants inherited from Base

Base::PARTIAL_PATH_PREFIX

Instance Attribute Summary

Attributes inherited from Base

#blob

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ServerSide

#prepare!, #render_error

Methods inherited from Base

auxiliary?, binary?, #binary_detected_after_load?, #collapsed?, #initialize, load_async?, loading_partial_path, partial_path, #prepare!, #render_error, rich?, simple?, text?, #too_large?

Constructor Details

This class inherits a constructor from BlobViewer::Base

Class Method Details

.can_render?(blob, verify_binary: true) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/blob_viewer/graph.rb', line 20

def self.can_render?(blob, verify_binary: true)
  # most blob views will not be graph files and the local can_render checks are a bit expensive
  return false unless super

  settings = Gitlab::CurrentSettings.current_application_settings
  return true if INTERNAL_EXTENSIONS&.include?(blob.extension)
  return true if settings.plantuml_enabled? && PLANTUML_EXTENSIONS&.include?(blob.extension)
  return true if settings.kroki_enabled? && ::Gitlab::Kroki.formats(settings).include?(graph_format(blob))

  false
end

.graph_format(blob) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/models/blob_viewer/graph.rb', line 32

def self.graph_format(blob)
  case blob.extension
  # included formats
  when *%w[mermaid]
    'mermaid'
  # kroki formats
  when *%w[d2]
    'd2'
  when *%w[dot gv]
    'graphviz'
  when *%w[noml]
    'nomnoml'
  when *%w[vg]
    'vega'
  when *%w[vl]
    'vegalite'
  # kroki/plantuml formats
  when *%w[plantuml pu puml iuml]
    'plantuml'
  end
end

Instance Method Details

#banzai_render_contextObject



54
55
56
57
58
# File 'app/models/blob_viewer/graph.rb', line 54

def banzai_render_context
  {}.tap do |h|
    h[:cache_key] = ['blob', blob.id, 'commit', blob.commit_id]
  end
end