Class: Sirens::LayoutBuilder
- Inherits:
-
Object
- Object
- Sirens::LayoutBuilder
- Defined in:
- lib/components_builder/layout_builder.rb
Instance Attribute Summary collapse
-
#built_components ⇒ Object
readonly
Returns the value of attribute built_components.
-
#built_props ⇒ Object
readonly
Accessing.
Instance Method Summary collapse
-
#button(props = , &build_block) ⇒ Object
Widgets.
- #checkbox(props = , &build_block) ⇒ Object
- #choices_list(props = , &build_block) ⇒ Object
- #choices_tree(props = , &build_block) ⇒ Object
-
#component(component) ⇒ Object
Containers.
- #eval(props: , &build_block) ⇒ Object
- #horizontal_splitter(props = , &build_block) ⇒ Object
- #horizontal_stack(props = , &build_block) ⇒ Object
-
#initialize(root_component: nil) ⇒ LayoutBuilder
constructor
Initializing.
- #input_text(props = , &build_block) ⇒ Object
- #list(props = , &build_block) ⇒ Object
- #merge_props(props) ⇒ Object
- #model(model) ⇒ Object
- #popup_menu(&block) ⇒ Object
- #radio_button(props = , &build_block) ⇒ Object
- #radio_buttons_group(props = , &build_block) ⇒ Object
-
#render(props: , &build_block) ⇒ Object
Building.
- #styles(props) ⇒ Object
- #tabs(props = , &build_block) ⇒ Object
- #text(props = , &build_block) ⇒ Object
- #vertical_splitter(props = , &build_block) ⇒ Object
- #vertical_stack(props = , &build_block) ⇒ Object
- #window(props = , &build_block) ⇒ Object
Constructor Details
#initialize(root_component: nil) ⇒ LayoutBuilder
Initializing
6 7 8 9 10 11 12 |
# File 'lib/components_builder/layout_builder.rb', line 6 def initialize(root_component: nil) super() @root_component = root_component @built_props = Hash[] @built_components = [] end |
Instance Attribute Details
#built_components ⇒ Object (readonly)
Returns the value of attribute built_components.
17 18 19 |
# File 'lib/components_builder/layout_builder.rb', line 17 def built_components @built_components end |
#built_props ⇒ Object (readonly)
Accessing
16 17 18 |
# File 'lib/components_builder/layout_builder.rb', line 16 def built_props @built_props end |
Instance Method Details
#button(props = , &build_block) ⇒ Object
Widgets
129 130 131 132 133 134 135 |
# File 'lib/components_builder/layout_builder.rb', line 129 def (props = Hash[], &build_block) LayoutBuilder.new.tap do |builder| builder.eval(props: props, &build_block) @built_components << Button.new(builder.built_props) end end |
#checkbox(props = , &build_block) ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/components_builder/layout_builder.rb', line 137 def checkbox(props = Hash[], &build_block) LayoutBuilder.new.tap do |builder| builder.eval(props: props, &build_block) @built_components << Checkbox.new(builder.built_props) end end |
#choices_list(props = , &build_block) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/components_builder/layout_builder.rb', line 171 def choices_list(props = Hash[], &build_block) columns_builder = ColumnsBuilder.new.render(props, &build_block) props[:popup_menu] = columns_builder. unless columns_builder..nil? ListChoice.new(props).tap { |list| list.define_columns(columns_builder.columns) @built_components << list } end |
#choices_tree(props = , &build_block) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/components_builder/layout_builder.rb', line 199 def choices_tree(props = Hash[], &build_block) columns_builder = ColumnsBuilder.new.render(props, &build_block) props[:popup_menu] = columns_builder. unless columns_builder..nil? TreeChoice.new(props).tap { |tree| tree.define_columns(columns_builder.columns) @built_components << tree } end |
#component(component) ⇒ Object
Containers
51 52 53 |
# File 'lib/components_builder/layout_builder.rb', line 51 def component(component) @built_components << component end |
#eval(props: , &build_block) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/components_builder/layout_builder.rb', line 29 def eval(props: Hash[], &build_block) merge_props(props) instance_exec(@root_component, &build_block) unless build_block.nil? self end |
#horizontal_splitter(props = , &build_block) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/components_builder/layout_builder.rb', line 91 def horizontal_splitter(props = Hash[], &build_block) LayoutBuilder.new.tap do |builder| builder.eval(props: props, &build_block) Splitter.horizontal(builder.built_props).tap do |splitter| splitter.add_all_components(builder.built_components) @built_components << splitter end end end |
#horizontal_stack(props = , &build_block) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/components_builder/layout_builder.rb', line 67 def horizontal_stack(props = Hash[], &build_block) LayoutBuilder.new.tap do |builder| builder.eval(props: props, &build_block) Stack.horizontal(builder.built_props).tap do |stack| stack.add_all_components(builder.built_components) @built_components << stack end end end |
#input_text(props = , &build_block) ⇒ Object
183 184 185 186 187 188 189 |
# File 'lib/components_builder/layout_builder.rb', line 183 def input_text(props = Hash[], &build_block) LayoutBuilder.new.tap do |builder| builder.eval(props: props, &build_block) @built_components << InputText.new(builder.built_props) end end |
#list(props = , &build_block) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/components_builder/layout_builder.rb', line 159 def list(props = Hash[], &build_block) columns_builder = ColumnsBuilder.new.render(props, &build_block) props[:popup_menu] = columns_builder. unless columns_builder..nil? List.new(props).tap { |list| list.define_columns(columns_builder.columns) @built_components << list } end |
#merge_props(props) ⇒ Object
45 46 47 |
# File 'lib/components_builder/layout_builder.rb', line 45 def merge_props(props) @built_props.merge!(props) end |
#model(model) ⇒ Object
41 42 43 |
# File 'lib/components_builder/layout_builder.rb', line 41 def model(model) merge_props(model: model) end |
#popup_menu(&block) ⇒ Object
211 212 213 |
# File 'lib/components_builder/layout_builder.rb', line 211 def (&block) merge_props(popup_menu: block) end |
#radio_button(props = , &build_block) ⇒ Object
145 146 147 148 149 150 151 |
# File 'lib/components_builder/layout_builder.rb', line 145 def (props = Hash[], &build_block) LayoutBuilder.new.tap do |builder| builder.eval(props: props, &build_block) @built_components << RadioButton.new(builder.built_props) end end |
#radio_buttons_group(props = , &build_block) ⇒ Object
153 154 155 156 157 |
# File 'lib/components_builder/layout_builder.rb', line 153 def (props = Hash[], &build_block) = RadioButtonGroupBuilder.new.render(&build_block) @built_components.concat() end |
#render(props: , &build_block) ⇒ Object
Building
21 22 23 24 25 26 27 |
# File 'lib/components_builder/layout_builder.rb', line 21 def render(props: Hash[], &build_block) eval(props: props, &build_block) @root_component.add_all_components(built_components) self end |
#styles(props) ⇒ Object
37 38 39 |
# File 'lib/components_builder/layout_builder.rb', line 37 def styles(props) merge_props(props) end |
#tabs(props = , &build_block) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/components_builder/layout_builder.rb', line 115 def tabs(props = Hash[], &build_block) LayoutBuilder.new.tap do |builder| builder.eval(props: props, &build_block) Tabs.new(builder.built_props).tap do |tabs| tabs.add_all_components(builder.built_components) @built_components << tabs end end end |
#text(props = , &build_block) ⇒ Object
191 192 193 194 195 196 197 |
# File 'lib/components_builder/layout_builder.rb', line 191 def text(props = Hash[], &build_block) LayoutBuilder.new.tap do |builder| builder.eval(props: props, &build_block) @built_components << Text.new(builder.built_props) end end |
#vertical_splitter(props = , &build_block) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/components_builder/layout_builder.rb', line 103 def vertical_splitter(props = Hash[], &build_block) LayoutBuilder.new.tap do |builder| builder.eval(props: props, &build_block) Splitter.vertical(builder.built_props).tap do |splitter| splitter.add_all_components(builder.built_components) @built_components << splitter end end end |
#vertical_stack(props = , &build_block) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/components_builder/layout_builder.rb', line 79 def vertical_stack(props = Hash[], &build_block) LayoutBuilder.new.tap do |builder| builder.eval(props: props, &build_block) Stack.vertical(builder.built_props).tap do |stack| stack.add_all_components(builder.built_components) @built_components << stack end end end |
#window(props = , &build_block) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/components_builder/layout_builder.rb', line 55 def window(props = Hash[], &build_block) LayoutBuilder.new.tap do |builder| builder.eval(props: props, &build_block) Window.new(builder.built_props).tap do |window| window.add_all_components(builder.built_components) @built_components << window end end end |