Sha256: efab38d5e16402414265f0ee8da1c0f1de380e7e165231207efac93dd7d55df6
Contents?: true
Size: 706 Bytes
Versions: 19
Compression:
Stored size: 706 Bytes
Contents
module Lookbook class Icon::Component < Lookbook::BaseComponent ICON_CACHE = {} attr_reader :stroke def initialize(name:, size: 4, stroke: 2, **html_attrs) @icon_name = name.to_s.tr("_", "-") @size = size || 4 @stroke = stroke super(**html_attrs) end def size_rems "#{@size * 0.25}rem" end def svg ICON_CACHE[@icon_name] ||= read_svg end def read_svg File.read(svg_path).html_safe rescue if Rails.env.development? || Rails.env.test? raise "`#{@icon_name}` is not a valid icon name" end end def svg_path Lookbook::Engine.root.join("assets/icons/#{@icon_name}.svg") end end end
Version data entries
19 entries across 19 versions & 1 rubygems