Class: NdrUi::Bootstrap::Accordion
- Inherits:
-
Object
- Object
- NdrUi::Bootstrap::Accordion
- Defined in:
- app/helpers/ndr_ui/bootstrap/accordion.rb
Overview
Creates a plain or nested bootstrap accordion along with bootstrap_accordion_tag helper method. Produce the inner html code of an accordion item. Legacy styling recognised by jQuery UI and only fully supports one level accordion.
Signatures
bootstrap_accordion_tag(dom_id) do |accordion|
accordion.bootstrap_accordion_group(heading, ) do
#content or nested accordion
end
end
Options
-
open: true
- This will allow accordion item open by default -
seamless: true
- This omits the panel-body container so that tables and lists can be seamless -
Accordion are using pre-defined html format, and options and html attributes are not accepted.
Examples
<%= bootstrap_accordion_tag :fruit do |fruit_accordion| %>
<%= fruit_accordion.bootstrap_accordion_group "Apple" do %>
This is an apple.
<% end %>
<%= fruit_accordion.bootstrap_accordion_group "Orange", open: true do %>
This is an orange.
<% end %>
<% end %>
# =>
<div id="fruit" class="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<a href="#fruit_1" data-parent="#fruit" data-toggle="collapse">Apple</a>
</div>
<div class="panel-collapse collapse" id="fruit_1">
<div class="panel-body">
This is an apple.
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<a href="#fruit_2" data-parent="#fruit" data-toggle="collapse">Orange</a>
</div>
<div class="panel-collapse collapse in" id="fruit_2">
<div class="panel-body">
This is an orange.
</div>
</div>
</div>
</div>
Instance Attribute Summary collapse
-
#dom_id ⇒ Object
Returns the value of attribute dom_id.
-
#index ⇒ Object
Returns the value of attribute index.
Instance Method Summary collapse
- #bootstrap_accordion_group(heading, options = {}, &block) ⇒ Object
-
#initialize(accordion_id, template) ⇒ Accordion
constructor
A new instance of Accordion.
Constructor Details
#initialize(accordion_id, template) ⇒ Accordion
Returns a new instance of Accordion.
61 62 63 64 65 |
# File 'app/helpers/ndr_ui/bootstrap/accordion.rb', line 61 def initialize(accordion_id, template) @dom_id = accordion_id @template = template @index = 0 end |
Instance Attribute Details
#dom_id ⇒ Object
Returns the value of attribute dom_id.
59 60 61 |
# File 'app/helpers/ndr_ui/bootstrap/accordion.rb', line 59 def dom_id @dom_id end |
#index ⇒ Object
Returns the value of attribute index.
59 60 61 |
# File 'app/helpers/ndr_ui/bootstrap/accordion.rb', line 59 def index @index end |
Instance Method Details
#bootstrap_accordion_group(heading, options = {}, &block) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/helpers/ndr_ui/bootstrap/accordion.rb', line 67 def bootstrap_accordion_group(heading, = {}, &block) return unless block_given? .stringify_keys! seamless = ['seamless'] @index += 1 content = @template.capture(&block) content = @template.content_tag('div', content, class: 'panel-body') unless seamless @template.content_tag('div', class: 'panel panel-default') do div_panel_heading(heading) + div_panel_collapse(content, ['open']) end end |