Module: FontAwesome5::Rails::IconHelper

Defined in:
app/helpers/font_awesome5/rails/icon_helper.rb

Constant Summary collapse

ICON_TYPES =
%w(fas far fal fab fad fak).freeze

Instance Method Summary collapse

Instance Method Details

#fa5_icon(icon, options = {}) ⇒ Object Also known as: fa_icon



22
23
24
# File 'app/helpers/font_awesome5/rails/icon_helper.rb', line 22

def fa5_icon(icon, options = {})
  FontAwesome5Rails::Parsers::FaIconParser.new(icon, options).tag
end

#fa5_stacked_icon(icon, options = {}) ⇒ Object Also known as: fa_stacked_icon



27
28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/font_awesome5/rails/icon_helper.rb', line 27

def fa5_stacked_icon(icon, options = {})
  parser = FontAwesome5Rails::Parsers::FaStackedIconParser.new(icon, options)

  tags =  :span, class: parser.span_classes, title: parser.title do
    (:i, nil, class: (parser.reverse ? parser.second_icon_classes : parser.first_icon_classes), **parser.more_options(:base_options)) +
    (:i, nil, class: (parser.reverse ? parser.first_icon_classes : parser.second_icon_classes), **parser.more_options(:icon_options))
  end

  tags += parser.text unless parser.text.nil?
  tags
end

#fa_inline_icon(icon, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/font_awesome5/rails/icon_helper.rb', line 10

def fa_inline_icon(icon, options = {})
  file = FontAwesome5Rails::Parsers::FaIconParser.new(icon, options).file
  return nil unless Pathname.new(file).exist?

  doc = Nokogiri::XML(File.read(file))
  svg = doc.root
  svg[:fill] = 'currentColor'
  classes = [options[:class], svg[:class]].flatten.compact.join ' '
  svg[:class] = classes if classes
  ActiveSupport::SafeBuffer.new(svg.to_s)
end

#fa_layered_icon(options = {}, &block) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'app/helpers/font_awesome5/rails/icon_helper.rb', line 40

def fa_layered_icon(options = {}, &block)
  parser = FontAwesome5Rails::Parsers::FaLayeredIconParser.new(options)
  tag = (:span, class: parser.classes, title: parser.title, style: parser.style, &block)
  return tag if parser.size.nil?

   :div, class: "fa-#{parser.size}" do
    tag
  end
end