class Bootstrap::ViewHelpers::Components::Card
Public Instance Methods
body(content_or_options = nil) { || ... }
click to toggle source
# 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 content_tag(:div, class: body_class(opts)) do yield if block_given? concat(content) if content.present? end end
header(title_or_opts = nil, opts = {}) { || ... }
click to toggle source
# 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?) content_tag(:div, class: "card-header #{opts[:class]}") do yield if block_given? concat(title_tag(opts[:title])) unless block_given? end end
to_html()
click to toggle source
# File lib/bootstrap/view_helpers/components/card.rb, line 5 def to_html content_tag(: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
Private Instance Methods
assign_and_validate_style()
click to toggle source
# File lib/bootstrap/view_helpers/components/card.rb, line 47 def assign_and_validate_style; end
body_class(opts)
click to toggle source
# File lib/bootstrap/view_helpers/components/card.rb, line 71 def body_class(opts) classes = ['card-body'] classes << (options[:body] || {}).delete(:class) classes << (opts || {}).delete(:class) classes.compact.join(' ') end
container_options()
click to toggle source
# File lib/bootstrap/view_helpers/components/card.rb, line 60 def container_options default = { class: 'card ' } default[:class] << options.delete(:class).to_s default.merge(options) end
header_options()
click to toggle source
# File lib/bootstrap/view_helpers/components/card.rb, line 66 def header_options default = { class: 'my-0', tag: :h5 } default.merge(options[:header] || {}) end
no_header?(title, has_block)
click to toggle source
# File lib/bootstrap/view_helpers/components/card.rb, line 49 def no_header?(title, has_block) title.blank? && options[:title].blank? && !has_block end
parse_options(options)
click to toggle source
Calls superclass method
Bootstrap::ViewHelpers::Component#parse_options
# File lib/bootstrap/view_helpers/components/card.rb, line 42 def parse_options(options) super(options) options[:body] = {} if options[:body].is_a?(TrueClass) end
title_tag(title)
click to toggle source
# File lib/bootstrap/view_helpers/components/card.rb, line 53 def title_tag(title) title ||= options[:title] return title unless header_options[:tag] content_tag(header_options[:tag], title, class: header_options[:class]) end