Class: ActiveAdmin::Views::StatusTag

Inherits:
Component
  • Object
show all
Defined in:
lib/active_admin/views/components/status_tag.rb

Overview

Build a StatusTag

Instance Method Summary collapse

Instance Method Details

#status_tag(status, options = {}) ⇒ ActiveAdmin::Views::StatusTag

Examples:

status_tag(true)
# => <span class="status-tag" data-status="yes">Yes</span>
status_tag(false)
# => <span class="status-tag" data-status="no">No</span>
status_tag(nil)
# => <span class="status-tag" data-status="unset">Unknown</span>
status_tag('In Progress')
# => <span class="status-tag" data-status="in_progress">In Progress</span>
status_tag('Active', class: 'important', id: 'status_123', label: 'on')
# => <span class="status-tag important" id="status_123" data-status="active">on</span>

Parameters:

  • status (String)

    the status to display.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :class (String)

    to override the default class

  • :id (String)

    to override the default id

  • :label (String)

    to override the default label

Returns:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/active_admin/views/components/status_tag.rb', line 40

def build(status, options = {})
  label = options.delete(:label)
  classes = options.delete(:class)
  boolean_status = convert_to_boolean_status(status)
  status = boolean_status || status

  if status
    content = label || if s = status.to_s and s.present?
                         I18n.t "active_admin.status_tag.#{s.downcase}", default: s.titleize
                       end
  end

  super(content, options)
  add_class "status-tag"
  set_attribute("data-status", convert_status(status)) if status
  add_class(classes) if classes
end

#tag_nameObject



8
9
10
# File 'lib/active_admin/views/components/status_tag.rb', line 8

def tag_name
  "span"
end