Sha256: 0218fcc5d39b9c5f4b89a881904ca6bc6a567964afea41ff68a7f468b7ce3941

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

# Icon helpers for MaterialDesignIcons
module MaterialDesignIcons
  module IconHelper
    # Creates an icon tag given an icon name and possible icon
    # modifiers.
    #
    # Examples
    #
    #   mdi_icon "sheep"
    #   # => <i class="mdi md-sheep"></i>
    #
    def mdi(names = 'sheep', original_options = {})
      options = original_options.deep_dup
      classes = ['mdi']
      classes.concat Private.icon_names(names)
      classes.concat Array(options.delete(:class))
      text = options.delete(:text)
      right_icon = options.delete(:right)
      icon = content_tag(:i, nil, options.merge(class: classes))
      Private.icon_join(icon, text, right_icon)
    end
    alias mdi_icon mdi

    def mdi_spin(names = 'sheep', original_options = {})
      mdi_icon(names, original_options.merge(class: ['mdi-spin']))
    end
    module Private
      extend ActionView::Helpers::OutputSafetyHelper

      def self.icon_join(icon, text, reverse_order = false)
        return icon if text.blank?

        elements = [icon, ERB::Util.html_escape(text)]
        elements.reverse! if reverse_order
        safe_join(elements, ' ')
      end

      def self.icon_names(names = [])
        array_value(names).map { |n| "mdi-#{n}" }
      end

      def self.array_value(value = [])
        value.is_a?(Array) ? value : value.to_s.split(/\s+/)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_material_design_icons-6.5.95 lib/rails_material_design_icons/icon_helper.rb