Class: Bootstrap4Helper::Spinner

Inherits:
Component show all
Defined in:
lib/bootstrap4_helper/spinner.rb

Overview

Builds a simple CSS spinner component.

Instance Method Summary collapse

Methods inherited from Component

#capture, #concat, #config, #content_tag, #parse_arguments, #uuid

Constructor Details

#initialize(template, opts = {}, &block) ⇒ Spinner

Note:

The different support types are: ‘:border` and `:grow`

Class constructor

Options Hash (opts):

  • :type (Symbol)
  • :id (String)
  • :class (String)
  • :data (Hash)


17
18
19
20
21
22
23
24
25
# File 'lib/bootstrap4_helper/spinner.rb', line 17

def initialize(template, opts = {}, &block)
  super(template)

  @type    = opts.fetch(:type, :border)
  @id      = opts.fetch(:id,    uuid)
  @class   = opts.fetch(:class, '')
  @data    = opts.fetch(:data,  {})
  @content = block || proc { '' }
end

Instance Method Details

#to_sString

String representation of the object.



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bootstrap4_helper/spinner.rb', line 31

def to_s
  (
    :span,
    id:    @id,
    class: "spinner-#{@type} #{@class}",
    role:  'status',
    aria:  { hidden: true },
    data:  @data
  ) do
     :span, 'Loading', class: 'sr-only'
  end
end