Class: Booties::Panel

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Utils
Defined in:
lib/booties/panel.rb

Instance Method Summary collapse

Methods included from Utils

merge_classes

Constructor Details

#initialize(view_context, context: :default, **options) ⇒ Panel

Instantiates a new Panel. Several helper methods like #content_tag will be delegated to view_context. The optional context argument can be passed in to specify the panel context. context defaults to :default. Any additional options will be included as attributes on the top-level panel div.



14
15
16
17
18
# File 'lib/booties/panel.rb', line 14

def initialize(view_context, context: :default, **options)
  @view_context = view_context
  @context      = context
  @options      = options
end

Instance Method Details

#body(content = nil, &block) ⇒ Object

Renders the panel body. The content of the body can be passed in through the content parameter or as a block.



54
55
56
57
# File 'lib/booties/panel.rb', line 54

def body(content = nil, &block)
  content ||= capture &block
   :div, content, class: 'panel-body'
end

Renders the panel footer. The content of the footer can be passed in through the content parameter or as a block.



62
63
64
65
# File 'lib/booties/panel.rb', line 62

def footer(content = nil, &block)
  content ||= capture &block
   :div, content, class: 'panel-footer'
end

#heading(content = nil, &block) ⇒ Object

Renders the panel heading. The content of the heading can be passed in through the content parameter or as a block.



38
39
40
41
# File 'lib/booties/panel.rb', line 38

def heading(content = nil, &block)
  content ||= capture &block
   :div, content, class: 'panel-heading'
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.



26
27
28
29
30
31
32
33
# File 'lib/booties/panel.rb', line 26

def render(&block)
  options = @options.dup
  classes = merge_classes %W[panel panel-#@context],
    options.delete(:class)
   :div, class: classes, **options do
    capture self, &block
  end
end

#title(content = nil, &block) ⇒ Object

Renders the panel title. The content of the title can be passed in through the content paramter or as a block.



46
47
48
49
# File 'lib/booties/panel.rb', line 46

def title(content = nil, &block)
  content ||= capture &block
   :h3, content, class: 'panel-title'
end