module FontAwesomeFileIcons::Helpers

Constants

DEFAULT_ICON
FILE_ICONS_MAPPING
FILE_ICONS_MAPPING_REGEXP

Public Instance Methods

fa_file_icon(filename, *options) click to toggle source
# File lib/font_awesome_file_icons.rb, line 50
def fa_file_icon(filename, *options)
  icon = get_icon(filename)
  fa_icon(icon, *options)
end
fa_file_stacked_icon(filename, *options) click to toggle source
# File lib/font_awesome_file_icons.rb, line 55
def fa_file_stacked_icon(filename, *options)
  icon = get_icon(filename)
  fa_stacked_icon(icon, *options)
end

Private Instance Methods

get_icon(filename) click to toggle source
# File lib/font_awesome_file_icons.rb, line 62
def get_icon(filename)
  extension = File.extname(filename.to_s)
  mime_type = MimeMagic.by_extension(extension)&.type
  icon      = FILE_ICONS_MAPPING[mime_type]

  if icon.nil?
    key  = FILE_ICONS_MAPPING_REGEXP.detect{|e| e =~ mime_type }
    icon = FILE_ICONS_MAPPING[key] if key
  end

  #puts "#{extension}  -> #{mime_type}  ->  #{icon}"
  icon ||= DEFAULT_ICON
end