Sha256: 9ac01c3863ae0e8ebe2b7b830e8167395efedb5b720efd93dac896aa3fbb02bb
Contents?: true
Size: 760 Bytes
Versions: 1
Compression:
Stored size: 760 Bytes
Contents
module Plutonium class Icons ICON_CACHE = {} ICON_SIZES = { sm: "w-3 h-3", md: "w-4 h-4", lg: "w-6 h-6" } class << self def render(name, size: :md) # This is not threadsafe, but should not cause any issues # I believe adding a mutex would be overall more expensive than a few potential # concurrent disk accesses for a brief while after boot. size = ICON_SIZES.key?(size) ? size : :sm ICON_CACHE["#{name}:#{size}"] ||= begin path = Plutonium.root.join "app/assets/icons/#{name}.svg" raise "Invalid icon: #{name}" unless File.exist?(path) File.read(path).sub("<svg ", "<svg class=\"#{ICON_SIZES[size]}\" ") end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
plutonium-0.8.0 | lib/plutonium/icons.rb |