class FontAwesome5Rails::Parsers::FaIconParser

Constants

GEM_PATH

Attributes

attrs[R]
data[R]
icon[R]
options[R]
right[R]
style[R]
text[R]
title[R]

Public Class Methods

new(icon, options) click to toggle source
# File lib/font_awesome5_rails/parsers/fa_icon_parser.rb, line 13
def initialize(icon, options)
  @icon = icon
  @options = options
  @data = options[:data]
  @style = options[:style]
  @text = options[:text]
  @title = options[:title]
  @right = options[:right] == true
  @attrs = options.except(:text, :type, :class, :icon, :animation, :size, :right)
end

Public Instance Methods

classes() click to toggle source
# File lib/font_awesome5_rails/parsers/fa_icon_parser.rb, line 24
def classes
  @classes ||= parse_classes
end
file() click to toggle source
# File lib/font_awesome5_rails/parsers/fa_icon_parser.rb, line 38
def file
  file = GEM_PATH.join("app/assets/images/fa5/#{icon_type_path(@options[:type])}/#{@icon}.svg")
  file.exist? ? file : nil
end
sizes() click to toggle source
# File lib/font_awesome5_rails/parsers/fa_icon_parser.rb, line 28
def sizes
  @sizes ||= @options[:size].nil? ? '' : arr_with_fa(@options[:size]).uniq.join(' ').strip
end
tag() click to toggle source
# File lib/font_awesome5_rails/parsers/fa_icon_parser.rb, line 32
def tag
  return icon_content_tag if @text.nil?

  @right ? (text_content_tag + icon_content_tag) : (icon_content_tag + text_content_tag)
end

Private Instance Methods

icon_content_tag() click to toggle source
# File lib/font_awesome5_rails/parsers/fa_icon_parser.rb, line 55
def icon_content_tag
  content_tag(:i, nil, class: classes, **@attrs)
end
parse_classes() click to toggle source
# File lib/font_awesome5_rails/parsers/fa_icon_parser.rb, line 45
def parse_classes
  tmp = []
  tmp << icon_type(@options[:type])
  tmp += arr_with_fa(@icon)
  tmp += @options[:class].split(' ') unless @options[:class].nil?
  tmp += arr_with_fa(@options[:size]) unless @options[:size].nil?
  tmp += arr_with_fa(@options[:animation]) unless @options[:animation].nil?
  tmp.uniq.join(' ').strip
end
text_content_tag() click to toggle source
# File lib/font_awesome5_rails/parsers/fa_icon_parser.rb, line 59
def text_content_tag
  content_tag(:span, @text, class: "#{@right ? 'fa5-text-r' : 'fa5-text'}#{' ' unless sizes.blank?}#{sizes}",
                            style: @style)
end