Class: BootstrapConcerns::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/bootstrap_concerns/option.rb

Constant Summary collapse

BUTTON_BASE_CLASS =
"btn".freeze
DEFAULT_BUTTON_COLOR =
"primary".freeze

Class Method Summary collapse

Class Method Details

.options_with_base_class(options, *base_class) ⇒ Object



17
18
19
20
21
# File 'lib/bootstrap_concerns/option.rb', line 17

def options_with_base_class(options, *base_class)
  options.merge(
    class: (base_class + [options[:class]]).compact.join(" ")
  )
end

.options_with_button_class(options = {}) ⇒ Object



7
8
9
10
11
# File 'lib/bootstrap_concerns/option.rb', line 7

def options_with_button_class(options = {})
  color = prefixed_option(options, key: :color, prefix: BUTTON_BASE_CLASS, default: DEFAULT_BUTTON_COLOR)
  size = prefixed_option(options, key: :size, prefix: BUTTON_BASE_CLASS)
  options_with_base_class(options, BUTTON_BASE_CLASS, color, size)
end

.prefixed_option(options, key:, prefix:, default: nil) ⇒ Object



13
14
15
# File 'lib/bootstrap_concerns/option.rb', line 13

def prefixed_option(options, key:, prefix:, default: nil)
  (options.delete(key) || default)&.then { "#{prefix}-#{it}" }
end