class Heroicon::Icon
def file
def file @file ||= Rails.application.assets.find_asset("heroicon/#{variant}/#{name}.svg").source.force_encoding("UTF-8") rescue nil end
def initialize(name:, variant:, options:)
def initialize(name:, variant:, options:) @name = name @variant = safe_variant(variant) @options = options end
def render
def render return warning unless file.present? doc = Nokogiri::HTML::DocumentFragment.parse(file) svg = doc.at_css "svg" svg["class"] = options[:class] if options[:class].present? doc end
def render(*args)
def render(*args) new(*args).render end
def safe_variant(provided_variant)
def safe_variant(provided_variant) if %i[solid outline].include?(provided_variant.to_sym) provided_variant else :solid end end
def warning
def warning return unless Rails.env.development? <<-HTML <script type="text/javascript"> //<![CDATA[ console.warn("Heroicon: Failed to find heroicon: #{name}") //]]> </script> HTML end