Class: Booties::Panel
- Inherits:
-
Object
- Object
- Booties::Panel
- Extended by:
- Forwardable
- Includes:
- Utils
- Defined in:
- lib/booties/panel.rb
Overview
:nodoc:
Constant Summary collapse
- CSS_CLASSES =
{ heading: 'panel-heading', title: 'panel-title', body: 'panel-body', footer: 'panel-footer', }.freeze
Instance Method Summary collapse
-
#body(content = nil, class: nil, **options, &block) ⇒ Object
Renders the panel body.
-
#footer(content = nil, class: nil, **options, &block) ⇒ Object
Renders the panel footer.
-
#heading(content = nil, class: nil, **options, &block) ⇒ Object
Renders the panel heading.
-
#initialize(template, context: :default, wrapper_tag: 'div', **options) ⇒ Panel
constructor
Instantiates a new Panel.
-
#render(&block) ⇒ Object
Renders the top-level div for the panel.
-
#title(content = nil, class: nil, **options, &block) ⇒ Object
Renders the panel title.
Methods included from Utils
Constructor Details
#initialize(template, context: :default, wrapper_tag: 'div', **options) ⇒ Panel
Instantiates a new Panel. Several helper methods like #content_tag will be delegated to template
.
The optional context
argument can be passed in to specify the panel context; otherwise, the context :default
is used.
The default behavior is to use a div
tag for to top-level panel container, but you may specify a different tag using the wrapper_tag
keyword. (There are no guarantees on whether or not other tags will work correctly with Bootstrap panels.
Any additional options will be included as attributes on the top-level panel container.
31 32 33 34 35 36 37 |
# File 'lib/booties/panel.rb', line 31 def initialize(template, context: :default, wrapper_tag: 'div', **) @template = template @wrapper_tag = wrapper_tag @context = context # TODO: pass options to #render instead of constructor @options = end |
Instance Method Details
#body(content = nil, class: nil, **options, &block) ⇒ Object
Renders the panel body. The content of the body can be passed in through the content
parameter or as a block. If class
is given, it will be merged with the required panel body class. Additional keyword arguments will be passed as an options Hash to #content_tag.
83 84 85 86 87 88 |
# File 'lib/booties/panel.rb', line 83 def body(content = nil, class: nil, **, &block) content ||= capture(&block) classes = merge_classes CSS_CLASSES[:body], binding.local_variable_get(:class) content_tag :div, content, class: classes, ** end |
#footer(content = nil, class: nil, **options, &block) ⇒ Object
Renders the panel footer. The content of the footer can be passed in through the content
parameter or as a block. If class
is given, it will be merged with the required panel footer class. Additional keyword arguments will be passed as an options Hash to #content_tag.
95 96 97 98 99 100 |
# File 'lib/booties/panel.rb', line 95 def (content = nil, class: nil, **, &block) content ||= capture(&block) classes = merge_classes CSS_CLASSES[:footer], binding.local_variable_get(:class) content_tag :div, content, class: classes, ** end |
#heading(content = nil, class: nil, **options, &block) ⇒ Object
Renders the panel heading. The content of the heading can be passed in through the content
parameter or as a block. If class
is given, it will be merged with the required panel heading class. Additional keyword arguments will be passed as an options Hash to #content_tag.
59 60 61 62 63 64 |
# File 'lib/booties/panel.rb', line 59 def heading(content = nil, class: nil, **, &block) content ||= capture(&block) classes = merge_classes CSS_CLASSES[:heading], binding.local_variable_get(:class) content_tag :div, content, class: classes, ** end |
#render(&block) ⇒ Object
Renders the top-level div for the panel. @context is used to specify the panel’s context. The content is captured from block
. The Panel object will be passed as a parameter to block
.
45 46 47 48 49 50 51 52 |
# File 'lib/booties/panel.rb', line 45 def render(&block) = @options.dup classes = merge_classes %W[panel panel-#{@context}], .delete(:class) content_tag @wrapper_tag, class: classes, ** do capture self, &block end end |
#title(content = nil, class: nil, **options, &block) ⇒ Object
Renders the panel title. The content of the title can be passed in through the content
paramter or as a block. If class
is given, it will be merged with the required panel title class. Additional keyword arguments will be passed as an options Hash to #content_tag.
71 72 73 74 75 76 |
# File 'lib/booties/panel.rb', line 71 def title(content = nil, class: nil, **, &block) content ||= capture(&block) classes = merge_classes CSS_CLASSES[:title], binding.local_variable_get(:class) content_tag :h3, content, class: classes, ** end |