Class: Emfsvg::SvgBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/emfsvg/svg_builder.rb

Overview

Lightweight XML builder matching libemf2svg's exact byte output:

- no indentation
- self-closing elements use `/>` (no leading space)
- callers control newlines explicitly via `rawln` / `newline`

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSvgBuilder

Returns a new instance of SvgBuilder.



9
10
11
# File 'lib/emfsvg/svg_builder.rb', line 9

def initialize
  @out = (+"").force_encoding("ASCII-8BIT")
end

Instance Attribute Details

#outObject (readonly)

Returns the value of attribute out.



13
14
15
# File 'lib/emfsvg/svg_builder.rb', line 13

def out
  @out
end

Instance Method Details

#newlineObject



41
42
43
44
# File 'lib/emfsvg/svg_builder.rb', line 41

def newline
  @out << "\n"
  self
end

#raw(string) ⇒ Object

Raw append, no newline.



30
31
32
33
# File 'lib/emfsvg/svg_builder.rb', line 30

def raw(string)
  @out << string
  self
end

#rawln(string) ⇒ Object

Raw append with trailing newline.



36
37
38
39
# File 'lib/emfsvg/svg_builder.rb', line 36

def rawln(string)
  @out << string << "\n"
  self
end

#tag(name, attrs = {}, single: false) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/emfsvg/svg_builder.rb', line 15

def tag(name, attrs = {}, single: false)
  open_tag(name, attrs, single: single)
  if block_given?
    yield
    close_tag(name)
  end
  self
end

#text(content) ⇒ Object



24
25
26
27
# File 'lib/emfsvg/svg_builder.rb', line 24

def text(content)
  @out << escape_text(content)
  self
end

#to_sObject



46
47
48
# File 'lib/emfsvg/svg_builder.rb', line 46

def to_s
  @out
end