Class: FontAwesome5Rails::Parsers::FaIconParser

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper, ParseMethods
Defined in:
lib/font_awesome5_rails/parsers/fa_icon_parser.rb

Constant Summary collapse

GEM_PATH =
Pathname.new('../../../../').expand_path(__FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ParseMethods

#arr_with_fa, #icon_type, #icon_type_path, #prepend_fa

Constructor Details

#initialize(icon, options) ⇒ FaIconParser

Returns a new instance of FaIconParser.



13
14
15
16
17
18
19
20
21
22
# 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

Instance Attribute Details

#attrs ⇒ Object (readonly)

Returns the value of attribute attrs.



11
12
13
# File 'lib/font_awesome5_rails/parsers/fa_icon_parser.rb', line 11

def attrs
  @attrs
end

#data ⇒ Object (readonly)

Returns the value of attribute data.



11
12
13
# File 'lib/font_awesome5_rails/parsers/fa_icon_parser.rb', line 11

def data
  @data
end

#icon ⇒ Object (readonly)

Returns the value of attribute icon.



11
12
13
# File 'lib/font_awesome5_rails/parsers/fa_icon_parser.rb', line 11

def icon
  @icon
end

#options ⇒ Object (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/font_awesome5_rails/parsers/fa_icon_parser.rb', line 11

def options
  @options
end

#right ⇒ Object (readonly)

Returns the value of attribute right.



11
12
13
# File 'lib/font_awesome5_rails/parsers/fa_icon_parser.rb', line 11

def right
  @right
end

#style ⇒ Object (readonly)

Returns the value of attribute style.



11
12
13
# File 'lib/font_awesome5_rails/parsers/fa_icon_parser.rb', line 11

def style
  @style
end

#text ⇒ Object (readonly)

Returns the value of attribute text.



11
12
13
# File 'lib/font_awesome5_rails/parsers/fa_icon_parser.rb', line 11

def text
  @text
end

#title ⇒ Object (readonly)

Returns the value of attribute title.



11
12
13
# File 'lib/font_awesome5_rails/parsers/fa_icon_parser.rb', line 11

def title
  @title
end

Instance Method Details

#classes ⇒ Object



24
25
26
# File 'lib/font_awesome5_rails/parsers/fa_icon_parser.rb', line 24

def classes
  @classes ||= parse_classes
end

#file ⇒ Object



38
39
40
41
# 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 ⇒ Object



28
29
30
# 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 ⇒ Object



32
33
34
35
36
# File 'lib/font_awesome5_rails/parsers/fa_icon_parser.rb', line 32

def tag
  return  if @text.nil?

  @right ? ( + ) : ( + )
end