Module: Avo::Fields::Concerns::HasHTMLAttributes

Extended by:
ActiveSupport::Concern
Included in:
BaseField, Index::GridItemComponent
Defined in:
lib/avo/fields/concerns/has_html_attributes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



7
8
9
# File 'lib/avo/fields/concerns/has_html_attributes.rb', line 7

def html
  @html
end

Instance Method Details

#get_html(name = nil, element:, view:) ⇒ Object

Used to get attributes for elements and views

examples: get_html :data, view: :edit, element: :input get_html :classes, view: :show, element: :wrapper get_html :styles, view: :index, element: :wrapper



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/avo/fields/concerns/has_html_attributes.rb', line 15

def get_html(name = nil, element:, view:)
  view = view.to_sym if view.present?

  if [view, element].any?(&:nil?)
    default_attribute_value name
  end

  parsed = parse_html

  attributes = if parsed.is_a? Hash
    get_html_from_hash name, element: element, hash: parsed, view: view
  elsif parsed.is_a? Avo::HTML::Builder
    get_html_from_block name, element: element, html_builder: parsed, view: view
  elsif parsed.nil?
    # Handle empty parsed by returning an empty state
    default_attribute_value name
  end

  add_action_data_attributes(attributes, name, element)
  add_resource_data_attributes(attributes, name, element, view)

  value_or_default name, attributes
end