Module: FlexiAdmin::Components::Helpers::ValueFormatter

Included in:
Resources::GridViewComponent, Resources::ListViewComponent
Defined in:
lib/flexi_admin/components/helpers/value_formatter.rb

Instance Method Summary collapse

Instance Method Details

#as_date(value, format: nil) ⇒ Object



9
10
11
12
13
# File 'lib/flexi_admin/components/helpers/value_formatter.rb', line 9

def as_date(value, format: nil)
  return nil if value.blank?

  I18n.l(value, format:)
end

#as_navigation(value) ⇒ Object



15
16
17
18
# File 'lib/flexi_admin/components/helpers/value_formatter.rb', line 15

def as_navigation(value)
  helpers.link_to value, value, 'data-turbo-frame': '_top'
  # content_tag(:a, value, href: value, 'data-turbo-frame': '_top')
end

#as_text(value) ⇒ Object



5
6
7
# File 'lib/flexi_admin/components/helpers/value_formatter.rb', line 5

def as_text(value)
  value.to_s
end

#format(formatter) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/flexi_admin/components/helpers/value_formatter.rb', line 20

def format(formatter)
  case formatter.to_sym
  when :date
    proc { |value| as_date(value) }
  when :text
    proc { |value| as_text(value) }
  when :navigation
    proc { |value| as_navigation(value) }
  else
    raise ArgumentError, "Unknown formatter: #{@formatter}"
  end
end