Class: Bootstrap3Helper::Panel

Inherits:
Component show all
Defined in:
lib/bootstrap3_helper/panel.rb

Overview

Used to rapidly build Bootstrap Panel Components.

Examples:

Rendering a Bootstrap Panel Component in a view:

<%= panel_helper class: 'panel-primary' do |p| %>
  <%= p.header { "Some Title" }
  <%= p.body class: 'custom-class', id: 'custom-id' do %>
    //HTML or Ruby code here...
  <% end %>
  <%= p.footer do %>
    //HTML or Ruby
  <% end %>
<% end %>

Instance Method Summary collapse

Methods inherited from Component

#concat, #content_tag, #parse_arguments, #uuid

Constructor Details

#initialize(template, context_or_options = nil, opts = {}, &block) ⇒ Panel

Creates a new Panel object.

Parameters:

  • template (Class)
    • Template in which your are binding too.

  • - (NilClass|String|Symbol|Hash)

    Bootstrap class context, or options hash.

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :id (String)

    The ID of the element

  • :class (String)

    Custom class for the component.

  • :data (Hash)

    Any data attributes for the element.



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

def initialize(template, context_or_options = nil, opts = {}, &block)
  super(template)
  @context, args = parse_arguments(context_or_options, opts)

  @id      = args.fetch(:id, '')
  @class   = args.fetch(:class, '')
  @data    = args.fetch(:data, nil)
  @content = block || proc { '' }
end

Instance Method Details

#body(args = {}, &block) ⇒ Object

Used to generate the body component for the panel.

Parameters:

  • args (Hash) (defaults to: {})

Options Hash (args):

  • :id (String)

    The ID of the element

  • :class (String)

    Custom class for the component.

Yield Returns:

  • (String)


59
60
61
62
63
64
# File 'lib/bootstrap3_helper/panel.rb', line 59

def body(args = {}, &block)
  id    = args.fetch(:id, '')
  klass = args.fetch(:class, '')

  (:div, id: id, class: 'panel-body ' + klass, &block)
end

Used to generate the footer component for the panel.

Parameters:

  • args (Hash) (defaults to: {})

Options Hash (args):

  • :id (String)

    The ID of the element

  • :class (String)

    Custom class for the component.

Yield Returns:

  • (String)


73
74
75
76
77
78
# File 'lib/bootstrap3_helper/panel.rb', line 73

def footer(args = {}, &block)
  id    = args.fetch(:id, '')
  klass = args.fetch(:class, '')

  (:div, id: id, class: 'panel-footer ' + klass, &block)
end

#header(args = {}, &block) ⇒ Object

Used to generate the header component for the panel.

Parameters:

  • args (Hash) (defaults to: {})

Options Hash (args):

  • :id (String)

    The ID of the element

  • :class (String)

    Custom class for the component.

Yield Returns:

  • (String)


43
44
45
46
47
48
49
50
# File 'lib/bootstrap3_helper/panel.rb', line 43

def header(args = {}, &block)
  id    = args.fetch(:id, '')
  klass = args.fetch(:class, '')

  (:div, id: id, class: 'panel-heading ' + klass) do
    (:h3, class: 'panel-title', &block)
  end
end

#to_sString

Used to render the html for the entire panel object.

Returns:

  • (String)


84
85
86
87
88
# File 'lib/bootstrap3_helper/panel.rb', line 84

def to_s
   :div, id: @id, class: container_classes, data: @data do
    @content.call(self)
  end
end