Sha256: b00d9d8135b15e63ecff8e55a472c41974f0ca05782c1908a232d223d86347a1
Contents?: true
Size: 585 Bytes
Versions: 66
Compression:
Stored size: 585 Bytes
Contents
module Coco class Svg < Coco::Component SVG_CACHE = {} InvalidSvgError = Class.new(StandardError) attr_reader :path def initialize(path: nil, **kwargs) @path = path.gsub(".svg", "") end def svg SVG_CACHE[path] ||= read_svg end def read_svg File.read(full_path).html_safe rescue if Rails.env.development? || Rails.env.test? raise InvalidSvgError, "The SVG `#{full_path}` was not found" end end def full_path Coco::Engine.root.join("app/assets/build/coco/img/#{path}.svg") end end end
Version data entries
66 entries across 66 versions & 1 rubygems