Class: Avo::ItemsHolder
- Inherits:
-
Object
- Object
- Avo::ItemsHolder
- Defined in:
- lib/avo/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 bag.
- #heading(body = nil, **args, &block) ⇒ Object
-
#initialize ⇒ ItemsHolder
constructor
A new instance of ItemsHolder.
- #panel(panel_name = nil, **args, &block) ⇒ Object
- #tab(name, **args, &block) ⇒ Object
- #tabs(instance) ⇒ Object
- #tool(klass, **args) ⇒ Object
Constructor Details
#initialize ⇒ ItemsHolder
Returns a new instance of ItemsHolder.
7 8 9 10 11 |
# File 'lib/avo/items_holder.rb', line 7 def initialize @items = [] @items_index = 0 @invalid_fields = [] end |
Instance Attribute Details
#invalid_fields ⇒ Object
Returns the value of attribute invalid_fields.
5 6 7 |
# File 'lib/avo/items_holder.rb', line 5 def invalid_fields @invalid_fields end |
#items ⇒ Object
Returns the value of attribute items.
4 5 6 |
# File 'lib/avo/items_holder.rb', line 4 def items @items end |
#tools ⇒ Object (readonly)
Returns the value of attribute tools.
3 4 5 |
# File 'lib/avo/items_holder.rb', line 3 def tools @tools end |
Instance Method Details
#add_item(instance) ⇒ Object
58 59 60 61 62 |
# File 'lib/avo/items_holder.rb', line 58 def add_item(instance) @items << instance increment_order_index end |
#field(field_name, **args, &block) ⇒ Object
Adds a field to the bag
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/avo/items_holder.rb', line 14 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 |
#heading(body = nil, **args, &block) ⇒ Object
52 53 54 55 56 |
# File 'lib/avo/items_holder.rb', line 52 def heading(body = nil, **args, &block) field = Avo::Fields::HeadingField.new(body, **args) add_item field end |
#panel(panel_name = nil, **args, &block) ⇒ Object
46 47 48 49 50 |
# File 'lib/avo/items_holder.rb', line 46 def panel(panel_name = nil, **args, &block) panel = Avo::PanelBuilder.parse_block(name: panel_name, **args, &block) add_item panel end |
#tab(name, **args, &block) ⇒ Object
37 38 39 |
# File 'lib/avo/items_holder.rb', line 37 def tab(name, **args, &block) add_item Avo::TabBuilder.parse_block(name: name, **args, &block) end |
#tabs(instance) ⇒ Object
33 34 35 |
# File 'lib/avo/items_holder.rb', line 33 def tabs(instance) add_item instance end |
#tool(klass, **args) ⇒ Object
41 42 43 44 |
# File 'lib/avo/items_holder.rb', line 41 def tool(klass, **args) instance = klass.new(**args) add_item instance end |