Sha256: 7a3f19165bf082818806ae78d9bc514bced7ce89305b43c41c9f1442f0d9990d
Contents?: true
Size: 699 Bytes
Versions: 4
Compression:
Stored size: 699 Bytes
Contents
# frozen_string_literal: true module Heroicons class Icon def initialize(name:, variant:, attributes: {}) @name = name @variant = variant @attributes = attributes end def render return if file.nil? doc = Nokogiri::XML::Document.parse(file) svg = doc.at_css("svg") @attributes.each do |k, v| svg[dasherize(k.to_s)] = v end doc.to_html.strip end private def file @file ||= File.read(path).force_encoding("UTF-8") rescue StandardError nil end def path File.join(ICONS_PATH, @variant.to_s, "#{@name}.svg") end def dasherize(s) s.gsub(/_/, "-") end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
heroicons-ruby-2.1.1 | lib/heroicons/icon.rb |
heroicons-ruby-2.1.0 | lib/heroicons/icon.rb |
heroicons-ruby-2.0.0 | lib/heroicons/icon.rb |
heroicons-ruby-2.0.0.pre.beta.1 | lib/heroicons/icon.rb |