Class: Kramdown::PlantUml::SvgDiagram

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

Overview

A diagram in SVG format.

Instance Method Summary collapse

Constructor Details

#initialize(plantuml_result) ⇒ SvgDiagram

Returns a new instance of SvgDiagram.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
22
# File 'lib/kramdown-plantuml/svg_diagram.rb', line 12

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

  plantuml_result.validate!
  svg = plantuml_result.stdout
  @doc = REXML::Document.new svg
  @source = plantuml_result.plantuml_diagram
  @style_builder = StyleBuilder.new
  transfer_options(plantuml_result)
end

Instance Method Details

#heightObject



42
43
44
# File 'lib/kramdown-plantuml/svg_diagram.rb', line 42

def height
  get_xml_attribute_value(:height)
end

#styleObject



46
47
48
# File 'lib/kramdown-plantuml/svg_diagram.rb', line 46

def style
  get_xml_attribute_value(:style)
end

#to_sObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kramdown-plantuml/svg_diagram.rb', line 24

def to_s
  return '' if @doc.root.nil?

  wrapper_doc = REXML::Document.new
  wrapper_doc.context[:attribute_quote] = :quote
  wrapper_element = REXML::Element.new('div').tap do |div|
    div.add_attribute 'class', wrapper_class_name
    div.add_element @doc.root
  end

  wrapper_doc.add_element wrapper_element
  wrapper_doc.to_s
end

#widthObject



38
39
40
# File 'lib/kramdown-plantuml/svg_diagram.rb', line 38

def width
  get_xml_attribute_value(:width)
end