class Bootstrap4Helper::InputGroup

The InputGroup helper is meant to help you rapidly build Bootstrap input group components quickly and easily.

Constants

VALID_TYPES

Public Class Methods

new(template, type = :prepend, opts = {}, &block) click to toggle source

Class constructor

@param [Class] template - Template in which your are binding too. @param [Symbol] type - Whether the component is prepend or append. @param [Hash] opts @return [InputGroup]

Calls superclass method Bootstrap4Helper::Component::new
# File lib/bootstrap4_helper/input_group.rb, line 15
def initialize(template, type = :prepend, opts = {}, &block)
  super(template)

  @type    = VALID_TYPES.include?(type) ? type : :prepend
  @id      = opts.fetch(:id,          nil)
  @class   = opts.fetch(:class,       '')
  @data    = opts.fetch(:data,        {})
  @content = block || proc { '' }
end

Public Instance Methods

text(opts = {}, &block) click to toggle source

This is the element that actually houses the icon or text used in the input group.

@param [Hash] opts @return [String]

# File lib/bootstrap4_helper/input_group.rb, line 31
def text(opts = {}, &block)
  opts[:class] = (opts[:class] || '') << " input-group-#{@type}"

  content_tag :div, opts do
    content_tag :span, class: 'input-group-text', &block
  end
end
to_s() click to toggle source

Used to render out the InputGroup component.

@return [String]

# File lib/bootstrap4_helper/input_group.rb, line 43
def to_s
  content_tag(
    :div,
    id:    @id,
    class: "input-group #{@class}",
    data:  @data
  ) do
    @content.call(self)
  end
end