Sha256: 86fa1bb65f6b0f883ec29289bce3016d5acd68f0124ef3730b7a9111aafd4104
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
# frozen_string_literal: true module Heroicon class Icon attr_reader :name, :variant, :options def initialize(name:, variant:, options:) @name = name @variant = safe_variant(variant) @options = options end def render return warning unless file.present? doc = Nokogiri::HTML::DocumentFragment.parse(file) svg = doc.at_css "svg" options.each do |key, value| svg[key.to_s] = value end doc end private def safe_variant(provided_variant) if %i[solid outline].include?(provided_variant.to_sym) provided_variant else :solid end end def file @file ||= File.read(file_path).force_encoding("UTF-8") rescue nil end def file_path File.join(Heroicon.root, "app/assets/images/heroicon/#{variant}/#{name}.svg") end def warning return unless Rails.env.development? <<-HTML <script type="text/javascript"> //<![CDATA[ console.warn("Heroicon: Failed to find heroicon: #{name}") //]]> </script> HTML end class << self def render(**kwargs) new(**kwargs).render end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
heroicon-0.3.0 | lib/heroicon/icon.rb |