Class: Bootstrap4Helper::InputGroup
- Defined in:
- lib/bootstrap4_helper/input_group.rb
Overview
The InputGroup helper is meant to help you rapidly build Bootstrap input group components quickly and easily.
Constant Summary collapse
- VALID_TYPES =
i[append prepend].freeze
Instance Method Summary collapse
-
#initialize(template, type = :prepend, opts = {}, &block) ⇒ InputGroup
constructor
Class constructor.
-
#text(opts = {}, &block) ⇒ String
This is the element that actually houses the icon or text used in the input group.
-
#to_s ⇒ String
Used to render out the InputGroup component.
Methods inherited from Component
#capture, #concat, #config, #content_tag, #parse_arguments, #uuid
Constructor Details
#initialize(template, type = :prepend, opts = {}, &block) ⇒ InputGroup
Class constructor
15 16 17 18 19 20 21 22 23 |
# 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 |
Instance Method Details
#text(opts = {}, &block) ⇒ String
This is the element that actually houses the icon or text used in the input group.
31 32 33 34 35 36 37 |
# 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 ⇒ String
Used to render out the InputGroup component.
43 44 45 46 47 48 49 50 51 52 |
# 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 |