Class: ActiveAdmin::Views::StatusTag

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

Overview

Build a StatusTag

Instance Method Summary collapse

Methods inherited from Component

#initialize

Constructor Details

This class inherits a constructor from ActiveAdmin::Component

Instance Method Details

#build(*args) ⇒ ActiveAdmin::Views::StatusTag

Examples:

status_tag('In Progress')
# => <span class='status in_progress'>In Progress</span>

status_tag('active', :ok)
# => <span class='status active ok'>Active</span>

status_tag('active', :ok, :class => 'important', :id => 'status_123')
# => <span class='status active ok important' id='status_123'>Active</span>

Parameters:

  • status (String)

    the status to display. One of the span classes will be an underscored version of the status.

  • type (Symbol)

    type of status. Will become a class of the span. ActiveAdmin provide style for :ok, :warning and :error.

  • options (Hash)

    such as :class, :id etc

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/active_admin/views/components/status_tag.rb', line 33

def build(*args)
  options = args.extract_options!
  status = args[0]
  type = args[1]
  classes = options.delete(:class)

  status = status.titleize if status

  super(status, options)

  add_class(status_to_class(status)) if status
  add_class(type.to_s) if type
  add_class(classes) if classes
end

#default_class_nameObject



11
12
13
# File 'lib/active_admin/views/components/status_tag.rb', line 11

def default_class_name
  'status'
end

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

Examples:

status_tag('In Progress')
# => <span class='status in_progress'>In Progress</span>

status_tag('active', :ok)
# => <span class='status active ok'>Active</span>

status_tag('active', :ok, :class => 'important', :id => 'status_123')
# => <span class='status active ok important' id='status_123'>Active</span>

Parameters:

  • status (String)

    the status to display. One of the span classes will be an underscored version of the status.

  • type (Symbol) (defaults to: nil)

    type of status. Will become a class of the span. ActiveAdmin provide style for :ok, :warning and :error.

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

    such as :class, :id etc

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/active_admin/views/components/status_tag.rb', line 33

def build(*args)
  options = args.extract_options!
  status = args[0]
  type = args[1]
  classes = options.delete(:class)

  status = status.titleize if status

  super(status, options)

  add_class(status_to_class(status)) if status
  add_class(type.to_s) if type
  add_class(classes) if classes
end

#status_to_class(status) ⇒ Object (protected)



50
51
52
# File 'lib/active_admin/views/components/status_tag.rb', line 50

def status_to_class(status)
  status.titleize.gsub(/\s/, '').underscore
end

#tag_nameObject



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

def tag_name
  'span'
end