Class: Avo::Resources::Items::Holder
- Inherits:
-
Object
- Object
- Avo::Resources::Items::Holder
- Defined in:
- lib/avo/resources/items/holder.rb
Instance Attribute Summary collapse
-
#invalid_fields ⇒ Object
Returns the value of attribute invalid_fields.
-
#items ⇒ Object
Returns the value of attribute items.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Instance Method Summary collapse
- #add_item(instance) ⇒ Object
-
#field(field_name, **args, &block) ⇒ Object
Adds a field to the items_holder.
-
#initialize ⇒ Holder
constructor
A new instance of Holder.
- #panel(panel_name = nil, **args, &block) ⇒ Object
- #row(**args, &block) ⇒ Object
- #sidebar(**args, &block) ⇒ Object
- #tab(name, **args, &block) ⇒ Object
- #tabs(tab = nil, **kwargs, &block) ⇒ Object
- #tool(klass, **args) ⇒ Object
Constructor Details
#initialize ⇒ Holder
Returns a new instance of Holder.
6 7 8 9 10 |
# File 'lib/avo/resources/items/holder.rb', line 6 def initialize @items = [] @items_index = 0 @invalid_fields = [] end |
Instance Attribute Details
#invalid_fields ⇒ Object
Returns the value of attribute invalid_fields.
4 5 6 |
# File 'lib/avo/resources/items/holder.rb', line 4 def invalid_fields @invalid_fields end |
#items ⇒ Object
Returns the value of attribute items.
3 4 5 |
# File 'lib/avo/resources/items/holder.rb', line 3 def items @items end |
#tools ⇒ Object (readonly)
Returns the value of attribute tools.
2 3 4 |
# File 'lib/avo/resources/items/holder.rb', line 2 def tools @tools end |
Instance Method Details
#add_item(instance) ⇒ Object
63 64 65 66 67 |
# File 'lib/avo/resources/items/holder.rb', line 63 def add_item(instance) @items << instance increment_order_index end |
#field(field_name, **args, &block) ⇒ Object
Adds a field to the items_holder
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/avo/resources/items/holder.rb', line 13 def field(field_name, **args, &block) field_parser = Avo::Dsl::FieldParser.new(id: field_name, order_index: @items_index, **args, &block).parse if field_parser.invalid? as = args.fetch(:as, nil) # End execution ehre and add the field to the invalid_fileds payload so we know to wanr the developer about that. # @todo: Make sure this warning is still active return add_invalid_field({ name: field_name, as: as, # resource: resource_class.name, message: "There's an invalid field configuration for this resource. <br/> <code class='px-1 py-px rounded bg-red-600'>field :#{field_name}, as: :#{as}</code>" }) end add_item field_parser.instance end |
#panel(panel_name = nil, **args, &block) ⇒ Object
53 54 55 56 57 |
# File 'lib/avo/resources/items/holder.rb', line 53 def panel(panel_name = nil, **args, &block) panel = Avo::Resources::Items::ItemGroup::Builder.parse_block(name: panel_name, **args, &block) add_item panel end |
#row(**args, &block) ⇒ Object
44 45 46 |
# File 'lib/avo/resources/items/holder.rb', line 44 def row(**args, &block) add_item Avo::Resources::Items::Row::Builder.parse_block(**args, &block) end |
#sidebar(**args, &block) ⇒ Object
59 60 61 |
# File 'lib/avo/resources/items/holder.rb', line 59 def (**args, &block) add_item Avo::Resources::Items::Sidebar::Builder.parse_block(**args, &block) end |
#tab(name, **args, &block) ⇒ Object
40 41 42 |
# File 'lib/avo/resources/items/holder.rb', line 40 def tab(name, **args, &block) add_item Avo::Resources::Items::Tab::Builder.parse_block(name: name, **args, &block) end |
#tabs(tab = nil, **kwargs, &block) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/avo/resources/items/holder.rb', line 32 def tabs(tab = nil, **kwargs, &block) if tab.present? add_item tab else add_item Avo::Resources::Items::TabGroup::Builder.parse_block(**kwargs, &block) end end |
#tool(klass, **args) ⇒ Object
48 49 50 51 |
# File 'lib/avo/resources/items/holder.rb', line 48 def tool(klass, **args) instance = klass.new(**args) add_item instance end |