Class: DrawioDsl::Schema::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/drawio_dsl/schema/page.rb

Overview

Page is a container for nodes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(diagram, **args) ⇒ Page

rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/drawio_dsl/schema/page.rb', line 40

def initialize(diagram, **args)
  @diagram = diagram

  @id           = args[:id]
  @active       = args[:active].nil? ? true : !args[:active].nil?
  @name         = args[:name]
  @theme        = args[:theme] || diagram.theme
  @bg_theme     = args[:bg_theme] || diagram.bg_theme

  # cursor positioning is used by the layout engine
  @position_x   = 0
  @position_y   = 0

  # settings to support the layout engine
  @margin_left  = args[:margin_left]  || 50
  @margin_top   = args[:margin_top]   || 50

  # settings that live on the drawio page object
  @grid         = args[:grid]         || 0
  @grid_size    = args[:grid_size]    || 10
  @guides       = args[:guides]       || 1
  @tooltips     = args[:tooltips]     || 1
  @connect      = args[:connect]      || 1
  @arrows       = args[:arrows]       || 1
  @fold         = args[:fold]         || 1
  @page_no      = args[:page_no]      || 1
  @page_scale   = args[:page_scale]   || 1
  @page_width   = args[:page_width]   || 1169 # A4
  @page_height  = args[:page_height]  || 827  # A4
  @background   = args[:background]   || bg_theme_palette.bg_color
  @page_shadow  = args[:page_shadow]  || 0
  @math         = args[:math]         || 0

  @style = DrawioDsl::Schema::CommonStyle.new(**args) do
    # Inherit from the diagram style when specific style not specified.
    @white_space  ||= diagram.style.white_space
    @html         ||= diagram.style.html
    @rounded      ||= diagram.style.rounded
    @shadow       ||= diagram.style.shadow
    @sketch       ||= diagram.style.sketch
    @glass        ||= diagram.style.glass
  end

  @palette = DrawioDsl::Schema::DefaultPalette.new(self, **args) do |page|
    # Inherit from theme when specific palette options are not specified.
    @fill_color   ||= page.theme_palette.fill_color
    @stroke_color ||= page.theme_palette.stroke_color
    @font_color   ||= page.theme_palette.font_color
    @gradient     ||= page.theme_palette.gradient
  end

  @nodes = NodeList.new # []
end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



14
15
16
# File 'lib/drawio_dsl/schema/page.rb', line 14

def active
  @active
end

#arrowsObject (readonly)

arrows = “1”



29
30
31
# File 'lib/drawio_dsl/schema/page.rb', line 29

def arrows
  @arrows
end

#backgroundObject (readonly)

background = “#FFFACD”



35
36
37
# File 'lib/drawio_dsl/schema/page.rb', line 35

def background
  @background
end

#bg_themeObject (readonly)

Returns the value of attribute bg_theme.



17
18
19
# File 'lib/drawio_dsl/schema/page.rb', line 17

def bg_theme
  @bg_theme
end

#connectObject (readonly)

connect = “1”



28
29
30
# File 'lib/drawio_dsl/schema/page.rb', line 28

def connect
  @connect
end

#diagramObject

Returns the value of attribute diagram.



7
8
9
# File 'lib/drawio_dsl/schema/page.rb', line 7

def diagram
  @diagram
end

#foldObject (readonly)

fold = “1”



30
31
32
# File 'lib/drawio_dsl/schema/page.rb', line 30

def fold
  @fold
end

#gridObject (readonly)

grid = “0”



24
25
26
# File 'lib/drawio_dsl/schema/page.rb', line 24

def grid
  @grid
end

#grid_sizeObject (readonly)

gridSize = “10”



25
26
27
# File 'lib/drawio_dsl/schema/page.rb', line 25

def grid_size
  @grid_size
end

#guidesObject (readonly)

guides = “1”



26
27
28
# File 'lib/drawio_dsl/schema/page.rb', line 26

def guides
  @guides
end

#idObject

Returns the value of attribute id.



13
14
15
# File 'lib/drawio_dsl/schema/page.rb', line 13

def id
  @id
end

#margin_leftObject (readonly)

Returns the value of attribute margin_left.



20
21
22
# File 'lib/drawio_dsl/schema/page.rb', line 20

def margin_left
  @margin_left
end

#margin_topObject (readonly)

Returns the value of attribute margin_top.



21
22
23
# File 'lib/drawio_dsl/schema/page.rb', line 21

def margin_top
  @margin_top
end

#mathObject (readonly)

math = “0”



37
38
39
# File 'lib/drawio_dsl/schema/page.rb', line 37

def math
  @math
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/drawio_dsl/schema/page.rb', line 15

def name
  @name
end

#nodesObject (readonly)

Returns the value of attribute nodes.



22
23
24
# File 'lib/drawio_dsl/schema/page.rb', line 22

def nodes
  @nodes
end

#page_heightObject (readonly)

pageHeight = “827”



34
35
36
# File 'lib/drawio_dsl/schema/page.rb', line 34

def page_height
  @page_height
end

#page_noObject (readonly)

page = “1”



31
32
33
# File 'lib/drawio_dsl/schema/page.rb', line 31

def page_no
  @page_no
end

#page_scaleObject (readonly)

pageScale = “1”



32
33
34
# File 'lib/drawio_dsl/schema/page.rb', line 32

def page_scale
  @page_scale
end

#page_shadowObject (readonly)

shadow = “0”



36
37
38
# File 'lib/drawio_dsl/schema/page.rb', line 36

def page_shadow
  @page_shadow
end

#page_widthObject (readonly)

pageWidth = “583”



33
34
35
# File 'lib/drawio_dsl/schema/page.rb', line 33

def page_width
  @page_width
end

#paletteObject (readonly)

Returns the value of attribute palette.



19
20
21
# File 'lib/drawio_dsl/schema/page.rb', line 19

def palette
  @palette
end

#position_xObject

These transient attributes hold the current x, y location for the last element added to the page



10
11
12
# File 'lib/drawio_dsl/schema/page.rb', line 10

def position_x
  @position_x
end

#position_yObject

Returns the value of attribute position_y.



11
12
13
# File 'lib/drawio_dsl/schema/page.rb', line 11

def position_y
  @position_y
end

#styleObject (readonly)

Returns the value of attribute style.



18
19
20
# File 'lib/drawio_dsl/schema/page.rb', line 18

def style
  @style
end

#themeObject (readonly)

Returns the value of attribute theme.



16
17
18
# File 'lib/drawio_dsl/schema/page.rb', line 16

def theme
  @theme
end

#tooltipsObject (readonly)

tooltips = “1”



27
28
29
# File 'lib/drawio_dsl/schema/page.rb', line 27

def tooltips
  @tooltips
end

Instance Method Details

#active?Boolean

rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength

Returns:

  • (Boolean)


95
96
97
# File 'lib/drawio_dsl/schema/page.rb', line 95

def active?
  !!@active
end

#add_node(node) ⇒ Object



99
100
101
102
# File 'lib/drawio_dsl/schema/page.rb', line 99

def add_node(node)
  @nodes.add(self, node)
  node
end

#as_xml(xml) ⇒ Object



112
113
114
# File 'lib/drawio_dsl/schema/page.rb', line 112

def as_xml(xml)
  nodes.as_xml(xml)
end

#bg_theme_paletteObject



108
109
110
# File 'lib/drawio_dsl/schema/page.rb', line 108

def bg_theme_palette
  @bg_theme_palette ||= KConfig.configuration.drawio.theme.background(bg_theme)
end

#theme_paletteObject



104
105
106
# File 'lib/drawio_dsl/schema/page.rb', line 104

def theme_palette
  @theme_palette ||= KConfig.configuration.drawio.theme.element(theme)
end

#to_hObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/drawio_dsl/schema/page.rb', line 116

def to_h
  {
    id: id,
    active: active,
    name: name,
    position_x: position_x,
    position_y: position_y,
    theme: theme,
    bg_theme: bg_theme,
    palette: palette.to_h,
    style: style.to_h,
    settings: settings,
    nodes: nodes.to_h
  }
end