Class: DrawioDsl::DomBuilder
- Inherits:
-
Object
- Object
- DrawioDsl::DomBuilder
- Includes:
- DomBuilderShapes
- Defined in:
- lib/drawio_dsl/dom_builder.rb
Overview
Build Document object model to represent DrawioDsl output file.
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#focus_node ⇒ Object
readonly
Returns the value of attribute focus_node.
-
#last_action ⇒ Object
readonly
Returns the value of attribute last_action.
Instance Method Summary collapse
- #add_flex_layout(**opts) ⇒ Object
-
#add_grid_layout(**opts) ⇒ Object
———————————————————————- Layout provides rules for positioning components ———————————————————————-.
- #add_layout(rule) ⇒ Object
-
#add_page(**opts) ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#add_shape(shape) ⇒ Object
———————————————————————- Shapes represent visual components ———————————————————————-.
-
#debug ⇒ Object
:nocov:.
- #diagram ⇒ Object
-
#dom ⇒ Object
:nocov:.
-
#initialize ⇒ DomBuilder
constructor
attr_reader :current_layout_rule attr_reader :current_shape.
- #queue_action(action) ⇒ Object
- #reset ⇒ Object
- #set_diagram(**opts) ⇒ Object
Methods included from DomBuilderShapes
#add_actor, #add_actor2, #add_callout, #add_callout2, #add_callout3, #add_callout4, #add_circle, #add_cloud, #add_container, #add_container2, #add_container3, #add_container4, #add_cross, #add_dash, #add_dash24, #add_dash32, #add_dash44, #add_dash_dot, #add_dash_dot_dot, #add_dash_long_dash, #add_database, #add_db_json, #add_diamond, #add_document, #add_dot, #add_dot_dot_dot, #add_double, #add_double_dash, #add_double_dot, #add_ellipse, #add_embed_col200, #add_embed_col50, #add_embed_row, #add_envelop, #add_face, #add_group, #add_h1, #add_h2, #add_h3, #add_h4, #add_h5, #add_h6, #add_hexagon, #add_interface, #add_klass, #add_long_dash, #add_note, #add_p, #add_process, #add_rectangle, #add_rectangle2, #add_solid, #add_square, #add_step, #add_tick, #add_todo, #add_triangle
Constructor Details
#initialize ⇒ DomBuilder
attr_reader :current_layout_rule attr_reader :current_shape
17 18 19 20 |
# File 'lib/drawio_dsl/dom_builder.rb', line 17 def initialize @actions = [] @last_action = {} end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
8 9 10 |
# File 'lib/drawio_dsl/dom_builder.rb', line 8 def actions @actions end |
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
12 13 14 |
# File 'lib/drawio_dsl/dom_builder.rb', line 12 def current_page @current_page end |
#focus_node ⇒ Object (readonly)
Returns the value of attribute focus_node.
11 12 13 |
# File 'lib/drawio_dsl/dom_builder.rb', line 11 def focus_node @focus_node end |
#last_action ⇒ Object (readonly)
Returns the value of attribute last_action.
9 10 11 |
# File 'lib/drawio_dsl/dom_builder.rb', line 9 def last_action @last_action end |
Instance Method Details
#add_flex_layout(**opts) ⇒ Object
73 74 75 76 |
# File 'lib/drawio_dsl/dom_builder.rb', line 73 def add_flex_layout(**opts) rule = DrawioDsl::Schema::FlexLayout.new(current_page, **opts) add_layout(rule) end |
#add_grid_layout(**opts) ⇒ Object
Layout provides rules for positioning components
68 69 70 71 |
# File 'lib/drawio_dsl/dom_builder.rb', line 68 def add_grid_layout(**opts) rule = DrawioDsl::Schema::GridLayout.new(current_page, **opts) add_layout(rule) end |
#add_layout(rule) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/drawio_dsl/dom_builder.rb', line 78 def add_layout(rule) # @current_layout_rule = rule rule.id = "rule-#{current_page.nodes.length + 1}" unless rule.id # current_page.nodes.add(rule) focus_node.nodes.add(focus_node, rule) rule end |
#add_page(**opts) ⇒ Object
rubocop:disable Metrics/AbcSize
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/drawio_dsl/dom_builder.rb', line 45 def add_page(**opts) @current_page = DrawioDsl::Schema::Page.new(diagram, **opts) current_page.id = SecureRandom.alphanumeric(3) unless current_page.id # add anchor nodes page_anchor = DrawioDsl::Schema::Anchor.new(self, id: "page_root_#{current_page.id}", key: :page_root) node_anchor = DrawioDsl::Schema::Anchor.new(self, id: "node_root_#{current_page.id}", key: :node_root) page_anchor.add_node(node_anchor) @focus_node = node_anchor # page_anchor.nodes.add(node_anchor) current_page.add_node(page_anchor) diagram.pages << @current_page @current_page end |
#add_shape(shape) ⇒ Object
Shapes represent visual components
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/drawio_dsl/dom_builder.rb', line 93 def add_shape(shape) # @current_shape = shape shape.id = "#{current_page.id}-#{focus_node.nodes.length + 1}" unless shape.id # current_page.nodes.add(shape) focus_node.nodes.add(focus_node, shape) shape end |
#debug ⇒ Object
:nocov:
105 106 107 108 |
# File 'lib/drawio_dsl/dom_builder.rb', line 105 def debug puts JSON.pretty_generate(actions) puts JSON.pretty_generate(diagram.to_h) end |
#diagram ⇒ Object
38 39 40 41 42 |
# File 'lib/drawio_dsl/dom_builder.rb', line 38 def diagram return @diagram if defined? @diagram set_diagram end |
#dom ⇒ Object
:nocov:
111 112 113 |
# File 'lib/drawio_dsl/dom_builder.rb', line 111 def dom diagram.to_h end |
#queue_action(action) ⇒ Object
29 30 31 32 |
# File 'lib/drawio_dsl/dom_builder.rb', line 29 def queue_action(action) @actions << action @last_action = action end |
#reset ⇒ Object
22 23 24 25 26 27 |
# File 'lib/drawio_dsl/dom_builder.rb', line 22 def reset @actions = [] @last_action = {} set_diagram # set_layout_engine end |