Class: Lutaml::Xsd::Spa::Svg::DocumentBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/xsd/spa/svg/document_builder.rb

Overview

Assembles final SVG document from components

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ DocumentBuilder

Returns a new instance of DocumentBuilder.



13
14
15
16
# File 'lib/lutaml/xsd/spa/svg/document_builder.rb', line 13

def initialize(config)
  @config = config
  @defs_builder = DefsBuilder.new(config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/lutaml/xsd/spa/svg/document_builder.rb', line 11

def config
  @config
end

Instance Method Details

#build(components, dimensions) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/lutaml/xsd/spa/svg/document_builder.rb', line 18

def build(components, dimensions)
  width = dimensions&.width || 800
  height = dimensions&.height || 600
  <<~SVG
    <svg xmlns="http://www.w3.org/2000/svg"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         width="#{width}" height="#{height}"
         viewBox="0 0 #{width} #{height}">
      #{@defs_builder.build}
      #{build_styles}
      <g id="diagram-content">
        #{components.join("\n")}
      </g>
    </svg>
  SVG
end