Class: Bootstrap5Helper::Tab
- Defined in:
- lib/bootstrap5_helper/tab.rb,
lib/bootstrap5_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, type_or_options = nil, opts = {}, &block) ⇒ Tab
constructor
Class constructor.
-
#nav(*tag_or_options) {|Nav| ... } ⇒ Nav
Builds a custom Nav component for the tabs.
- #to_s ⇒ Object
- #type_or_options(*args) ⇒ Object
Methods inherited from Component
#capture, #concat, #config, #content_tag, #parse_arguments, #parse_context_or_options, #parse_tag_or_options, #parse_text_or_options, #uuid
Constructor Details
#initialize(template, type_or_options = nil, opts = {}, &block) ⇒ Tab
Class constructor
15 16 17 18 19 20 21 22 23 |
# File 'lib/bootstrap5_helper/tab.rb', line 15 def initialize(template, = nil, opts = {}, &block) super(template) @type, args = (, opts) @id = args.fetch(:id, uuid) @class = args.fetch(:class, '') @data = args.fetch(:data, {}) @content = block || proc { '' } end |
Instance Method Details
#content(opts = {}, &block) ⇒ Tab::Content
Builds the Content object for the Tab.
63 64 65 |
# File 'lib/bootstrap5_helper/tab.rb', line 63 def content(opts = {}, &block) Content.new(@template, opts, &block) end |
#nav(tag, opts) ⇒ Nav #nav(opts) ⇒ Nav
Builds a custom Nav component for the tabs.
45 46 47 48 49 50 51 52 53 |
# File 'lib/bootstrap5_helper/tab.rb', line 45 def nav(*, &block) tag, args = (*, {}) args[:class] = (args[:class] || '') << " nav-#{@type}" args[:data] = (args[:data] || {}).merge('bs-toggle' => 'tab') args[:child] = { data: { 'bs-toggle' => 'tab' } } Nav.new(@template, tag, args, &block) end |
#to_s ⇒ Object
Note:
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.
Note:
Was updated to return an empty string opposed to nil.
74 75 76 77 78 |
# File 'lib/bootstrap5_helper/tab.rb', line 74 def to_s @content.call(self) '' end |
#type_or_options(*args) ⇒ Object
80 81 82 |
# File 'lib/bootstrap5_helper/tab.rb', line 80 def (*args) parse_arguments(*args, :tabs) end |