Sha256: f0f0ddf6f4309cb0f917cfc2a0d098d8aa0c6168699fbc4ea9d1b7fe83c3fbf6

Contents?: true

Size: 1012 Bytes

Versions: 1

Compression:

Stored size: 1012 Bytes

Contents

# frozen_string_literal: true

require 'railsstrap/classes/base'

module Railsstrap
  module Classes
    class Badge < Base
      # @return [#to_s] the content-related class to assign to the badge box.
      def variant_class
        Badge.variants[@options.fetch :variant, @options[:priority]]
      end

      def render_tag
        if @options[:href]
          render content_tag(:a)
        else
          render content_tag(:span)
        end
      end

      # @return [Hash<Symbol, String>] the class that Bootstrap requires to
      #   append to an badge box based on its variant.

      def self.variants
        HashWithIndifferentAccess.new(:'badge-info').tap do |klass|
          variant_types.each do |variant|
            klass[variant.to_sym] = :"badge-#{variant}"
          end
          #Aliases
          klass[:notice] = :'badge-success'
          klass[:badge]  = :'badge-danger'
        end
      end

      def pill_class
        'badge-pill' if @options[:pill]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
railsstrap-4.0.0.beta3 lib/railsstrap/classes/badge.rb