Class: Bootstrap::ViewHelpers::Components::Card

Inherits:
Bootstrap::ViewHelpers::Component show all
Defined in:
lib/bootstrap/view_helpers/components/card.rb

Direct Known Subclasses

Accordion::Card

Instance Attribute Summary

Attributes inherited from Bootstrap::ViewHelpers::Component

#block, #options, #style, #view

Instance Method Summary collapse

Methods inherited from Bootstrap::ViewHelpers::Component

#initialize

Constructor Details

This class inherits a constructor from Bootstrap::ViewHelpers::Component

Instance Method Details

#body(content_or_options = nil) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/bootstrap/view_helpers/components/card.rb', line 23

def body(content_or_options = nil)
  opts = content_or_options.is_a?(Hash) ? content_or_options : {}
  content = content_or_options.is_a?(String) ? content_or_options : nil
  (:div, class: body_class(opts)) do
    yield if block_given?
    concat(content) if content.present?
  end
end


32
33
34
35
36
37
38
# File 'lib/bootstrap/view_helpers/components/card.rb', line 32

def footer(content = nil, opts = {})
  opts, content = content, nil if content.is_a? Hash
  (:div, class: "card-footer #{opts[:class]}") do
    yield if block_given?
    concat(content) unless block_given? || content.present?
  end
end

#header(title_or_opts = nil, opts = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/bootstrap/view_helpers/components/card.rb', line 13

def header(title_or_opts = nil, opts = {})
  opts = title_or_opts if title_or_opts.is_a? Hash
  opts[:title] = title_or_opts if title_or_opts.is_a? String
  return if no_header?(opts[:title], block_given?)
  (:div, class: "card-header #{opts[:class]}") do
    yield if block_given?
    concat(title_tag(opts[:title])) unless block_given?
  end
end

#to_htmlObject



5
6
7
8
9
10
11
# File 'lib/bootstrap/view_helpers/components/card.rb', line 5

def to_html
  (:div, class: container_options[:class]) do
    concat(header) if options[:title]
    concat(body(&block)) if options[:body]
    block.call(self) if block.present? && !options[:body]
  end
end