Class: Jekyll::FontAwesome::Svg::FontAwesomeIcon

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/fontawesome/svg/fa-icon.rb

Instance Method Summary collapse

Constructor Details

#initialize(icon) ⇒ FontAwesomeIcon

Returns a new instance of FontAwesomeIcon.



5
6
7
# File 'lib/jekyll/fontawesome/svg/fa-icon.rb', line 5

def initialize(icon)
  @icon = icon
end

Instance Method Details

#mapper(type) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/jekyll/fontawesome/svg/fa-icon.rb', line 9

def mapper(type)
  {
      "fas" => "solid",
      "fab" => "brands",
      "far" => "regular"
  }[type]
end

#to_filenameObject

absolute path to file



35
36
37
38
# File 'lib/jekyll/fontawesome/svg/fa-icon.rb', line 35

def to_filename
  base_directory = __dir__ + "/assets/fa_svgs/"
  base_directory + to_folder_name + "/" + to_icon_name + ".svg"
end

#to_folder_nameObject

solid / brands / regular



25
26
27
# File 'lib/jekyll/fontawesome/svg/fa-icon.rb', line 25

def to_folder_name
  mapper(to_font_awesome_type)
end

#to_font_awesome_typeObject

fab / far / fas



30
31
32
# File 'lib/jekyll/fontawesome/svg/fa-icon.rb', line 30

def to_font_awesome_type
  @icon.split('.').first.strip
end

#to_icon_nameObject

fa-dev



18
19
20
21
22
# File 'lib/jekyll/fontawesome/svg/fa-icon.rb', line 18

def to_icon_name
  icon = @icon.split('.').last.split('-')
  icon.shift
  icon.join('-')
end

#to_svg_htmlObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/jekyll/fontawesome/svg/fa-icon.rb', line 40

def to_svg_html
  file = File.read(to_filename)
  path_data = /^.*path d="(.*)" ?\/>.*$/.match(file).captures.first
  viewBox = /^.*viewBox="([^"]*)".*$/.match(file).captures.first
  "<symbol id='#{@icon}' viewBox='#{viewBox}'>
    <title>#{to_icon_name}</title>
    <path class='path1' d='#{path_data}'></path>
</symbol>
"
end

#valueObject



51
52
53
# File 'lib/jekyll/fontawesome/svg/fa-icon.rb', line 51

def value
  @icon
end