Class: DrawioDsl::Formatters::BaseFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/drawio_dsl/formatters/base_formatter.rb

Overview

Base for any HTML formatter

Direct Known Subclasses

InterfaceFormatter, KlassFormatter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element_style_defaults = {}) ⇒ BaseFormatter

Returns a new instance of BaseFormatter.



14
15
16
17
# File 'lib/drawio_dsl/formatters/base_formatter.rb', line 14

def initialize(element_style_defaults = {})
  @html = DrawioDsl::Formatters::HtmlBuilder.new(element_style_defaults)
  @items = []
end

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



9
10
11
# File 'lib/drawio_dsl/formatters/base_formatter.rb', line 9

def html
  @html
end

#itemsObject (readonly)

items are separate to html and are used for building a hash for export



12
13
14
# File 'lib/drawio_dsl/formatters/base_formatter.rb', line 12

def items
  @items
end

Instance Method Details

#as_html(new_line: false) ⇒ Object



104
105
106
# File 'lib/drawio_dsl/formatters/base_formatter.rb', line 104

def as_html(new_line: false)
  html.as_html(new_line: new_line)
end

#b(content, **opts) ⇒ Object



26
27
28
29
30
31
# File 'lib/drawio_dsl/formatters/base_formatter.rb', line 26

def b(content, **opts)
  html.b(content, **opts)
  items << { type: :b, content: content }

  self
end

#empty?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/drawio_dsl/formatters/base_formatter.rb', line 100

def empty?
  html.empty?
end

#h1(content, **opts) ⇒ Object



40
41
42
43
44
45
# File 'lib/drawio_dsl/formatters/base_formatter.rb', line 40

def h1(content, **opts)
  html.h1(content, **opts)
  items << { type: :h1, content: content }

  self
end

#h2(content, **opts) ⇒ Object



47
48
49
50
51
52
# File 'lib/drawio_dsl/formatters/base_formatter.rb', line 47

def h2(content, **opts)
  html.h2(content, **opts)
  items << { type: :h2, content: content }

  self
end

#h3(content, **opts) ⇒ Object



54
55
56
57
58
59
# File 'lib/drawio_dsl/formatters/base_formatter.rb', line 54

def h3(content, **opts)
  html.h3(content, **opts)
  items << { type: :h3, content: content }

  self
end

#h4(content, **opts) ⇒ Object



61
62
63
64
65
66
# File 'lib/drawio_dsl/formatters/base_formatter.rb', line 61

def h4(content, **opts)
  html.h4(content, **opts)
  items << { type: :h4, content: content }

  self
end

#h5(content, **opts) ⇒ Object



68
69
70
71
72
73
# File 'lib/drawio_dsl/formatters/base_formatter.rb', line 68

def h5(content, **opts)
  html.h5(content, **opts)
  items << { type: :h5, content: content }

  self
end

#h6(content, **opts) ⇒ Object



75
76
77
78
79
80
# File 'lib/drawio_dsl/formatters/base_formatter.rb', line 75

def h6(content, **opts)
  html.h6(content, **opts)
  items << { type: :h6, content: content }

  self
end

#hr(size: 1) ⇒ Object



19
20
21
22
23
24
# File 'lib/drawio_dsl/formatters/base_formatter.rb', line 19

def hr(size: 1)
  html.hr(size: size)
  items << { type: :hr }

  self
end

#li(content, **opts) ⇒ Object



94
95
96
97
98
# File 'lib/drawio_dsl/formatters/base_formatter.rb', line 94

def li(content, **opts)
  html.li(content, **opts)

  self
end

#p(content, **opts) ⇒ Object



33
34
35
36
37
38
# File 'lib/drawio_dsl/formatters/base_formatter.rb', line 33

def p(content, **opts)
  html.p(content, **opts)
  items << { type: :p, content: content }

  self
end

#to_hObject



108
109
110
111
112
# File 'lib/drawio_dsl/formatters/base_formatter.rb', line 108

def to_h
  {
    items: items.map(&:to_h)
  }
end

#ul_e(**opts) ⇒ Object



88
89
90
91
92
# File 'lib/drawio_dsl/formatters/base_formatter.rb', line 88

def ul_e(**opts)
  html.ul_e(**opts)

  self
end

#ul_s(**opts) ⇒ Object



82
83
84
85
86
# File 'lib/drawio_dsl/formatters/base_formatter.rb', line 82

def ul_s(**opts)
  html.ul_s(**opts)

  self
end