Class: TinyAdmin::Views::Components::FieldValue

Inherits:
BasicComponent
  • Object
show all
Defined in:
lib/tiny_admin/views/components/field_value.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BasicComponent

#update_attributes

Constructor Details

#initialize(field, value, record:) ⇒ FieldValue

Returns a new instance of FieldValue.



9
10
11
12
13
# File 'lib/tiny_admin/views/components/field_value.rb', line 9

def initialize(field, value, record:)
  @field = field
  @value = value
  @record = record
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



7
8
9
# File 'lib/tiny_admin/views/components/field_value.rb', line 7

def field
  @field
end

#recordObject (readonly)

Returns the value of attribute record.



7
8
9
# File 'lib/tiny_admin/views/components/field_value.rb', line 7

def record
  @record
end

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/tiny_admin/views/components/field_value.rb', line 7

def value
  @value
end

Instance Method Details

#view_templateObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tiny_admin/views/components/field_value.rb', line 15

def view_template
  translated_value = field.translate_value(value)
  value_class = field.options[:options]&.include?('value_class') ? "value-#{value}" : nil
  if field.options[:link_to]
    a(href: TinyAdmin.route_for(field.options[:link_to], reference: translated_value)) {
      span(class: value_class) {
        field.apply_call_option(record) || translated_value
      }
    }
  else
    span(class: value_class) {
      translated_value
    }
  end
end