Class: Ea::Svg::EaEmitter::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/ea/svg/ea_emitter/document.rb

Overview

Top-level orchestrator: emits a complete standalone SVG document matching EA's structure. Calls the layer emitters in EA's canonical order.

Constant Summary collapse

BUILD_ID =
"1628"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(diagram, model_index:, **_options) ⇒ Document

Returns a new instance of Document.



14
15
16
17
# File 'lib/ea/svg/ea_emitter/document.rb', line 14

def initialize(diagram, model_index:, **_options)
  @diagram = diagram
  @model_index = model_index
end

Instance Attribute Details

#diagramObject (readonly)

Returns the value of attribute diagram.



12
13
14
# File 'lib/ea/svg/ea_emitter/document.rb', line 12

def diagram
  @diagram
end

#model_indexObject (readonly)

Returns the value of attribute model_index.



12
13
14
# File 'lib/ea/svg/ea_emitter/document.rb', line 12

def model_index
  @model_index
end

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/ea/svg/ea_emitter/document.rb', line 12

def options
  @options
end

Instance Method Details

#renderObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ea/svg/ea_emitter/document.rb', line 19

def render
  canvas = Canvas.from(diagram)
  layers = [
    Background.render(canvas),
    Elements.new(diagram, model_index: model_index).render,
    Connectors.new(diagram).render,
    Markers.new(diagram, model_index: model_index).render,
    Labels.new(diagram).render
  ].reject { |s| s.nil? || s.empty? }

  <<~SVG
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">

    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="#{canvas.width_cm}" height="#{canvas.height_cm}" viewBox="#{canvas.view_box}">
    <title></title>
    <desc>Created with Enterprise Architect (Build: #{BUILD_ID}) 2</desc>

    #{layers.join("\n\n")}
    </svg>
  SVG
end