Sha256: 582bb990f0148f28fb336e2dd9b1a26842a09b932e5f0ba0ed53655c1998a821

Contents?: true

Size: 560 Bytes

Versions: 3

Compression:

Stored size: 560 Bytes

Contents

require 'nokogiri'

module RailsHeroicons
  class IconNotFound < Exception
  end

  class Icons
    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)
        file_data = frag.to_s
      end

      file_data.html_safe
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rails_heroicons-0.6.0 lib/rails_heroicons/icons.rb
rails_heroicons-0.5.0 lib/rails_heroicons/icons.rb
rails_heroicons-0.4.0 lib/rails_heroicons/icons.rb