Module: Card::Set::All::Bootstrap::Accordion::HtmlFormat

Extended by:
Card::Set::AbstractFormat
Defined in:
tmpsets/set/mod026-bootstrap/all/bootstrap/accordion.rb

Instance Method Summary collapse

Instance Method Details

#accordion(title, content, collapse_id = card.name.safe_key) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'tmpsets/set/mod026-bootstrap/all/bootstrap/accordion.rb', line 29

def accordion title, content, collapse_id=card.name.safe_key
  accordion_content =
    case content
    when Hash  then accordion_group content, collapse_id
    when Array then content.present? && list_group(content)
    when String then content
    end
  <<-HTML.html_safe
    <div class="card">
      #{accordion_panel(title, accordion_content, collapse_id)}
    </div>
  HTML
end

#accordion_group(list, collapse_id = nil, args = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'tmpsets/set/mod026-bootstrap/all/bootstrap/accordion.rb', line 9

def accordion_group list, collapse_id=nil, args={}
  collapse_id ||= card.name.safe_key
  accordions = ""
  index = 1
  case list
  when Array then accordions = list.join
  when String then accordions = list
  else
    list.each_pair do |title, content|
      accordions << accordion(title, content, "#{collapse_id}-#{index}")
      index += 1
    end
  end
  add_class args, "act-accordion-group w-100"
  wrap_with :div, class: args[:class], id: "accordion-#{collapse_id}",
                  role: "tablist", "aria-multiselectable" => "true" do
    accordions
  end
end

#accordion_panel(title, body, collapse_id, _panel_heading_link = false) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'tmpsets/set/mod026-bootstrap/all/bootstrap/accordion.rb', line 43

def accordion_panel title, body, collapse_id, _panel_heading_link=false
  if body
    <<-HTML
      <div class="card-header" role="tab" id="heading-#{collapse_id}">
        <h5 class="mb-0">
          <a data-toggle="collapse" data-parent="#accordion-#{collapse_id}" \
             href="##{collapse_id}" aria-expanded="true" \
             aria-controls="#{collapse_id}">
            #{title}
          </a>
        </h5>
      </div>
      <div id="#{collapse_id}" class="collapse" \
             role="tabpanel" aria-labelledby="heading-#{collapse_id}">
        <div class="card-body">
          #{body}
        </div>
      </div>
    HTML
  else
    <<-HTML
      <li class="list-group-item">
        <h4 class="card-header">#{title}</h4>
      </li>
    HTML
  end
end