class RailsHeroicons::Icons

Public Instance Methods

icon(name, style, class_name) click to toggle source
# File lib/rails_heroicons/icons.rb, line 8
def icon(name, style, class_name)
  file_path = RailsHeroicons.root("lib/rails_heroicons/icons/#{style}/#{name}.svg")

  begin
    file_data = File.read(file_path)
  rescue
    raise RailsHeroicons::IconNotFound
  end

  if class_name.present?
    frag = Nokogiri::HTML.fragment(file_data)
    frag.child.set_attribute('class', class_name)
    frag.child.set_attribute('alt', name)
    file_data = frag.to_s
  end

  file_data.html_safe
end