Module: NdrUi::Bootstrap::PanelHelper

Included in:
NdrUi::BootstrapHelper
Defined in:
app/helpers/ndr_ui/bootstrap/panel_helper.rb

Overview

This provides accordion

Constant Summary collapse

PANEL_SUBCLASSES =
%w(
  panel-default
  panel-primary
  panel-success
  panel-info
  panel-warning
  panel-danger
).freeze

Instance Method Summary collapse

Instance Method Details

#bootstrap_accordion_tag(dom_id, &block) ⇒ Object

Creates an accordion wrapper and creates a new NdrUi::Bootstrap::Accordion instance Creates an plain or nested bootstrap accordion along with bootstrap_accordion_group method at NdrUi::Bootstrap::Accordion class.

Signatures

bootstrap_accordion_tag(dom_id) do |accordion|
  #content for accordion items
end

Examples

<%= bootstrap_accordion_group :fruit do |fruit_accordion| %>
<% end %>
# => <div id="fruit" class="accordion"></div>


29
30
31
32
33
34
35
# File 'app/helpers/ndr_ui/bootstrap/panel_helper.rb', line 29

def bootstrap_accordion_tag(dom_id, &block)
  return unless block_given?
  accordion = ::NdrUi::Bootstrap::Accordion.new(dom_id, self)
  '<div id="'.html_safe + accordion.dom_id.to_s + '" class="panel-group">'.html_safe +
    capture { yield(accordion) } +
    '</div>'.html_safe
end

#bootstrap_panel_body_tag(&block) ⇒ Object

Creates a simple bootstrap panel body.

Signatures

bootstrap_panel_body_tag do
  #content for panel body
end

Examples

<%= bootstrap_panel_body_tag do %>
  Check it out!!
<% end %>
# => <div class="panel-body">Check it out!!</div>


81
82
83
84
# File 'app/helpers/ndr_ui/bootstrap/panel_helper.rb', line 81

def bootstrap_panel_body_tag(&block)
  return unless block_given?
  (:div, capture(&block), class: 'panel-body')
end

#bootstrap_panel_tag(heading, options = {}, &block) ⇒ Object

Creates a bootstrap panel wrapper. the heading is wrapped in a panel-heading. The content is not wrapped in a panel-body to enable seamless tables and lists.

Signatures

bootstrap_panel_tag(heading, options = {}) do
  #content for panel
end

Examples

<%= bootstrap_panel_tag 'Apples', class: 'panel-warning', id: 'fruit' do %>
  Check it out!!
<% end %>
# => <div id="fruit" class="panel panel-warning"><div class="panel-heading">Apples</div>
Check it out!!</div>


53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/helpers/ndr_ui/bootstrap/panel_helper.rb', line 53

def bootstrap_panel_tag(heading, options = {}, &block)
  return unless block_given?
  options.stringify_keys!
  classes = %w(panel)
  classes += options['class'].to_s.split(' ') if options.include?('class')
  classes << 'panel-default' if (classes & PANEL_SUBCLASSES).empty?
  options['class'] = classes.uniq.join(' ')

  (:div,
              (:div, heading, class: 'panel-heading') +
              capture(&block),
              options)
end