Module: Bootstrap::AccordionHelper

Defined in:
app/helpers/bootstrap/accordion_helper.rb

Overview

Rails helpers for building Bootstrap accordions.

See: twitter.github.io/bootstrap/javascript.html#collapse

<%= accordion do %>

  <%= accordion_group('Section 1', open: true) do %>
    content for group 1
  <% end >

  <%= accordion_group('Section 1') do %>
    content for group 2
  <% end %>

<% end %>

Instance Method Summary collapse

Instance Method Details

#accordion(options = {}) { ... } ⇒ String

Returns the html for a Bootstrap accordion.

Parameters:

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

    html attributes for accordion <div>

Yields:

  • Should contain calls to #accordion_group

Yield Returns:

  • (String)

    Html from #accordion_group calls

Returns:

  • (String)

    <div class=“accordion”> plus results of yielded block



25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/bootstrap/accordion_helper.rb', line 25

def accordion(options={})
  options = canonicalize_options(options)
  options = ensure_accordion_id(options)
  @accordion_id = options[:id]
  options = ensure_class(options, 'panel-group')
  
  (:div, options) do
    yield
  end
end

#accordion_group(text, options = {}) { ... } ⇒ Object

Returns the html for a Bootstrap accordion group.

Parameters:

  • text (String)

    the text in the accordion group header

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

    All keys except :open become html attributes for the accordion group

Options Hash (options):

  • :open (true)

    Set to true if you want this group initially open

Yields:

  • Html contents of accordion group

Yield Returns:

  • (String)

    Html for accordion group contents



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/helpers/bootstrap/accordion_helper.rb', line 43

def accordion_group(text, options={})
  options = canonicalize_options(options)
  open = options.delete(:open)

  # options = ensure_accordion_group_id(options)
  @accordion_group_id = get_next_group_id

  options = ensure_class(options, 'panel panel-default')
  
  (:div, options) do
    accordion_group_heading(text) + accordion_group_body(open) { yield }
  end
end