Class: Bootstrap4Helper::Tab
- Defined in:
- lib/bootstrap4_helper/tab.rb,
lib/bootstrap4_helper/tab/content.rb
Overview
Builds a Tab component.
Defined Under Namespace
Classes: Content
Instance Method Summary collapse
-
#content(opts = {}, &block) ⇒ Tab::Content
Builds the Content object for the Tab.
-
#initialize(template, opts = {}, &block) ⇒ Tab
constructor
Class constructor.
-
#nav(opts = {}, &block) ⇒ Nav
Builds a custom Nav component for the tabs.
-
#to_s ⇒ Object
This has a weird interaction.
Methods inherited from Component
#capture, #concat, #config, #content_tag, #parse_arguments, #uuid
Constructor Details
#initialize(template, opts = {}, &block) ⇒ Tab
Note:
The support types are: ‘:tabs` and `:pills`
Class constructor
17 18 19 20 21 22 23 24 25 |
# File 'lib/bootstrap4_helper/tab.rb', line 17 def initialize(template, opts = {}, &block) super(template) @type = opts.fetch(:type, :tabs) @id = opts.fetch(:id, uuid) @class = opts.fetch(:class, '') @data = opts.fetch(:data, {}) @content = block || proc { '' } end |
Instance Method Details
#content(opts = {}, &block) ⇒ Tab::Content
Builds the Content object for the Tab.
54 55 56 |
# File 'lib/bootstrap4_helper/tab.rb', line 54 def content(opts = {}, &block) Content.new(@template, opts, &block) end |
#nav(opts = {}, &block) ⇒ Nav
Builds a custom Nav component for the tabs.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bootstrap4_helper/tab.rb', line 34 def nav(opts = {}, &block) opts[:class] = (opts[:class] || '') << " nav-#{@type}" opts[:data] = (opts[:data] || {}).merge(toggle: 'tab') opts[:child] = { data: { toggle: 'tab' } } Nav.new(@template, opts, &block) end |
#to_s ⇒ Object
This has a weird interaction. Because this object doesn’t actually return any wrapping string or DOM element, we want to return nil, so that only the output buffer on the sub components are returned. If we return the return value of the block, we will get the last element added to the input buffer as an unescaped string.
64 65 66 67 68 |
# File 'lib/bootstrap4_helper/tab.rb', line 64 def to_s @content.call(self) nil end |