Sha256: 0532f01dfa6875e77011809c2f15393ca575fff5b65cae1861587f4665848a7e

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

module MaterialIcons
  module Rails
    class MaterialIconStack < OpenStruct

      include ActionView::Helpers::TagHelper

      cattr_accessor(:style_options_attributes) { [:class, :style] }

      def initialize(icons, options = {})
        material_icons = icons.collect{ |icon, options| MaterialIcon.new(icon, options.except(:text)) }
        super(options.merge({icons: material_icons}))
        fill_defaults
        normalize
      end

      def to_html
        content_tag(self[:tag], self[:icons].collect(&:to_html).join.html_safe + self[:text], style_options_attributes.collect{ |a| [a, self[a] || self.send(a)] }.to_h)
      end

      private

      def fill_defaults
        {
          tag: 'span',
          text: '',
          size: '1em',
        }.each{ |k, v| self[k] = v unless self[k].present? }
      end

      def normalize
        self[:size] = case self[:size]
        when /^\d+x$/ then "#{size.to_i}em"
        when self[:size].to_i.to_s then "#{size}px"
        else self[:size]
        end

        self[:class] = case self[:class]
        when Array then self[:class]
        when String then self[:class].split(' ')
        else []
        end.concat(['material-icons-stack'])
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
material_icons-rails-1.0.3 lib/material_icons/rails/material_icon_stack.rb
material_icons-rails-1.0.2 lib/material_icons/rails/material_icon_stack.rb
material_icons-rails-0.1.2 lib/material_icons/rails/material_icon_stack.rb