Class: Kramdown::PlantUml::PlantUmlDiagram

Inherits:
Object
  • Object
show all
Defined in:
lib/kramdown-plantuml/plantuml_diagram.rb

Overview

Represents a PlantUML diagram that can be converted to SVG.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plantuml, options) ⇒ PlantUmlDiagram

Returns a new instance of PlantUmlDiagram.

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kramdown-plantuml/plantuml_diagram.rb', line 17

def initialize(plantuml, options)
  raise ArgumentError, 'options cannot be nil' if options.nil?
  raise ArgumentError, "options must be a '#{Options}'." unless options.is_a?(Options)

  @plantuml = plantuml.strip unless plantuml.nil?
  @options = options
  @theme = Theme.new(options)
  @logger = LogWrapper.init
  @executor = Executor.new
  @logger.warn 'PlantUML diagram is empty' if @plantuml.nil? || @plantuml.empty?
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/kramdown-plantuml/plantuml_diagram.rb', line 15

def options
  @options
end

#plantumlObject (readonly)

Returns the value of attribute plantuml.



15
16
17
# File 'lib/kramdown-plantuml/plantuml_diagram.rb', line 15

def plantuml
  @plantuml
end

#resultObject (readonly)

Returns the value of attribute result.



15
16
17
# File 'lib/kramdown-plantuml/plantuml_diagram.rb', line 15

def result
  @result
end

#themeObject (readonly)

Returns the value of attribute theme.



15
16
17
# File 'lib/kramdown-plantuml/plantuml_diagram.rb', line 15

def theme
  @theme
end

Instance Method Details

#svgObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/kramdown-plantuml/plantuml_diagram.rb', line 29

def svg
  return @svg_diagram unless @svg_diagram.nil?

  @plantuml = @theme.apply(@plantuml)
  log(@plantuml)
  @result = @executor.execute(self)
  @svg_diagram = SvgDiagram.new(@result)
rescue StandardError => e
  raise e if @options.raise_errors?

  @logger.error e.to_s
end