Sha256: 85d2cf173ce29acae0cee4616d48fffacc339b488a7786aef83aecd5f934f9e0

Contents?: true

Size: 1.81 KB

Versions: 6

Compression:

Stored size: 1.81 KB

Contents

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

    # rubocop:disable Rails/HelperInstanceVariable
    def card_classes
      @card_classes ||= {
        :card   => "card",
        :header => "card-header",
        :body   => "card-body",
        :footer => "card-footer",
      }
    end
    # rubocop:enable Rails/HelperInstanceVariable
  end

  def bs_progress_bar(percentage)
    content_tag(:div, class: "progress") do
      content_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 = Agilibox::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 }
    else
      header_html = "".html_safe
    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 }
    else
      footer_html = "".html_safe
    end

    content_tag(card_tag, class: card_classes) do
      header_html + body_html + footer_html
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
agilibox-1.7.2 app/helpers/agilibox/bootstrap_helper.rb
agilibox-1.7.1 app/helpers/agilibox/bootstrap_helper.rb
agilibox-1.7.0 app/helpers/agilibox/bootstrap_helper.rb
agilibox-1.6.2 app/helpers/agilibox/bootstrap_helper.rb
agilibox-1.6.1 app/helpers/agilibox/bootstrap_helper.rb
agilibox-1.6.0 app/helpers/agilibox/bootstrap_helper.rb