Sha256: 88c3f62ed3630b7b92b175b87761f4ea766e99b14bf99fc8fb21ef1af5b4bd46

Contents?: true

Size: 1.66 KB

Versions: 4

Compression:

Stored size: 1.66 KB

Contents

module BMC::BootstrapHelper
  class << self
    attr_writer :card_classes

    def card_classes
      @card_classes ||= {
        :card   => "card",
        :header => "card-header",
        :body   => "card-body",
        :footer => "card-footer",
      }
    end
  end

  def bs_progress_bar(percentage)
    percentage = percentage.round if percentage.respond_to?(:round)

    tag.div(class: "progress") do
      tag.div(class: "progress-bar", style: "width:#{percentage}%") do
        "#{percentage}%"
      end
    end
  end

  def bs_card( # rubocop:disable Metrics/ParameterLists
    header: nil,
    body: true,
    footer: nil,
    card_tag: :div,
    header_tag: :div,
    body_tag: :div,
    footer_tag: :div,
    card_class: nil,
    header_class: nil,
    body_class: nil,
    footer_class: nil,
    &block
  )
    global_classes = BMC::BootstrapHelper.card_classes
    card_classes   = ([global_classes[:card]]   + card_class.to_s.split).compact.sort
    header_classes = ([global_classes[:header]] + header_class.to_s.split).compact.sort
    body_classes   = ([global_classes[:body]]   + body_class.to_s.split).compact.sort
    footer_classes = ([global_classes[:footer]] + footer_class.to_s.split).compact.sort

    if header
      header_html = content_tag(header_tag, class: header_classes) { header }
    end

    if body
      body_html = content_tag(body_tag, class: body_classes) { capture(&block) }
    else
      body_html = capture(&block)
    end

    if footer
      footer_html = content_tag(footer_tag, class: footer_classes) { footer }
    end

    content_tag(card_tag, class: card_classes) do
      [header_html, body_html, footer_html].compact.sum
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bmc-1.2.0 app/helpers/bmc/bootstrap_helper.rb
bmc-1.1.0 app/helpers/bmc/bootstrap_helper.rb
bmc-1.0.1 app/helpers/bmc/bootstrap_helper.rb
bmc-1.0.0 app/helpers/bmc/bootstrap_helper.rb